Class: JPathTree
- Inherits:
-
Object
- Object
- JPathTree
- Defined in:
- lib/json/stream/j_path_tree.rb
Instance Attribute Summary collapse
-
#jpath ⇒ Object
Returns the value of attribute jpath.
-
#tree ⇒ Object
Returns the value of attribute tree.
Instance Method Summary collapse
-
#initialize(jpath) ⇒ JPathTree
constructor
A new instance of JPathTree.
- #parsing_feasible?(key) ⇒ Boolean
Constructor Details
#initialize(jpath) ⇒ JPathTree
Returns a new instance of JPathTree.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/json/stream/j_path_tree.rb', line 4 def initialize(jpath) self.jpath = jpath self.tree = (jpath.nil? or jpath.empty? or !jpath.match(/^\//)) ? nil : {} self.tree || return prev_key = nil self.jpath.split('/')[1..-1].each do |name| name = name.intern self.tree[name] = {prev: prev_key, value: false, next: nil} self.tree[prev_key][:next] = name if prev_key prev_key = name end end |
Instance Attribute Details
#jpath ⇒ Object
Returns the value of attribute jpath.
2 3 4 |
# File 'lib/json/stream/j_path_tree.rb', line 2 def jpath @jpath end |
#tree ⇒ Object
Returns the value of attribute tree.
2 3 4 |
# File 'lib/json/stream/j_path_tree.rb', line 2 def tree @tree end |
Instance Method Details
#parsing_feasible?(key) ⇒ Boolean
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/json/stream/j_path_tree.rb', line 18 def parsing_feasible?(key) key = key.is_a?(String) ? key.intern : nil return if key.nil? or self.tree.nil? or self.tree.empty? node = self.tree[key] return unless (node) return if (node[:value]) prev_node = self.tree[node[:prev]] next_node = self.tree[node[:next]] if (next_node.nil?) if (prev_node.nil? || prev_node[:value]) node[:value] = true return true end elsif (prev_node.nil? || prev_node[:value]) node[:value] = true return nil else return nil end end |