Class: TinCanApi::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/tin_can_api/attachment.rb

Overview

Attachment Class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Attachment

Returns a new instance of Attachment.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tin_can_api/attachment.rb', line 9

def initialize(options={}, &block)
  json = options.fetch(:json, nil)
  if json
    attributes = JSON.parse(json)
    self.usage_type = attributes['usageType'] if attributes['usageType']
    self.display = attributes['display'] if attributes['display']
    self.description = attributes['description'] if attributes['description']
    self.content_type = attributes['contentType'] if attributes['contentType']
    self.length = attributes['length'] if attributes['length']
    self.sha2 = attributes['sha2'] if attributes['sha2']
    self.file_url = attributes['fileUrl'] if attributes['fileUrl']
  else
    self.usage_type = options.fetch(:usage_type, nil)
    self.display = options.fetch(:display, nil)
    self.description = options.fetch(:description, nil)
    self.content_type = options.fetch(:content_type, nil)
    self.length = options.fetch(:length, nil)
    self.sha2 = options.fetch(:sha2, nil)
    self.file_url = options.fetch(:file_url, nil)

    if block_given?
      block[self]
    end
  end
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



6
7
8
# File 'lib/tin_can_api/attachment.rb', line 6

def content_type
  @content_type
end

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/tin_can_api/attachment.rb', line 6

def description
  @description
end

#displayObject

Returns the value of attribute display.



6
7
8
# File 'lib/tin_can_api/attachment.rb', line 6

def display
  @display
end

#file_urlObject

Returns the value of attribute file_url.



7
8
9
# File 'lib/tin_can_api/attachment.rb', line 7

def file_url
  @file_url
end

#lengthObject

Returns the value of attribute length.



6
7
8
# File 'lib/tin_can_api/attachment.rb', line 6

def length
  @length
end

#sha2Object

Returns the value of attribute sha2.



6
7
8
# File 'lib/tin_can_api/attachment.rb', line 6

def sha2
  @sha2
end

#usage_typeObject

Returns the value of attribute usage_type.



7
8
9
# File 'lib/tin_can_api/attachment.rb', line 7

def usage_type
  @usage_type
end

Instance Method Details

#serialize(version) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tin_can_api/attachment.rb', line 51

def serialize(version)
  node = {}
  node['usageType'] = usage_type.to_s if usage_type
  node['display'] = display if display
  node['description'] = description if description
  node['contentType'] = content_type if content_type
  node['length'] = length if length
  node['sha2'] = sha2 if sha2
  node['fileUrl'] = file_url.to_s if file_url
  node
end