Class: ApacheCrunch::MostCommon
- Inherits:
-
ProcedureRoutine
- Object
- ProcedureRoutine
- ApacheCrunch::MostCommon
- Defined in:
- lib/procedure_dsl.rb
Overview
DSL routine that finds the most common n values for the given block.
Returns a list of lists, each of which is [value, count]. This list is sorted by count.
Instance Method Summary collapse
Methods inherited from ProcedureRoutine
#finish, #initialize, #method_missing
Constructor Details
This class inherits a constructor from ApacheCrunch::ProcedureRoutine
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ApacheCrunch::ProcedureRoutine
Instance Method Details
#execute(n, &blk) ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/procedure_dsl.rb', line 257 def execute(n, &blk) counts = CountBy.new(@_log_parser).execute(&blk) # Sort the block values descending sorted_vals = counts.keys.sort do |val_a,val_b| - (counts[val_a] <=> counts[val_b]) end sorted_vals[0..n].map do |val| [val, counts[val]] end end |