Module: Kippt::Collection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Included in:
- ClipCollection, CommentCollection, ListCollection, UserCollection
- Defined in:
- lib/kippt/collection.rb
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #each(&block) ⇒ Object
- #initialize(data, client = nil) ⇒ Object
- #next_page ⇒ Object
- #next_page? ⇒ Boolean
- #objects ⇒ Object
- #previous_page ⇒ Object (also: #prev_page)
- #previous_page? ⇒ Boolean (also: #prev_page?)
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
4 5 6 |
# File 'lib/kippt/collection.rb', line 4 def limit @limit end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
4 5 6 |
# File 'lib/kippt/collection.rb', line 4 def offset @offset end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
4 5 6 |
# File 'lib/kippt/collection.rb', line 4 def total_count @total_count end |
Instance Method Details
#[](index) ⇒ Object
26 27 28 |
# File 'lib/kippt/collection.rb', line 26 def [](index) objects[index] end |
#each(&block) ⇒ Object
30 31 32 |
# File 'lib/kippt/collection.rb', line 30 def each(&block) objects.each(&block) end |
#initialize(data, client = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/kippt/collection.rb', line 6 def initialize(data, client = nil) = data.fetch("meta") { {} } @limit = .fetch("limit") { nil } @offset = .fetch("offset") { nil } @next = .fetch("next") { nil } @previous = .fetch("previous") { nil } @total_count = .fetch("total_count") { nil } @client = client @object_data = data.fetch("objects") end |
#next_page ⇒ Object
38 39 40 41 42 |
# File 'lib/kippt/collection.rb', line 38 def next_page raise Kippt::APIError.new("There is no next page") if @next.nil? || @next == "" collection_resource.collection_from_url(@next) end |
#next_page? ⇒ Boolean
34 35 36 |
# File 'lib/kippt/collection.rb', line 34 def next_page? @next end |
#objects ⇒ Object
22 23 24 |
# File 'lib/kippt/collection.rb', line 22 def objects @objects ||= @object_data.map {|data| object_class.new(data, client) } end |
#previous_page ⇒ Object Also known as: prev_page
49 50 51 52 53 |
# File 'lib/kippt/collection.rb', line 49 def previous_page raise Kippt::APIError.new("There is no previous page") if @previous.nil? || @previous == "" collection_resource.collection_from_url(@previous) end |
#previous_page? ⇒ Boolean Also known as: prev_page?
44 45 46 |
# File 'lib/kippt/collection.rb', line 44 def previous_page? @previous end |