Class: Abroad::Serializers::TrieNode

Inherits:
Object
  • Object
show all
Defined in:
lib/abroad/serializers/trie.rb

Constant Summary collapse

NO_VALUE =
:__novalue__

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#childrenObject (readonly)

Returns the value of attribute children.



38
39
40
# File 'lib/abroad/serializers/trie.rb', line 38

def children
  @children
end

#valueObject

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_childObject



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

Returns:

  • (Boolean)


58
59
60
# File 'lib/abroad/serializers/trie.rb', line 58

def has_child?(key)
  children.include?(key)
end

#has_children?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/abroad/serializers/trie.rb', line 54

def has_children?
  !children.empty?
end

#has_value?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/abroad/serializers/trie.rb', line 70

def has_value?
  value != NO_VALUE
end