Class: Bataille::SearchResult

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bataille/search_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#resultsObject

Returns the value of attribute results.



4
5
6
# File 'lib/bataille/search_result.rb', line 4

def results
  @results
end

#wordObject

Returns the value of attribute word.



4
5
6
# File 'lib/bataille/search_result.rb', line 4

def word
  @word
end

Instance Method Details

#eachObject



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

#lengthObject



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