class Qiita::Markdown::Transformers::FilterAttributes

Constants

DELIMITER
FILTERS

Public Class Methods

call(**args) click to toggle source
# File lib/qiita/markdown/transformers/filter_attributes.rb, line 36
def self.call(**args)
  new(**args).transform
end
new(env) click to toggle source
# File lib/qiita/markdown/transformers/filter_attributes.rb, line 40
def initialize(env)
  @env = env
end

Public Instance Methods

transform() click to toggle source
# File lib/qiita/markdown/transformers/filter_attributes.rb, line 44
def transform
  return unless FILTERS.key?(name)

  FILTERS[name].each_pair do |attr, pattern|
    filter_attribute(attr, pattern) if node.attributes.key?(attr)
  end
end

Private Instance Methods

filter_attribute(attr, pattern) click to toggle source
# File lib/qiita/markdown/transformers/filter_attributes.rb, line 54
def filter_attribute(attr, pattern)
  node[attr] = node[attr].split(DELIMITER).select do |value|
    pattern.is_a?(Array) ? pattern.include?(value) : (pattern =~ value)
  end.join(DELIMITER)
end
name() click to toggle source
# File lib/qiita/markdown/transformers/filter_attributes.rb, line 60
def name
  @env[:node_name]
end
node() click to toggle source
# File lib/qiita/markdown/transformers/filter_attributes.rb, line 64
def node
  @env[:node]
end