Class: Chivy::Tree
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#name ⇒ Object
Returns the value of attribute name.
-
#tree ⇒ Object
Returns the value of attribute tree.
Class Method Summary collapse
-
.dump(answers) ⇒ Object
returns a yaml string of the answers.
-
.load(string) ⇒ Object
returns an answer-intance from the yaml string.
Instance Method Summary collapse
-
#build_tree ⇒ Object
returns the tree as an instance of Hash.
-
#initialize(filename) ⇒ Tree
constructor
returns self (instance of Answers) after building the tree by its template.
- #load(file) ⇒ Object
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
#file ⇒ Object
Returns the value of attribute file.
16 17 18 |
# File 'lib/chivy/tree.rb', line 16 def file @file end |
#locale ⇒ Object
Returns the value of attribute locale.
16 17 18 |
# File 'lib/chivy/tree.rb', line 16 def locale @locale end |
#name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/chivy/tree.rb', line 16 def name @name end |
#tree ⇒ Object
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 |
Instance Method Details
#build_tree ⇒ Object
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 |