Class: Tamiyo::YamlHelper::EventStream
- Inherits:
-
Object
- Object
- Tamiyo::YamlHelper::EventStream
- Defined in:
- lib/tamiyo/yaml/yaml_helper.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #assume_end ⇒ Object
- #assume_mapping ⇒ Object
- #assume_scalar ⇒ Object
- #assume_sequence ⇒ Object
- #each_within_mapping ⇒ Object
- #each_within_sequence ⇒ Object
-
#initialize(queue) ⇒ EventStream
constructor
A new instance of EventStream.
- #next ⇒ Object
- #on_keys(cases) ⇒ Object
- #on_types(cases) ⇒ Object
- #peak ⇒ Object
- #peak_next_is_end ⇒ Object
Constructor Details
#initialize(queue) ⇒ EventStream
Returns a new instance of EventStream.
97 98 99 |
# File 'lib/tamiyo/yaml/yaml_helper.rb', line 97 def initialize(queue) @queue = queue end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
94 95 96 |
# File 'lib/tamiyo/yaml/yaml_helper.rb', line 94 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
95 96 97 |
# File 'lib/tamiyo/yaml/yaml_helper.rb', line 95 def value @value end |
Instance Method Details
#assume_end ⇒ Object
146 147 148 149 |
# File 'lib/tamiyo/yaml/yaml_helper.rb', line 146 def assume_end self.next raise StopIteration, "Assumed end but found #{@type}" unless @type == :end end |
#assume_mapping ⇒ Object
141 142 143 144 |
# File 'lib/tamiyo/yaml/yaml_helper.rb', line 141 def assume_mapping self.next raise StopIteration, "Assumed map but found #{@type}" unless @type == :map end |
#assume_scalar ⇒ Object
130 131 132 133 134 |
# File 'lib/tamiyo/yaml/yaml_helper.rb', line 130 def assume_scalar self.next raise StopIteration, "Assumed scalar but found #{@type}" unless @type == :scalar @value end |
#assume_sequence ⇒ Object
136 137 138 139 |
# File 'lib/tamiyo/yaml/yaml_helper.rb', line 136 def assume_sequence self.next raise StopIteration, "Assumed seq but found #{@type}" unless @type == :seq end |
#each_within_mapping ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/tamiyo/yaml/yaml_helper.rb', line 109 def each_within_mapping assume_mapping until peak_next_is_end yield end assume_end end |
#each_within_sequence ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/tamiyo/yaml/yaml_helper.rb', line 101 def each_within_sequence assume_sequence until peak_next_is_end yield end assume_end end |
#next ⇒ Object
156 157 158 159 160 161 |
# File 'lib/tamiyo/yaml/yaml_helper.rb', line 156 def next event = @peak || @queue.pop @peak = nil @type, @value = event event end |
#on_keys(cases) ⇒ Object
124 125 126 127 128 |
# File 'lib/tamiyo/yaml/yaml_helper.rb', line 124 def on_keys(cases) value = assume_scalar raise StopIteration, "No case for key #{value} available" unless cases.include? value cases[value][] end |
#on_types(cases) ⇒ Object
117 118 119 120 121 122 |
# File 'lib/tamiyo/yaml/yaml_helper.rb', line 117 def on_types(cases) type, _ = peak raise StopIteration, "No case for type #{type} available" unless cases.include? type self.next if type == :scalar cases[type][] end |
#peak ⇒ Object
163 164 165 |
# File 'lib/tamiyo/yaml/yaml_helper.rb', line 163 def peak @peak ||= @queue.pop end |
#peak_next_is_end ⇒ Object
151 152 153 154 |
# File 'lib/tamiyo/yaml/yaml_helper.rb', line 151 def peak_next_is_end type, _ = peak type == :end end |