Class: HadoopDsl::WordCount::WordCountMapper
- Inherits:
-
BaseMapper
- Object
- BaseMapRed
- BaseMapper
- HadoopDsl::WordCount::WordCountMapper
- Defined in:
- lib/word_count.rb
Overview
controller
Instance Attribute Summary
Attributes inherited from BaseMapRed
Instance Method Summary collapse
-
#count_uniq ⇒ Object
emitters.
-
#initialize(script, key, value) ⇒ WordCountMapper
constructor
A new instance of WordCountMapper.
- #total(*types) ⇒ Object
Methods inherited from BaseMapper
Methods inherited from BaseMapRed
Methods included from DslController
Methods included from DslElement
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_uniq ⇒ Object
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 |