Class: LangTOMLBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/resyma/nise/toml.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLangTOMLBuilder

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

#prefixObject

Returns the value of attribute prefix.



13
14
15
# File 'lib/resyma/nise/toml.rb', line 13

def prefix
  @prefix
end

#rootObject

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

Raises:

  • (SyntaxError)


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_hashObject



9
10
11
# File 'lib/resyma/nise/toml.rb', line 9

def make_hash
  Hash.new { |hash, key| hash[key] = make_hash }
end