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.



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

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.



7
8
9
# File 'lib/contentstack/entry_collection.rb', line 7

def content_type
  @content_type
end

#countObject (readonly)

Returns the value of attribute count.



7
8
9
# File 'lib/contentstack/entry_collection.rb', line 7

def count
  @count
end

#entriesObject (readonly)

Returns the value of attribute entries.



7
8
9
# File 'lib/contentstack/entry_collection.rb', line 7

def entries
  @entries
end

#schemaObject (readonly)

Returns the value of attribute schema.



7
8
9
# File 'lib/contentstack/entry_collection.rb', line 7

def schema
  @schema
end

Instance Method Details

#collect(&block) ⇒ Object



25
26
27
# File 'lib/contentstack/entry_collection.rb', line 25

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

#each(&block) ⇒ Object



17
18
19
# File 'lib/contentstack/entry_collection.rb', line 17

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

#firstObject



33
34
35
# File 'lib/contentstack/entry_collection.rb', line 33

def first
  @entries.first
end

#get(index) ⇒ Object



41
42
43
# File 'lib/contentstack/entry_collection.rb', line 41

def get(index)
  @entries[index]
end

#lastObject



37
38
39
# File 'lib/contentstack/entry_collection.rb', line 37

def last
  @entries.last
end

#lengthObject



29
30
31
# File 'lib/contentstack/entry_collection.rb', line 29

def length
  @entries.length
end

#map(&block) ⇒ Object



21
22
23
# File 'lib/contentstack/entry_collection.rb', line 21

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