Sha256: 5f43ab47dfe19e2bd65346effb244b69b38c07a42e2f206dea1ff79df46dd678

Contents?: true

Size: 1.11 KB

Versions: 21

Compression:

Stored size: 1.11 KB

Contents

require "#{File.dirname(__FILE__)}/../lib/stages"

include Stages

#count the occurance of each letter in these song lyrics
@lyrics = 
  { :do => 'doe a deer a female deer',
    :re => 'ray a drop of golden sun',
    :mi => 'me a name I call myself',
    :fa => 'far a long long way to run',
    :so => 'a needle pulling thread',
    :la => 'a note to follow so',
    :ti => 'a drink with jam and bread'}

class Lyrics < Stage
  attr_accessor :lyrics
  def handle_value(value)
    output @lyrics[value]
  end
end

class Generator < Stage
  def initialize(things)
    @things = things
    super()
  end
  
  def process
    @things.each do |t|
      output t
    end
  end
end

def setup_pipeline
  get_lyric = Lyrics.new
  get_lyric.lyrics = @lyrics
  
  each_character = Each.new{ |x| x.chars }
  trim_whitespace = Select.new{ |x| x != ' '}
  letters_in_each_line = Wrap.new(get_lyric | each_character | trim_whitespace, :array)
  each_letter = Each.new
  each_note = Generator.new(@lyrics.keys)
  count_everything = Count.new
  
  each_note | letters_in_each_line | each_letter | count_everything
end

puts setup_pipeline.run.inspect



Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
stages-0.2.4 examples/sing_custom_stages.rb