class Tamiyo::YamlHelper::EventStream

Attributes

type[R]
value[R]

Public Class Methods

new(queue) click to toggle source
# File lib/tamiyo/yaml/yaml_helper.rb, line 97
def initialize(queue)
  @queue = queue
end

Public Instance Methods

assume_end() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() { || ... } click to toggle source
# 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() { || ... } click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/tamiyo/yaml/yaml_helper.rb, line 163
def peak
  @peak ||= @queue.pop
end
peak_next_is_end() click to toggle source
# File lib/tamiyo/yaml/yaml_helper.rb, line 151
def peak_next_is_end
  type, _ = peak
  type == :end
end