Class: Command::Results::HashArrayFormatter
- Inherits:
-
Formatter
- Object
- Formatter
- Command::Results::HashArrayFormatter
show all
- Defined in:
- lib/command-set/formatter/hash-array.rb
Instance Attribute Summary
Attributes inherited from Formatter
#advice
Instance Method Summary
collapse
Methods inherited from Formatter
#apply_advice, #default_advice, #finish, #notify, #receive_advice, #saw_begin_list, #saw_end_list, #saw_item, #start
Constructor Details
Returns a new instance of HashArrayFormatter.
5
6
7
8
|
# File 'lib/command-set/formatter/hash-array.rb', line 5
def initialize
@hash_stack = [{:array => []}]
super
end
|
Instance Method Details
#array ⇒ Object
14
15
16
|
# File 'lib/command-set/formatter/hash-array.rb', line 14
def array
hash[:array]
end
|
#closed_begin_list(list) ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'lib/command-set/formatter/hash-array.rb', line 18
def closed_begin_list(list)
list_array = []
list_hash = {:array => list_array}
array.push(list_array)
hash[array().length.to_s] = list_hash
hash[list.name] = list_hash
@hash_stack.push(list_hash)
end
|
#closed_end_list(list) ⇒ Object
33
34
35
|
# File 'lib/command-set/formatter/hash-array.rb', line 33
def closed_end_list(list)
@hash_stack.pop
end
|
#closed_item(item) ⇒ Object
27
28
29
30
31
|
# File 'lib/command-set/formatter/hash-array.rb', line 27
def closed_item(item)
thing = item.value
array().push(thing)
hash()[array().length.to_s] = thing
end
|
#hash ⇒ Object
10
11
12
|
# File 'lib/command-set/formatter/hash-array.rb', line 10
def hash
@hash_stack.last
end
|
#structure ⇒ Object
37
38
39
|
# File 'lib/command-set/formatter/hash-array.rb', line 37
def structure
@hash_stack.first
end
|