class ApacheCrunch::MostCommon

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.

Public Instance Methods

execute(n, &blk) click to toggle source
# 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