Class: Contentstack::EntryCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/contentstack/entry_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, content_type_uid = nil) ⇒ EntryCollection

Returns a new instance of EntryCollection.



7
8
9
10
11
12
13
# File 'lib/contentstack/entry_collection.rb', line 7

def initialize(json, content_type_uid=nil)
  @count        = json["count"] if json["count"]
  @entries      = json["entries"].collect{|entry| Entry.new(entry, content_type_uid) }
  @schema       = json["schema"].symbolize_keys if json["schema"]
  @content_type = json["content_type"].symbolize_keys if json["content_type"]
  self
end

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type.



5
6
7
# File 'lib/contentstack/entry_collection.rb', line 5

def content_type
  @content_type
end

#countObject (readonly)

Returns the value of attribute count.



5
6
7
# File 'lib/contentstack/entry_collection.rb', line 5

def count
  @count
end

#entriesObject (readonly)

Returns the value of attribute entries.



5
6
7
# File 'lib/contentstack/entry_collection.rb', line 5

def entries
  @entries
end

#schemaObject (readonly)

Returns the value of attribute schema.



5
6
7
# File 'lib/contentstack/entry_collection.rb', line 5

def schema
  @schema
end

Instance Method Details

#collect(&block) ⇒ Object



23
24
25
# File 'lib/contentstack/entry_collection.rb', line 23

def collect &block
  self.each(&block)
end

#each(&block) ⇒ Object



15
16
17
# File 'lib/contentstack/entry_collection.rb', line 15

def each &block
  @entries.map{|e| block.call(e)}
end

#firstObject



31
32
33
# File 'lib/contentstack/entry_collection.rb', line 31

def first
  @entries.first
end

#get(index) ⇒ Object



39
40
41
# File 'lib/contentstack/entry_collection.rb', line 39

def get(index)
  @entries[index]
end

#lastObject



35
36
37
# File 'lib/contentstack/entry_collection.rb', line 35

def last
  @entries.last
end

#lengthObject



27
28
29
# File 'lib/contentstack/entry_collection.rb', line 27

def length
  @entries.length
end

#map(&block) ⇒ Object



19
20
21
# File 'lib/contentstack/entry_collection.rb', line 19

def map &block
  self.each(&block)
end