Class: ApiBee::Node::List

Inherits:
ApiBee::Node show all
Defined in:
lib/api_bee/node.rb

Constant Summary collapse

DEFAULT_PER_PAGE =
100

Instance Attribute Summary

Attributes inherited from ApiBee::Node

#adapter

Instance Method Summary collapse

Methods inherited from ApiBee::Node

#[], #initialize, resolve, simbolized, #to_data

Constructor Details

This class inherits a constructor from ApiBee::Node

Instance Method Details

#current_pageObject



97
98
99
# File 'lib/api_bee/node.rb', line 97

def current_page
  (@attributes[:page] || 1).to_i
end

#each(&block) ⇒ Object



138
139
140
# File 'lib/api_bee/node.rb', line 138

def each(&block)
  __entries.each(&block)
end

#each_with_index(&block) ⇒ Object



142
143
144
# File 'lib/api_bee/node.rb', line 142

def each_with_index(&block)
  __entries.each_with_index(&block)
end

#firstObject



130
131
132
# File 'lib/api_bee/node.rb', line 130

def first
  __entries.first
end

#get_one(id) ⇒ Object



84
85
86
87
# File 'lib/api_bee/node.rb', line 84

def get_one(id)
  data = @adapter.get_one(@href, id)
  data.nil? ? nil : Node.resolve(@adapter, @config, data, @href)
end

#has_next_page?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/api_bee/node.rb', line 122

def has_next_page?
  next_page <= total_pages
end

#has_prev_page?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/api_bee/node.rb', line 126

def has_prev_page?
  current_page > 1
end

#lastObject



134
135
136
# File 'lib/api_bee/node.rb', line 134

def last
  __entries.last
end

#next_pageObject



110
111
112
# File 'lib/api_bee/node.rb', line 110

def next_page
  current_page + 1
end

#pagesObject



118
119
120
# File 'lib/api_bee/node.rb', line 118

def pages
  (1..total_pages).to_a
end

#paginate(options = {}) ⇒ Object



146
147
148
149
# File 'lib/api_bee/node.rb', line 146

def paginate(options = {})
  data = @adapter.get(@attributes[@config.uri_property_name], options)
  Node.resolve @adapter, @config, data, @href
end

#per_pageObject



101
102
103
# File 'lib/api_bee/node.rb', line 101

def per_page
  (@attributes[:per_page] || DEFAULT_PER_PAGE).to_i
end

#prev_pageObject



114
115
116
# File 'lib/api_bee/node.rb', line 114

def prev_page
  current_page - 1
end

#sizeObject



93
94
95
# File 'lib/api_bee/node.rb', line 93

def size
  __entries.size
end

#total_entriesObject



89
90
91
# File 'lib/api_bee/node.rb', line 89

def total_entries
  @attributes[:total_entries].to_i
end

#total_pagesObject



105
106
107
108
# File 'lib/api_bee/node.rb', line 105

def total_pages
  div = (total_entries.to_f / per_page.to_f).ceil
  div < 1 ? 1 : div
end