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.



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

def initialize(node_extractor)
  @node_extractor = node_extractor
end

Instance Method Details

#attr_values(path, attributes) ⇒ Object



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

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



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

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

#tag_values(base_path, paths) ⇒ Object



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

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