Sha256: 1f7bafd95ae6d0c1b8bec6a264f30b046effaac4d16f59484595dd01c88a5b97

Contents?: true

Size: 708 Bytes

Versions: 18

Compression:

Stored size: 708 Bytes

Contents

module Wukong
  module Streamer
    #
    # For each identical line in the map phase output, emit one representative
    # line followed by the count of occrrences (separated by a tab).
    #
    # (This is the functional equivalent of +'uniq -c'+)
    #
    class CountLines < Wukong::Streamer::Base
      def formatted_count item, key_count
        "%s\t%10d" % [item, key_count.to_i]
      end

      #
      # Delegate to +uniq -c+, but put the count last for idempotence.
      #
      def stream
        %x{/usr/bin/uniq -c}.split("\n").each do |line|
          key_count, item = line.chomp.strip.split(/\s+/, 2)
          puts formatted_count(item, key_count)
        end
      end
    end

  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
mrflip-wukong-0.1.0 lib/wukong/streamer/count_lines.rb
wukong-1.5.4 lib/wukong/streamer/count_lines.rb
wukong-1.5.3 lib/wukong/streamer/count_lines.rb
wukong-1.5.2 lib/wukong/streamer/count_lines.rb
wukong-1.5.1 lib/wukong/streamer/count_lines.rb
wukong-1.5.0 lib/wukong/streamer/count_lines.rb
wukong-1.4.12 lib/wukong/streamer/count_lines.rb
wukong-1.4.11 lib/wukong/streamer/count_lines.rb
wukong-1.4.10 lib/wukong/streamer/count_lines.rb
wukong-1.4.9 lib/wukong/streamer/count_lines.rb
wukong-1.4.7 lib/wukong/streamer/count_lines.rb
wukong-1.4.6 lib/wukong/streamer/count_lines.rb
wukong-1.4.5 lib/wukong/streamer/count_lines.rb
wukong-1.4.2 lib/wukong/streamer/count_lines.rb
wukong-1.4.1 lib/wukong/streamer/count_lines.rb
wukong-1.4.0 lib/wukong/streamer/count_lines.rb
wukong-0.1.4 lib/wukong/streamer/count_lines.rb
wukong-0.1.1 lib/wukong/streamer/count_lines.rb