Class: Documentation::SearchResult
- Inherits:
-
Object
- Object
- Documentation::SearchResult
- Defined in:
- lib/documentation/search_result.rb
Instance Attribute Summary collapse
-
#page ⇒ Object
Returns the value of attribute page.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#query ⇒ Object
Returns the value of attribute query.
-
#raw_results ⇒ Object
Returns the value of attribute raw_results.
-
#results ⇒ Object
Return the pages.
-
#time ⇒ Object
Returns the value of attribute time.
-
#total_results ⇒ Object
Returns the value of attribute total_results.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Is the result set empty?.
-
#end_result_number ⇒ Object
The number of the last result on the current page.
-
#excerpt_for(page) ⇒ Object
Return the highlight string for a given page.
-
#first_page? ⇒ Boolean
Is this the first page of the result set?.
-
#initialize ⇒ SearchResult
constructor
A new instance of SearchResult.
-
#last_page? ⇒ Boolean
Is this the last page of the result set?.
-
#start_result_number ⇒ Object
The number of the first result on the current page.
-
#total_pages ⇒ Object
The total number of pages in the result set.
Constructor Details
#initialize ⇒ SearchResult
Returns a new instance of SearchResult.
12 13 14 15 16 17 18 |
# File 'lib/documentation/search_result.rb', line 12 def initialize @time = nil @raw_results = {} @page = 1 @total_pages = 1 @per_page = nil end |
Instance Attribute Details
#page ⇒ Object
Returns the value of attribute page.
8 9 10 |
# File 'lib/documentation/search_result.rb', line 8 def page @page end |
#per_page ⇒ Object
Returns the value of attribute per_page.
9 10 11 |
# File 'lib/documentation/search_result.rb', line 9 def per_page @per_page end |
#query ⇒ Object
Returns the value of attribute query.
4 5 6 |
# File 'lib/documentation/search_result.rb', line 4 def query @query end |
#raw_results ⇒ Object
Returns the value of attribute raw_results.
6 7 8 |
# File 'lib/documentation/search_result.rb', line 6 def raw_results @raw_results end |
#results ⇒ Object
Return the pages
23 24 25 |
# File 'lib/documentation/search_result.rb', line 23 def results @results end |
#time ⇒ Object
Returns the value of attribute time.
5 6 7 |
# File 'lib/documentation/search_result.rb', line 5 def time @time end |
#total_results ⇒ Object
Returns the value of attribute total_results.
10 11 12 |
# File 'lib/documentation/search_result.rb', line 10 def total_results @total_results end |
Instance Method Details
#empty? ⇒ Boolean
Is the result set empty?
44 45 46 |
# File 'lib/documentation/search_result.rb', line 44 def empty? self.results.empty? end |
#end_result_number ⇒ Object
The number of the last result on the current page
65 66 67 |
# File 'lib/documentation/search_result.rb', line 65 def end_result_number start_result_number + (results.size) - 1 end |
#excerpt_for(page) ⇒ Object
Return the highlight string for a given page
33 34 35 36 37 38 39 |
# File 'lib/documentation/search_result.rb', line 33 def excerpt_for(page) if @raw_results[page.id] && hl = @raw_results[page.id][:highlights] ERB::Util.html_escape((hl.join("..."))).gsub('{{{', "<mark>").gsub("}}}", "</mark>").html_safe else page.content[0,255].gsub(/[\n\r]/, '') + "..." end end |
#first_page? ⇒ Boolean
Is this the first page of the result set?
72 73 74 |
# File 'lib/documentation/search_result.rb', line 72 def first_page? page == 1 end |
#last_page? ⇒ Boolean
Is this the last page of the result set?
79 80 81 |
# File 'lib/documentation/search_result.rb', line 79 def last_page? page == total_pages end |
#start_result_number ⇒ Object
The number of the first result on the current page
58 59 60 |
# File 'lib/documentation/search_result.rb', line 58 def start_result_number ((page - 1) * per_page) + 1 end |
#total_pages ⇒ Object
The total number of pages in the result set
51 52 53 |
# File 'lib/documentation/search_result.rb', line 51 def total_pages (total_results / per_page.to_f).ceil end |