Class: Chivy::Tree

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/chivy/tree.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Tree

returns self (instance of Answers) after building the tree by its template



27
28
29
30
31
32
# File 'lib/chivy/tree.rb', line 27

def initialize(filename)
  build_tree
  split_filename = filename.split('.')
  @locale = split_filename[-2]
  @name = split_filename.first
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



16
17
18
# File 'lib/chivy/tree.rb', line 16

def file
  @file
end

#localeObject

Returns the value of attribute locale.



16
17
18
# File 'lib/chivy/tree.rb', line 16

def locale
  @locale
end

#nameObject

Returns the value of attribute name.



16
17
18
# File 'lib/chivy/tree.rb', line 16

def name
  @name
end

#treeObject

Returns the value of attribute tree.



16
17
18
# File 'lib/chivy/tree.rb', line 16

def tree
  @tree
end

Class Method Details

.dump(answers) ⇒ Object

returns a yaml string of the answers



41
42
43
# File 'lib/chivy/tree.rb', line 41

def self.dump(answers)
  data.to_yaml
end

.load(string) ⇒ Object

returns an answer-intance from the yaml string



47
48
49
50
# File 'lib/chivy/tree.rb', line 47

def self.load(string)
  data = Tree.new
  data.load(string)
end

Instance Method Details

#build_treeObject

returns the tree as an instance of Hash



36
37
38
# File 'lib/chivy/tree.rb', line 36

def build_tree
  @tree = {}
end

#load(file) ⇒ Object



18
19
20
21
22
# File 'lib/chivy/tree.rb', line 18

def load(file)
  @file = file
  @tree = ::YAML.load_file(file)[locale] if file
  @tree
end