Class: MdnQuery::SearchResult
- Inherits:
-
Object
- Object
- MdnQuery::SearchResult
- Defined in:
- lib/mdn_query/search_result.rb
Overview
A result from a search query.
Instance Attribute Summary collapse
-
#items ⇒ Array<Hash>
readonly
The raw items of the search result.
-
#pages ⇒ Hash
readonly
Information about the pages.
-
#query ⇒ String
readonly
The query that was searched for.
-
#total ⇒ Fixnum
readonly
The total number of entries.
Instance Method Summary collapse
-
#current_page ⇒ Fixnum
Returns the number of the current page.
-
#empty? ⇒ Boolean
Returns whether there are any entries.
-
#initialize(query, json) ⇒ MdnQuery::SearchResult
constructor
Creates a new search result.
-
#next? ⇒ Boolean
Returns whether there is a next page.
-
#previous? ⇒ Boolean
Returns whether there is a previous page.
-
#to_list ⇒ MdnQuery::List
Creates a list with the items.
Constructor Details
#initialize(query, json) ⇒ MdnQuery::SearchResult
Creates a new search result.
21 22 23 24 25 26 27 28 29 |
# File 'lib/mdn_query/search_result.rb', line 21 def initialize(query, json) @query = query @pages = { count: json[:pages] || 0, current: json[:page] } @total = json[:count] @items = json[:documents] end |
Instance Attribute Details
#items ⇒ Array<Hash> (readonly)
Returns the raw items of the search result.
5 6 7 |
# File 'lib/mdn_query/search_result.rb', line 5 def items @items end |
#pages ⇒ Hash (readonly)
Returns information about the pages.
8 9 10 |
# File 'lib/mdn_query/search_result.rb', line 8 def pages @pages end |
#query ⇒ String (readonly)
Returns the query that was searched for.
11 12 13 |
# File 'lib/mdn_query/search_result.rb', line 11 def query @query end |
#total ⇒ Fixnum (readonly)
Returns the total number of entries.
14 15 16 |
# File 'lib/mdn_query/search_result.rb', line 14 def total @total end |
Instance Method Details
#current_page ⇒ Fixnum
Returns the number of the current page.
55 56 57 |
# File 'lib/mdn_query/search_result.rb', line 55 def current_page @pages[:current] end |
#empty? ⇒ Boolean
Returns whether there are any entries.
34 35 36 |
# File 'lib/mdn_query/search_result.rb', line 34 def empty? @pages[:count].zero? end |
#next? ⇒ Boolean
Returns whether there is a next page.
41 42 43 |
# File 'lib/mdn_query/search_result.rb', line 41 def next? !empty? && @pages[:current] < @pages[:count] end |
#previous? ⇒ Boolean
Returns whether there is a previous page.
48 49 50 |
# File 'lib/mdn_query/search_result.rb', line 48 def previous? !empty? && @pages[:current] > 1 end |