Class: JsonApiClient::ResultSet
- Inherits:
-
Array
- Object
- Array
- JsonApiClient::ResultSet
- Defined in:
- lib/json_api_client/result_set.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
Returns the value of attribute current_page.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#total_entries ⇒ Object
Returns the value of attribute total_entries.
-
#total_pages ⇒ Object
Returns the value of attribute total_pages.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#current_page ⇒ Object
Returns the value of attribute current_page.
4 5 6 |
# File 'lib/json_api_client/result_set.rb', line 4 def current_page @current_page end |
#errors ⇒ Object
Returns the value of attribute errors.
4 5 6 |
# File 'lib/json_api_client/result_set.rb', line 4 def errors @errors end |
#offset ⇒ Object
Returns the value of attribute offset.
4 5 6 |
# File 'lib/json_api_client/result_set.rb', line 4 def offset @offset end |
#per_page ⇒ Object
Returns the value of attribute per_page.
4 5 6 |
# File 'lib/json_api_client/result_set.rb', line 4 def per_page @per_page end |
#total_entries ⇒ Object
Returns the value of attribute total_entries.
4 5 6 |
# File 'lib/json_api_client/result_set.rb', line 4 def total_entries @total_entries end |
#total_pages ⇒ Object
Returns the value of attribute total_pages.
4 5 6 |
# File 'lib/json_api_client/result_set.rb', line 4 def total_pages @total_pages end |
Class Method Details
.build(klass, data) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/json_api_client/result_set.rb', line 7 def self.build(klass, data) result_data = data.fetch(klass.table_name, []) new(result_data.map {|attributes| klass.new(attributes) }).tap do |result_set| yield(result_set) if block_given? end end |
Instance Method Details
#has_errors? ⇒ Boolean
14 15 16 |
# File 'lib/json_api_client/result_set.rb', line 14 def has_errors? errors && errors.length > 0 end |
#next_page ⇒ Object
26 27 28 |
# File 'lib/json_api_client/result_set.rb', line 26 def next_page current_page < total_pages ? (current_page + 1) : nil end |
#out_of_bounds? ⇒ Boolean
18 19 20 |
# File 'lib/json_api_client/result_set.rb', line 18 def out_of_bounds? current_page > total_pages end |
#previous_page ⇒ Object
22 23 24 |
# File 'lib/json_api_client/result_set.rb', line 22 def previous_page current_page > 1 ? (current_page - 1) : nil end |