Class: Clr::Search
- Inherits:
-
Object
- Object
- Clr::Search
- Defined in:
- lib/clr/search.rb
Defined Under Namespace
Classes: Item
Instance Attribute Summary collapse
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#initialize ⇒ Search
constructor
A new instance of Search.
- #perform(file, pattern) ⇒ Object
- #summary ⇒ Object
Constructor Details
#initialize ⇒ Search
Returns a new instance of Search.
11 12 13 |
# File 'lib/clr/search.rb', line 11 def initialize @results = Array.new end |
Instance Attribute Details
#results ⇒ Object (readonly)
Returns the value of attribute results.
3 4 5 |
# File 'lib/clr/search.rb', line 3 def results @results end |
Instance Method Details
#perform(file, pattern) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/clr/search.rb', line 15 def perform(file, pattern) text = file.binread matches = text.scan(pattern) item = Item.new(file, pattern, matches) results.push(item).last end |
#summary ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/clr/search.rb', line 22 def summary results.group_by(&:filepath).each do |filepath, collection| # number of markers in file occurrences = collection.map(&:matches_count).inject(0,:+) yield filepath, occurrences, collection if occurrences > 0 end end |