Class: Bataille::SearchResult
- Inherits:
-
Object
- Object
- Bataille::SearchResult
- Includes:
- Enumerable
- Defined in:
- lib/bataille/search_result.rb
Instance Attribute Summary collapse
-
#results ⇒ Object
Returns the value of attribute results.
-
#word ⇒ Object
Returns the value of attribute word.
Instance Method Summary collapse
- #each ⇒ Object
- #find_by(match, site, opt = {}) ⇒ Object
-
#initialize(results, word) ⇒ SearchResult
constructor
A new instance of SearchResult.
- #length ⇒ Object
- #limit(n = 1) ⇒ Object (also: #top)
- #where(conditions, opt = {}) ⇒ Object
Constructor Details
#initialize(results, word) ⇒ SearchResult
Returns a new instance of SearchResult.
6 7 8 |
# File 'lib/bataille/search_result.rb', line 6 def initialize(results, word) @results, @word = results, word end |
Instance Attribute Details
#results ⇒ Object
Returns the value of attribute results.
4 5 6 |
# File 'lib/bataille/search_result.rb', line 4 def results @results end |
#word ⇒ Object
Returns the value of attribute word.
4 5 6 |
# File 'lib/bataille/search_result.rb', line 4 def word @word end |
Instance Method Details
#each ⇒ Object
14 15 16 |
# File 'lib/bataille/search_result.rb', line 14 def each @results.each { |r| yield r } end |
#find_by(match, site, opt = {}) ⇒ Object
29 30 31 |
# File 'lib/bataille/search_result.rb', line 29 def find_by(match, site, opt={}) finder(match, site, opt).first end |
#length ⇒ Object
10 11 12 |
# File 'lib/bataille/search_result.rb', line 10 def length @results.length end |
#limit(n = 1) ⇒ Object Also known as: top
18 19 20 |
# File 'lib/bataille/search_result.rb', line 18 def limit(n=1) self.class.new(@results[0..n-1]) end |
#where(conditions, opt = {}) ⇒ Object
23 24 25 26 27 |
# File 'lib/bataille/search_result.rb', line 23 def where(conditions, opt={}) conditions.inject(self) do |result,(key, value)| Bataille::SearchResult.new(finder(key, value, opt), @word) end end |