Class: Lotrb::ListObject

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#limitObject (readonly)

Returns the value of attribute limit.



7
8
9
# File 'lib/lotrb/list_object.rb', line 7

def limit
  @limit
end

#offsetObject (readonly)

Returns the value of attribute offset.



7
8
9
# File 'lib/lotrb/list_object.rb', line 7

def offset
  @offset
end

#pageObject (readonly)

Returns the value of attribute page.



7
8
9
# File 'lib/lotrb/list_object.rb', line 7

def page
  @page
end

#pagesObject (readonly)

Returns the value of attribute pages.



7
8
9
# File 'lib/lotrb/list_object.rb', line 7

def pages
  @pages
end

#resultsObject (readonly)

Returns the value of attribute results.



7
8
9
# File 'lib/lotrb/list_object.rb', line 7

def results
  @results
end

#totalObject (readonly)

Returns the value of attribute total.



7
8
9
# File 'lib/lotrb/list_object.rb', line 7

def total
  @total
end