Class: Extractor
- Inherits:
-
Object
- Object
- Extractor
- Defined in:
- lib/src/extractor.rb
Instance Method Summary collapse
- #extract(node) ⇒ Object
- #format_value(value, props) ⇒ Object
-
#initialize(xml, yml, modifiers) ⇒ Extractor
constructor
A new instance of Extractor.
- #paths_of(base_path, tag_path, link_path = nil) ⇒ Object
- #replace_link(original_path, link_path) ⇒ Object
- #unescape!(path) ⇒ Object
- #uniq_paths(paths, uniq_by_path) ⇒ Object
Constructor Details
#initialize(xml, yml, modifiers) ⇒ Extractor
Returns a new instance of Extractor.
183 184 185 186 187 188 |
# File 'lib/src/extractor.rb', line 183 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 |
Instance Method Details
#extract(node) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/src/extractor.rb', line 190 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) ⇒ Object
212 213 214 |
# File 'lib/src/extractor.rb', line 212 def format_value(value, props) formatter.format_value(value, props) end |
#paths_of(base_path, tag_path, link_path = nil) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/src/extractor.rb', line 220 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) ⇒ Object
216 217 218 |
# File 'lib/src/extractor.rb', line 216 def replace_link(original_path, link_path) path_manipulator.replace_link(original_path, link_path) end |
#unescape!(path) ⇒ Object
208 209 210 |
# File 'lib/src/extractor.rb', line 208 def unescape!(path) node_extractor.unescape!(path) end |
#uniq_paths(paths, uniq_by_path) ⇒ Object
234 235 236 237 238 |
# File 'lib/src/extractor.rb', line 234 def uniq_paths(paths, uniq_by_path) return paths if uniq_by_path.blank? path_manipulator.uniq_paths(paths, uniq_by_path) end |