Class: Omise::List

Inherits:
OmiseObject show all
Includes:
Enumerable
Defined in:
lib/omise/list.rb

Instance Method Summary collapse

Methods inherited from OmiseObject

location, resource

Methods included from Attributes

#[], #as_json, #assign_attributes, #attributes, #destroyed?, #key?, #location, #method_missing, #predicate?, #respond_to_missing?

Constructor Details

#initialize(attributes = {}, options = {}) ⇒ List

Returns a new instance of List.



8
9
10
11
# File 'lib/omise/list.rb', line 8

def initialize(attributes = {}, options = {})
  super(attributes, options)
  setup_data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Omise::Attributes

Instance Method Details

#each(*args, &block) ⇒ Object



51
52
53
# File 'lib/omise/list.rb', line 51

def each(*args, &block)
  to_a.each(*args, &block)
end

#first_page?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/omise/list.rb', line 23

def first_page?
  offset == 0
end

#jump_to_page(page) ⇒ Object



47
48
49
# File 'lib/omise/list.rb', line 47

def jump_to_page(page)
  self.class.new(@attributes, @options).send(:jump_to_page!, page)
end

#lastObject



59
60
61
# File 'lib/omise/list.rb', line 59

def last
  to_a.last
end

#last_page?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/omise/list.rb', line 27

def last_page?
  offset + limit >= total
end

#next_pageObject



39
40
41
# File 'lib/omise/list.rb', line 39

def next_page
  self.class.new(@attributes, @options).send(:next_page!)
end

#pageObject



31
32
33
# File 'lib/omise/list.rb', line 31

def page
  1 + (offset / limit)
end

#parentObject



19
20
21
# File 'lib/omise/list.rb', line 19

def parent
  @options[:parent]
end

#previous_pageObject



43
44
45
# File 'lib/omise/list.rb', line 43

def previous_page
  self.class.new(@attributes, @options).send(:previous_page!)
end

#reload(attributes = {}) ⇒ Object



13
14
15
16
17
# File 'lib/omise/list.rb', line 13

def reload(attributes = {})
  assign_attributes resource(attributes).get(attributes) do
    setup_data
  end
end

#to_aObject



55
56
57
# File 'lib/omise/list.rb', line 55

def to_a
  @data
end

#total_pagesObject



35
36
37
# File 'lib/omise/list.rb', line 35

def total_pages
  (total.to_f / limit).ceil
end