class Extract::ArrayOf
Attributes
index[R]
Public Class Methods
new(node, extractor, index = 0)
click to toggle source
Calls superclass method
# File lib/src/extract/array_of.rb, line 3 def initialize(node, extractor, index = 0) super(node, extractor) @index = index end
Public Instance Methods
value()
click to toggle source
# File lib/src/extract/array_of.rb, line 8 def value process_paths.flatten.compact end
Private Instance Methods
array_items()
click to toggle source
# File lib/src/extract/array_of.rb, line 16 def array_items arr_path, link_path, uniq_by = node.array_of_paths paths = extractor.paths_of(node.path, arr_path, link_path) paths = uniq_paths(paths, uniq_by) if uniq_by paths.each_with_index.map do |path, idx| HashBuilder.new(Node.new(node.props, path), extractor).value(index + idx) end.compact end
build_path(hash)
click to toggle source
# File lib/src/extract/array_of.rb, line 50 def build_path(hash) extractor.replace_link(hash[:path], [node.path, hash[:link]].join("/")) end
paths_from_props()
click to toggle source
# File lib/src/extract/array_of.rb, line 54 def paths_from_props [node.props[:array_of]].flatten end
process_path(path, inner_paths)
click to toggle source
# File lib/src/extract/array_of.rb, line 38 def process_path(path, inner_paths) path = build_path(path) if path.is_a?(Hash) extractor.paths_of(node.path, path).each_with_index.map do |some, idx| ArrayOf.new(Node.new(node.props.merge(array_of: inner_paths), some), extractor, index + idx).value end end
process_paths()
click to toggle source
# File lib/src/extract/array_of.rb, line 27 def process_paths paths = paths_from_props if paths.size > 1 process_path(paths.shift, paths) else node.props[:array_of] = paths.first array_items end end
uniq_paths(paths, uniq_by)
click to toggle source
# File lib/src/extract/array_of.rb, line 46 def uniq_paths(paths, uniq_by) extractor.uniq_paths(paths, uniq_by) end