Class: Poliqarp::QueryResult
- Inherits:
-
Object
- Object
- Poliqarp::QueryResult
- Includes:
- Enumerable
- Defined in:
- lib/poliqarpr/query_result.rb
Overview
- Author
-
Aleksander Pohl ([email protected])
- License
-
MIT License
The query result class is used to paginate results of the query. Each query result has information about its context (the next and previous page).
Instance Attribute Summary collapse
-
#page ⇒ Object
Returns the value of attribute page.
-
#page_count ⇒ Object
Returns the value of attribute page_count.
-
#page_size ⇒ Object
Returns the value of attribute page_size.
-
#query ⇒ Object
Returns the value of attribute query.
Instance Method Summary collapse
-
#<<(excerpt) ⇒ Object
Adds excerpt to the query result.
-
#==(other) ⇒ Object
Two excerpts are equal iff their page number, page count, query and page size are equal.
-
#[](index) ⇒ Object
Returns excerpt with given index.
-
#each ⇒ Object
Allows to iterate over the results stored in the result.
-
#initialize(page, page_count, page_size, client, query) ⇒ QueryResult
constructor
A new instance of QueryResult.
-
#next_page ⇒ Object
Return the next page of the query result.
-
#previous_page ⇒ Object
Returns the previous page of the query result.
-
#size ⇒ Object
Returns the number of excerpts stored in this page (query result).
Constructor Details
#initialize(page, page_count, page_size, client, query) ⇒ QueryResult
Returns a new instance of QueryResult.
13 14 15 16 17 18 19 20 |
# File 'lib/poliqarpr/query_result.rb', line 13 def initialize(page, page_count, page_size, client, query) @page = page @page_count = page_count @page_size = page_size @client = client @query = query @excerpts = [] end |
Instance Attribute Details
#page ⇒ Object
Returns the value of attribute page.
11 12 13 |
# File 'lib/poliqarpr/query_result.rb', line 11 def page @page end |
#page_count ⇒ Object
Returns the value of attribute page_count.
11 12 13 |
# File 'lib/poliqarpr/query_result.rb', line 11 def page_count @page_count end |
#page_size ⇒ Object
Returns the value of attribute page_size.
11 12 13 |
# File 'lib/poliqarpr/query_result.rb', line 11 def page_size @page_size end |
#query ⇒ Object
Returns the value of attribute query.
11 12 13 |
# File 'lib/poliqarpr/query_result.rb', line 11 def query @query end |
Instance Method Details
#<<(excerpt) ⇒ Object
Adds excerpt to the query result
23 24 25 |
# File 'lib/poliqarpr/query_result.rb', line 23 def <<(excerpt) @excerpts << excerpt end |
#==(other) ⇒ Object
Two excerpts are equal iff their page number, page count, query and page size are equal.
45 46 47 48 49 |
# File 'lib/poliqarpr/query_result.rb', line 45 def ==(other) return false unless other.is_a? QueryResult @page == other.page && @page_count == other.page_count && @query == other.query && @page_size == other.page_size end |
#[](index) ⇒ Object
Returns excerpt with given index.
39 40 41 |
# File 'lib/poliqarpr/query_result.rb', line 39 def [](index) @excerpts[index] end |
#each ⇒ Object
Allows to iterate over the results stored in the result
28 29 30 |
# File 'lib/poliqarpr/query_result.rb', line 28 def each @excerpts.each{|e| yield e} end |
#next_page ⇒ Object
Return the next page of the query result
60 61 62 63 64 65 |
# File 'lib/poliqarpr/query_result.rb', line 60 def next_page if @page < @page_count @client.find(@query, :page_size => @page_size, :page_index => @page + 1) end end |
#previous_page ⇒ Object
Returns the previous page of the query result
52 53 54 55 56 57 |
# File 'lib/poliqarpr/query_result.rb', line 52 def previous_page if @page > 1 @client.find(@query, :page_size => @page_size, :page_index => @page - 1) end end |
#size ⇒ Object
Returns the number of excerpts stored in this page (query result)
68 69 70 |
# File 'lib/poliqarpr/query_result.rb', line 68 def size @excerpts.size end |