Class: Wukong::Processor::Head

Inherits:
Filter show all
Defined in:
lib/wukong/widget/filters.rb

Overview

Emit only the first n records.

See Also:

Constant Summary

Constants inherited from Wukong::Processor

SerializerError

Instance Attribute Summary collapse

Attributes included from Hanuman::StageInstanceMethods

#graph

Instance Method Summary collapse

Methods inherited from Filter

#process, #reject?

Methods inherited from Wukong::Processor

configure, description, #finalize, #perform_action, #process, #receive_action, #stop

Methods included from Logging

included

Methods inherited from Hanuman::Stage

#clone

Methods included from Hanuman::StageClassMethods

#builder, #label, #register, #set_builder

Methods included from Hanuman::StageInstanceMethods

#add_link, #linkable_name, #root

Instance Attribute Details

#countObject

The current record count.



383
384
385
# File 'lib/wukong/widget/filters.rb', line 383

def count
  @count
end

Instance Method Details

#select?(record) ⇒ true, false

Select a record only if we're below the maximum number of records.

Parameters:

  • record (Object)

Returns:

  • (true, false)


395
396
397
398
399
# File 'lib/wukong/widget/filters.rb', line 395

def select?(record)
  keep = @count < n
  @count += 1
  keep
end

#setupObject

Initializes the record count to zero.



386
387
388
# File 'lib/wukong/widget/filters.rb', line 386

def setup
  self.count = 0
end