Class: Mollie::List
- Includes:
- Enumerable
- Defined in:
- lib/mollie/list.rb
Instance Attribute Summary collapse
-
#_links ⇒ Object
(also: #links)
Returns the value of attribute _links.
-
#items ⇒ Object
Returns the value of attribute items.
-
#klass ⇒ Object
Returns the value of attribute klass.
Attributes inherited from Base
Instance Method Summary collapse
- #[](index) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(list_attributes, klass) ⇒ List
constructor
A new instance of List.
- #next(options = {}) ⇒ Object
- #previous(options = {}) ⇒ Object
- #size ⇒ Object
Methods inherited from Base
all, #assign_attributes, cancel, create, #delete, delete, get, id_param, parent_id, request, resource_name, update, #update
Constructor Details
#initialize(list_attributes, klass) ⇒ List
Returns a new instance of List.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mollie/list.rb', line 8 def initialize(list_attributes, klass) @klass = klass list_attributes['items'] ||= if list_attributes['_embedded'] list_attributes['_embedded'].fetch(klass., []) else [] end super list_attributes @items = items.map do |attributes| klass.new attributes end end |
Instance Attribute Details
#_links ⇒ Object Also known as: links
Returns the value of attribute _links.
5 6 7 |
# File 'lib/mollie/list.rb', line 5 def _links @_links end |
#items ⇒ Object
Returns the value of attribute items.
5 6 7 |
# File 'lib/mollie/list.rb', line 5 def items @items end |
#klass ⇒ Object
Returns the value of attribute klass.
5 6 7 |
# File 'lib/mollie/list.rb', line 5 def klass @klass end |
Instance Method Details
#[](index) ⇒ Object
23 24 25 |
# File 'lib/mollie/list.rb', line 23 def [](index) @items[index] end |
#each(&block) ⇒ Object
31 32 33 |
# File 'lib/mollie/list.rb', line 31 def each(&block) @items.each(&block) end |
#next(options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/mollie/list.rb', line 35 def next( = {}) return self.class.new({}, klass) if links['next'].nil? href = URI.parse(links['next']['href']) query = URI.decode_www_form(href.query).to_h response = Mollie::Client.instance.perform_http_call('GET', links['next']['href'], nil, {}, .merge(query)) self.class.new(response, klass) end |
#previous(options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/mollie/list.rb', line 45 def previous( = {}) return self.class.new({}, klass) if links['previous'].nil? href = URI.parse(links['previous']['href']) query = URI.decode_www_form(href.query).to_h response = Mollie::Client.instance.perform_http_call('GET', links['previous']['href'], nil, {}, .merge(query)) self.class.new(response, klass) end |
#size ⇒ Object
27 28 29 |
# File 'lib/mollie/list.rb', line 27 def size @items.size end |