Class: Hotspots::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/hotspots/store.rb

Overview

:nodoc: all

Instance Method Summary collapse

Constructor Details

#initialize(lines, options = {}) ⇒ Store

Returns a new instance of Store.



3
4
5
6
7
8
9
10
11
12
# File 'lib/hotspots/store.rb', line 3

def initialize(lines, options = {})
  @lines  = lines
  @store  = Hash.new(0)
  @cutoff = options[:cutoff]      || 0
  @filter = options[:file_filter] || ""

  @lines.map   { |line| line.strip }.
         select{ |line| not line.empty? and line =~ Regexp.new(@filter) }.
         each  { |line| @store[line] += 1 }
end

Instance Method Details

#on(line) ⇒ Object



14
15
16
# File 'lib/hotspots/store.rb', line 14

def on(line)
  @store[line]
end

#to_sObject



18
19
20
21
# File 'lib/hotspots/store.rb', line 18

def to_s
  sorted_array.select     { |key, value| value >= @cutoff }.
               reduce("") { |acc, (key, value)| acc << "#{key},#{value}\n" }
end