Class: Tomlrb::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/tomlrb/handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHandler

Returns a new instance of Handler.



5
6
7
8
9
# File 'lib/tomlrb/handler.rb', line 5

def initialize
  @output = Hash.new {|h, k| h[k] = {} }
  @current = @output
  @stack = []
end

Instance Attribute Details

#stackObject (readonly)

Returns the value of attribute stack.



3
4
5
# File 'lib/tomlrb/handler.rb', line 3

def stack
  @stack
end

Instance Method Details

#assign(k) ⇒ Object



16
17
18
# File 'lib/tomlrb/handler.rb', line 16

def assign(k)
  @current[k] = @stack.pop
end

#end_arrayObject



24
25
26
27
28
29
30
31
# File 'lib/tomlrb/handler.rb', line 24

def end_array
  array = []
  while (value = @stack.pop) != [:array]
    raise if value.nil?
    array.unshift(value)
  end
  push(array)
end

#push(o) ⇒ Object



33
34
35
# File 'lib/tomlrb/handler.rb', line 33

def push(o)
  @stack << o
end

#resultObject



37
38
39
# File 'lib/tomlrb/handler.rb', line 37

def result
  @output
end

#set_context(name) ⇒ Object



11
12
13
14
# File 'lib/tomlrb/handler.rb', line 11

def set_context(name)
  @current = @output[name]
  @context = name
end

#start_arrayObject



20
21
22
# File 'lib/tomlrb/handler.rb', line 20

def start_array
  push [:array]
end