Class: TwitterCldr::Utils::FileSystemTrie

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_cldr/utils/file_system_trie.rb

Defined Under Namespace

Classes: Node

Constant Summary collapse

VALUE_FILE =
'value.dump'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path_root, root = Node.new) ⇒ FileSystemTrie

Returns a new instance of FileSystemTrie.



17
18
19
20
# File 'lib/twitter_cldr/utils/file_system_trie.rb', line 17

def initialize(path_root, root = Node.new)
  @path_root = path_root
  @root = root
end

Instance Attribute Details

#path_rootObject (readonly)

Returns the value of attribute path_root.



15
16
17
# File 'lib/twitter_cldr/utils/file_system_trie.rb', line 15

def path_root
  @path_root
end

Instance Method Details

#add(key, value) ⇒ Object



26
27
28
# File 'lib/twitter_cldr/utils/file_system_trie.rb', line 26

def add(key, value)
  store(key, value, false)
end

#empty?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/twitter_cldr/utils/file_system_trie.rb', line 22

def empty?
  !@root.has_children?
end

#get(key) ⇒ Object



34
35
36
37
# File 'lib/twitter_cldr/utils/file_system_trie.rb', line 34

def get(key)
  node = get_node(key)
  node && node.value
end

#get_node(key) ⇒ Object



39
40
41
42
43
44
# File 'lib/twitter_cldr/utils/file_system_trie.rb', line 39

def get_node(key)
  traverse(key) do |node, key_element|
    return unless node
    node.child(key_element)
  end
end

#set(key, value) ⇒ Object



30
31
32
# File 'lib/twitter_cldr/utils/file_system_trie.rb', line 30

def set(key, value)
  store(key, value)
end