Sha256: 6ba362359f038c7b1c2a7e9d39751db2e26e90dc1cc513f9566fc91e1ff30fde

Contents?: true

Size: 1.07 KB

Versions: 57

Compression:

Stored size: 1.07 KB

Contents

module Mandy
  module Reducers
    class Base < Mandy::Task
      include Mandy::IO::OutputFormatting

      def self.compile(opts={}, &blk)
        Class.new(Mandy::Reducers::Base) do 
          self.class_eval do
            define_method(:reducer, blk) if blk
            define_method(:setup, opts[:setup]) if opts[:setup]
            define_method(:teardown, opts[:teardown]) if opts[:teardown]
          end
        end
      end
    
      def execute
        setup if self.respond_to?(:setup)
        last_key, values = nil, []
        @input.each_line do |line|
           key, value = line.split(KEY_VALUE_SEPERATOR)
           value.chomp!
           last_key = key if last_key.nil?
           if key != last_key
             reducer(last_key, values)
             last_key, values = key, []
           end
           values << value
        end
        reducer(deserialize_key(last_key), values.map {|v| deserialize_value(v) })
        teardown if self.respond_to?(:teardown)
      end
    
      private
      
      def reducer(key,values)
        #nil
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
mandy-0.5.23 lib/mandy/reducers/base_reducer.rb
mandy-0.5.22 lib/mandy/reducers/base_reducer.rb
mandy-0.5.21 lib/mandy/reducers/base_reducer.rb
mandy-0.5.20 lib/mandy/reducers/base_reducer.rb
mandy-0.5.19 lib/mandy/reducers/base_reducer.rb
mandy-0.5.17 lib/mandy/reducers/base_reducer.rb
mandy-0.5.14 lib/mandy/reducers/base_reducer.rb
mandy-0.5.13 lib/mandy/reducers/base_reducer.rb
mandy-0.5.11 lib/mandy/reducers/base_reducer.rb
mandy-0.5.10 lib/mandy/reducers/base_reducer.rb
mandy-0.5.9 lib/mandy/reducers/base_reducer.rb
mandy-0.5.8 lib/mandy/reducers/base_reducer.rb
mandy-0.5.7 lib/mandy/reducers/base_reducer.rb
mandy-0.5.6 lib/mandy/reducers/base_reducer.rb
mandy-0.5.5 lib/mandy/reducers/base_reducer.rb
mandy-0.5.3 lib/mandy/reducers/base_reducer.rb
mandy-0.5.2 lib/mandy/reducers/base_reducer.rb
mandy-0.5.1 lib/mandy/reducers/base_reducer.rb
mandy-0.5 lib/mandy/reducers/base_reducer.rb
mandy-0.4.996 lib/mandy/reducers/base_reducer.rb