Class: TinCanApi::Verb

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Verb.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/tin_can_api/verb.rb', line 7

def initialize(options={}, &block)
  json = options.fetch(:json, nil)
  if json
    attributes = JSON.parse(json)
    self.id = attributes['id'] if attributes['id']
    self.display = attributes['display'] if attributes['display']
  else
    self.id = options.fetch(:id, nil)
    self.display = options.fetch(:display, nil)

    if block_given?
      block[self]
    end
  end
end

Instance Attribute Details

#displayObject

Returns the value of attribute display.



5
6
7
# File 'lib/tin_can_api/verb.rb', line 5

def display
  @display
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/tin_can_api/verb.rb', line 5

def id
  @id
end

Instance Method Details

#serialize(version) ⇒ Object



27
28
29
30
31
32
# File 'lib/tin_can_api/verb.rb', line 27

def serialize(version)
  node = {}
  node['id'] = id.to_s if id
  node['display'] = display if display
  node
end