Class: TinCanApi::Score

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

Overview

Score model class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Score.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tin_can_api/score.rb', line 8

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

    if block_given?
      block[self]
    end
  end

end

Instance Attribute Details

#maxObject

Returns the value of attribute max.



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

def max
  @max
end

#minObject

Returns the value of attribute min.



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

def min
  @min
end

#rawObject

Returns the value of attribute raw.



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

def raw
  @raw
end

#scaledObject

Returns the value of attribute scaled.



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

def scaled
  @scaled
end

Instance Method Details

#serialize(version) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/tin_can_api/score.rb', line 29

def serialize(version)
  node = {}
  node['scaled'] = scaled if scaled
  node['raw'] = raw if raw
  node['min'] = min if min
  node['max'] = max if max
  node
end