Module: Kippt::Collection

Extended by:
Forwardable
Includes:
Enumerable
Included in:
ClipCollection, CommentCollection, ListCollection, UserCollection
Defined in:
lib/kippt/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



4
5
6
# File 'lib/kippt/collection.rb', line 4

def limit
  @limit
end

#offsetObject (readonly)

Returns the value of attribute offset.



4
5
6
# File 'lib/kippt/collection.rb', line 4

def offset
  @offset
end

#total_countObject (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)
  meta         = data.fetch("meta") { {} }
  @limit       = meta.fetch("limit") { nil }
  @offset      = meta.fetch("offset") { nil }
  @next        = meta.fetch("next") { nil }
  @previous    = meta.fetch("previous") { nil }
  @total_count = meta.fetch("total_count") { nil }

  @client  = client

  @object_data = data.fetch("objects")
end

#next_pageObject

Raises:



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

Returns:

  • (Boolean)


34
35
36
# File 'lib/kippt/collection.rb', line 34

def next_page?
  @next
end

#objectsObject



22
23
24
# File 'lib/kippt/collection.rb', line 22

def objects
  @objects ||= @object_data.map {|data| object_class.new(data, client) }
end

#previous_pageObject Also known as: prev_page

Raises:



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?

Returns:

  • (Boolean)


44
45
46
# File 'lib/kippt/collection.rb', line 44

def previous_page?
  @previous
end