class Extractor
Attributes
formatter[R]
node_extractor[R]
node_value_extractor[R]
path_manipulator[R]
Public Class Methods
new(xml, yml, modifiers)
click to toggle source
# File lib/src/extractor.rb, line 180 def initialize(xml, yml, modifiers) @node_extractor = NodeExtractor.new(xml) @node_value_extractor = NodeValueExtractor.new(node_extractor) @path_manipulator = PathManipulator.new(node_value_extractor) @formatter = Format::Formatter.new(yml, modifiers) end
Public Instance Methods
extract(node)
click to toggle source
# File lib/src/extractor.rb, line 187 def extract(node) base, parent, tag, link, attribute = NodeParamsExtractor.new(node).extract path = PathBuilder.new(base: base, parent: parent, tag: tag).build if link.present? link_path = PathBuilder.new(base: base, parent: parent, tag: link).build if tag.is_a? Array tag = tag.map { |tag_path| replace_link(tag_path, link_path) } else path = replace_link(path, link_path) end end value = path_value(path, tag, attribute) format_value(value, node.props) end
format_value(value, props)
click to toggle source
# File lib/src/extractor.rb, line 209 def format_value(value, props) formatter.format_value(value, props) end
paths_of(base_path, tag_path, link_path = nil)
click to toggle source
# File lib/src/extractor.rb, line 217 def paths_of(base_path, tag_path, link_path = nil) path = PathBuilder.new(base: base_path, tag: tag_path).build if link_path.present? link_path = PathBuilder.new(base: base_path, tag: link_path).build path = replace_link(path, link_path) end node = node_extractor.extract(path) (node || []).size.times.map do |index| "#{path}[#{index + 1}]" end end
replace_link(original_path, link_path)
click to toggle source
# File lib/src/extractor.rb, line 213 def replace_link(original_path, link_path) path_manipulator.replace_link(original_path, link_path) end
unescape!(path)
click to toggle source
# File lib/src/extractor.rb, line 205 def unescape!(path) node_extractor.unescape!(path) end
uniq_paths(paths, uniq_by_path)
click to toggle source
# File lib/src/extractor.rb, line 231 def uniq_paths(paths, uniq_by_path) return paths if uniq_by_path.blank? path_manipulator.uniq_paths(paths, uniq_by_path) end
Private Instance Methods
path_value(path, tag, attribute)
click to toggle source
# File lib/src/extractor.rb, line 241 def path_value(path, tag, attribute) return node_value_extractor.attr_values(path, attribute) if attribute.present? node_value_extractor.tag_values(path, tag) end