Class: Tomlrb::Handler
- Inherits:
-
Object
- Object
- Tomlrb::Handler
- Defined in:
- lib/tomlrb/handler.rb
Instance Attribute Summary collapse
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
- #assign(k) ⇒ Object
- #end_array ⇒ Object
-
#initialize ⇒ Handler
constructor
A new instance of Handler.
- #push(o) ⇒ Object
- #result ⇒ Object
- #set_context(name) ⇒ Object
- #start_array ⇒ Object
Constructor Details
#initialize ⇒ Handler
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
#stack ⇒ Object (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_array ⇒ Object
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 |
#result ⇒ Object
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_array ⇒ Object
20 21 22 |
# File 'lib/tomlrb/handler.rb', line 20 def start_array push [:array] end |