Class: Skydrive::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/skydrive/collection.rb

Overview

An object with an array of objects of multiple types

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data) ⇒ Collection

Returns a new instance of Collection.



6
7
8
9
# File 'lib/skydrive/collection.rb', line 6

def initialize client, data
  @client = client
  @data = data
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/skydrive/collection.rb', line 5

def client
  @client
end

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/skydrive/collection.rb', line 5

def data
  @data
end

Instance Method Details

#itemsArray

Array of items in the collection

Returns:

  • (Array)


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/skydrive/collection.rb', line 19

def items
  @items = []
  @data.each do |object_data|
    if object_data["type"]
      @items << "Skydrive::#{object_data["type"].capitalize}".constantize.new(client, object_data)
    elsif object_data["id"].match /^comment\..+/
      @items << Skydrive::Comment.new(client, object_data)
    end
  end
  @items
end

#typeString

Additional type for the collection

Returns:

  • (String)


13
14
15
# File 'lib/skydrive/collection.rb', line 13

def type
  "collection"
end