Class: LangTOMLBuilder
- Inherits:
-
Object
- Object
- LangTOMLBuilder
- Defined in:
- lib/resyma/nise/toml.rb
Instance Attribute Summary collapse
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #add!(path, value) ⇒ Object
-
#initialize ⇒ LangTOMLBuilder
constructor
A new instance of LangTOMLBuilder.
- #make_hash ⇒ Object
Constructor Details
#initialize ⇒ LangTOMLBuilder
Returns a new instance of LangTOMLBuilder.
4 5 6 7 |
# File 'lib/resyma/nise/toml.rb', line 4 def initialize @root = make_hash @prefix = [] end |
Instance Attribute Details
#prefix ⇒ Object
Returns the value of attribute prefix.
13 14 15 |
# File 'lib/resyma/nise/toml.rb', line 13 def prefix @prefix end |
#root ⇒ Object
Returns the value of attribute root.
13 14 15 |
# File 'lib/resyma/nise/toml.rb', line 13 def root @root end |
Instance Method Details
#add!(path, value) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/resyma/nise/toml.rb', line 15 def add!(path, value) raise SyntaxError if path.empty? abs_path = @prefix + path cur = @root abs_path[...-1].each do |name| cur = cur[name.to_sym] end cur[abs_path.last.to_sym] = value end |
#make_hash ⇒ Object
9 10 11 |
# File 'lib/resyma/nise/toml.rb', line 9 def make_hash Hash.new { |hash, key| hash[key] = make_hash } end |