class Lev::Outputs

Public Class Methods

new(source_hash = nil, default = nil, &blk) click to toggle source
Calls superclass method
# File lib/lev/outputs.rb, line 4
def initialize(source_hash = nil, default = nil, &blk)
  @array_created = {}
  super(source_hash, default, &blk)
end

Public Instance Methods

add(name, value) click to toggle source
# File lib/lev/outputs.rb, line 9
def add(name, value)
  if self[name].nil?
    self[name] = value
  elsif @array_created[name]
    self[name].push value
  else
    @array_created[name] = true
    self[name] = [self[name], value]
  end
end
each() { |key, value| ... } click to toggle source
# File lib/lev/outputs.rb, line 20
def each
  self.each_key do |key|
    key = key.to_sym
    if @array_created[key]
      self[key].each { |value| yield key, value }
    else
      yield key, self[key]
    end
  end
end
transfer_to(other_outputs, &name_mapping_block) click to toggle source
# File lib/lev/outputs.rb, line 31
def transfer_to(other_outputs, &name_mapping_block)
  self.each do |name, value|
    new_name = block_given? ? name_mapping_block.call(name) : name
    other_outputs.add(new_name, value)
  end
end