Class: HadoopDsl::WordCount::WordCountMapper

Inherits:
BaseMapper show all
Defined in:
lib/word_count.rb

Overview

controller

Instance Attribute Summary

Attributes inherited from BaseMapRed

#emitted

Instance Method Summary collapse

Methods inherited from BaseMapper

#identity

Methods inherited from BaseMapRed

#emit

Methods included from DslController

#pre_process, #run

Methods included from DslElement

#method_missing

Constructor Details

#initialize(script, key, value) ⇒ WordCountMapper

Returns a new instance of WordCountMapper.



10
11
12
# File 'lib/word_count.rb', line 10

def initialize(script, key, value)
  super(script, WordCountMapperModel.new(key, value))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HadoopDsl::DslElement

Instance Method Details

#count_uniqObject

emitters



18
19
20
# File 'lib/word_count.rb', line 18

def count_uniq
  @model.value.split.each {|word| emit(word => 1)}
end

#total(*types) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/word_count.rb', line 22

def total(*types)
  types.each do |type|
    case type
    when :bytes
      emit("#{TOTAL_PREFIX}total bytes" => @model.value.gsub(/\s/, '').length)
    when :words
      emit("#{TOTAL_PREFIX}total words" => @model.value.split.size)
    when :lines
      emit("#{TOTAL_PREFIX}total lines" => 1)
    end
  end
end