Class: Lotrb::ListObject
- Inherits:
-
Object
- Object
- Lotrb::ListObject
- Defined in:
- lib/lotrb/list_object.rb
Overview
A data structure to hold list results from an API request ‘results` holds the actual POROs representing the data, while `total`, `limit`, `offset`, `page`, and `pages` hold the corresponding pagination values from the API.
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#initialize(result, klass) ⇒ ListObject
constructor
A new instance of ListObject.
Constructor Details
#initialize(result, klass) ⇒ ListObject
Returns a new instance of ListObject.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lotrb/list_object.rb', line 9 def initialize(result, klass) @total = result["total"] @limit = result["limit"] @offset = result["offset"] @page = result["page"] @pages = result["pages"] @results = result["docs"].map do |hash| klass.from_result_hash(hash) end end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
7 8 9 |
# File 'lib/lotrb/list_object.rb', line 7 def limit @limit end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
7 8 9 |
# File 'lib/lotrb/list_object.rb', line 7 def offset @offset end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
7 8 9 |
# File 'lib/lotrb/list_object.rb', line 7 def page @page end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
7 8 9 |
# File 'lib/lotrb/list_object.rb', line 7 def pages @pages end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
7 8 9 |
# File 'lib/lotrb/list_object.rb', line 7 def results @results end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
7 8 9 |
# File 'lib/lotrb/list_object.rb', line 7 def total @total end |