Class: NodeValueExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/src/extractor.rb

Instance Method Summary collapse

Constructor Details

#initialize(node_extractor) ⇒ NodeValueExtractor

Returns a new instance of NodeValueExtractor.



80
81
82
# File 'lib/src/extractor.rb', line 80

def initialize(node_extractor)
  @node_extractor = node_extractor
end

Instance Method Details

#attr_values(path, attributes) ⇒ Object



84
85
86
87
88
89
# File 'lib/src/extractor.rb', line 84

def attr_values(path, attributes)
  return attributes.map { |atr| attr_value(path, atr) } if attributes.is_a? Array
  return tag_count(path) if attributes == :tag_count

  attr_value(path, attributes)
end

#tag_count(path) ⇒ Object



91
92
93
# File 'lib/src/extractor.rb', line 91

def tag_count(path)
  node_extractor.extract(path).size
end

#tag_values(base_path, paths) ⇒ Object



95
96
97
98
99
# File 'lib/src/extractor.rb', line 95

def tag_values(base_path, paths)
  return tag_value(base_path) unless paths.is_a? Array

  paths.map { |path| tag_value([base_path, path].flatten.compact.join("/")) }
end