class Stamp::Emitters::Composite

Attributes

emitters[R]

Public Class Methods

new(emitters=[]) click to toggle source
# File lib/stamp/emitters/composite.rb, line 8
def initialize(emitters=[])
  @emitters = emitters
end

Public Instance Methods

-(others) click to toggle source
# File lib/stamp/emitters/composite.rb, line 28
def -(others)
  emitters - Array(others)
end
<<(emitter) click to toggle source
# File lib/stamp/emitters/composite.rb, line 20
def <<(emitter)    
  Array(emitter).each { |e| emitters << e }
end
each(&block) click to toggle source
# File lib/stamp/emitters/composite.rb, line 24
def each(&block)
  emitters.each(&block)
end
format(target) click to toggle source
# File lib/stamp/emitters/composite.rb, line 12
def format(target)
  # NOTE using #each to build string because benchmarking shows
  # that it's ~20% faster than .map.join('')
  result = ''
  emitters.each { |e| result << e.format(target).to_s }
  result
end
replace_each!() { |emitter| ... } click to toggle source

Replace each element as we iterate with the result of the given block.

# File lib/stamp/emitters/composite.rb, line 33
def replace_each!
  emitters.each_with_index do |emitter, index|
    emitters[index] = yield(emitter)
  end

  self
end