Class: Abroad::Serializers::TrieNode
- Inherits:
-
Object
- Object
- Abroad::Serializers::TrieNode
- Defined in:
- lib/abroad/serializers/trie.rb
Constant Summary collapse
- NO_VALUE =
:__novalue__
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #add_child(key, node) ⇒ Object
- #child_at(key) ⇒ Object
- #each_child ⇒ Object
- #has_child?(key) ⇒ Boolean
- #has_children? ⇒ Boolean
- #has_value? ⇒ Boolean
-
#initialize(value = NO_VALUE) ⇒ TrieNode
constructor
A new instance of TrieNode.
Constructor Details
#initialize(value = NO_VALUE) ⇒ TrieNode
Returns a new instance of TrieNode.
41 42 43 44 |
# File 'lib/abroad/serializers/trie.rb', line 41 def initialize(value = NO_VALUE) @value = value @children = {} end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
38 39 40 |
# File 'lib/abroad/serializers/trie.rb', line 38 def children @children end |
#value ⇒ Object
Returns the value of attribute value.
39 40 41 |
# File 'lib/abroad/serializers/trie.rb', line 39 def value @value end |
Instance Method Details
#add_child(key, node) ⇒ Object
66 67 68 |
# File 'lib/abroad/serializers/trie.rb', line 66 def add_child(key, node) @children[key] = node end |
#child_at(key) ⇒ Object
62 63 64 |
# File 'lib/abroad/serializers/trie.rb', line 62 def child_at(key) children[key] end |
#each_child ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/abroad/serializers/trie.rb', line 46 def each_child if block_given? children.each_pair { |key, child| yield key, child } else children.each end end |
#has_child?(key) ⇒ Boolean
58 59 60 |
# File 'lib/abroad/serializers/trie.rb', line 58 def has_child?(key) children.include?(key) end |
#has_children? ⇒ Boolean
54 55 56 |
# File 'lib/abroad/serializers/trie.rb', line 54 def has_children? !children.empty? end |
#has_value? ⇒ Boolean
70 71 72 |
# File 'lib/abroad/serializers/trie.rb', line 70 def has_value? value != NO_VALUE end |