class Mollie::List
Attributes
_links[RW]
items[RW]
klass[RW]
links[RW]
Public Class Methods
new(list_attributes, klass)
click to toggle source
Calls superclass method
Mollie::Base::new
# 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.resource_name, []) else [] end super list_attributes @items = items.map do |attributes| klass.new attributes end end
Public Instance Methods
[](index)
click to toggle source
# File lib/mollie/list.rb, line 23 def [](index) @items[index] end
each(&block)
click to toggle source
# File lib/mollie/list.rb, line 31 def each(&block) @items.each(&block) end
next(options = {})
click to toggle source
# File lib/mollie/list.rb, line 35 def next(options = {}) return self.class.new({}, klass) if links['next'].nil? href = URI.parse(links['next']['href']) query = URI.decode_www_form(href.query).to_h klass.all(options.merge(query)) end
previous(options = {})
click to toggle source
# File lib/mollie/list.rb, line 44 def previous(options = {}) return self.class.new({}, klass) if links['previous'].nil? href = URI.parse(links['previous']['href']) query = URI.decode_www_form(href.query).to_h klass.all(options.merge(query)) end
size()
click to toggle source
# File lib/mollie/list.rb, line 27 def size @items.size end