class Depth::Enumeration::Node
Public Instance Methods
array?()
click to toggle source
# File lib/depth/enumeration/node.rb, line 42 def array? fragment.is_a?(Array) end
current_index()
click to toggle source
# File lib/depth/enumeration/node.rb, line 4 def current_index @current_index ||= 0 end
enumerable?()
click to toggle source
# File lib/depth/enumeration/node.rb, line 57 def enumerable? # ignore other types for the moment array? || hash? end
fragment_type()
click to toggle source
# File lib/depth/enumeration/node.rb, line 50 def fragment_type { Array => :array, Hash => :hash }.fetch(fragment.class, :leaf) end
hash?()
click to toggle source
# File lib/depth/enumeration/node.rb, line 46 def hash? fragment.is_a?(Hash) end
humanized_route()
click to toggle source
# File lib/depth/enumeration/node.rb, line 18 def humanized_route route.map(&:key_or_index) end
leaf?()
click to toggle source
# File lib/depth/enumeration/node.rb, line 62 def leaf? !enumerable? end
next()
click to toggle source
# File lib/depth/enumeration/node.rb, line 22 def next if array? val = fragment[current_index] else val = fragment[fragment.keys[current_index]] end Node.new(self, current_index, val).tap { @current_index += 1 } end
next?()
click to toggle source
# File lib/depth/enumeration/node.rb, line 37 def next? return false if leaf? current_index < fragment.count end
parent_key()
click to toggle source
# File lib/depth/enumeration/node.rb, line 31 def parent_key return nil unless parent.enumerable? # root return parent_index if parent.array? parent.fragment.keys[parent_index] end
root?()
click to toggle source
# File lib/depth/enumeration/node.rb, line 66 def root? parent.nil? end
route()
click to toggle source
# File lib/depth/enumeration/node.rb, line 8 def route route = [] current = self while(!current.root?) route << RouteElement.new(current.parent_key, type: current.fragment_type) current = current.parent end route.reverse end