Class: Hotspots::Store
- Inherits:
-
Object
- Object
- Hotspots::Store
- Defined in:
- lib/hotspots/store.rb
Overview
:nodoc: all
Instance Method Summary collapse
-
#initialize(lines, options = {}) ⇒ Store
constructor
A new instance of Store.
- #on(line) ⇒ Object
- #to_s ⇒ Object
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, = {}) @lines = lines @store = Hash.new(0) @cutoff = [:cutoff] || 0 @filter = [:file_filter] || "" @lines.map { |line| line.strip }. select{ |line| !line.empty? && 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_s ⇒ Object
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 |