class Xapi::Attachment

Attachment Class

Attributes

content_type[RW]
description[RW]
display[RW]
file_url[R]
length[RW]
sha2[RW]
usage_type[R]

Public Class Methods

new(options={}, &block) click to toggle source
# File lib/xapi/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

Public Instance Methods

file_url=(value) click to toggle source
# File lib/xapi/attachment.rb, line 43
def file_url=(value)
  if value.is_a?(String)
    @file_url = Addressable::URI.parse(value)
  else
    @file_url = value
  end
end
serialize(version) click to toggle source
# File lib/xapi/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
usage_type=(value) click to toggle source
# File lib/xapi/attachment.rb, line 35
def usage_type=(value)
  if value.is_a?(String)
    @usage_type = Addressable::URI.parse(value)
  else
    @usage_type = value
  end
end