Class: ActiveLrs::Xapi::Score

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

Overview

Represents an xAPI Score object, which can include normalized (scaled), raw, minimum, and maximum values.

This maps directly to the score property inside an xAPI Result object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ void

Initializes a new Score instance with optional attributes.

Parameters:

  • attributes (Hash) (defaults to: {})

    a hash of score attributes

Options Hash (attributes):

  • "scaled" (Numeric, String)

    the normalized score (0.0–1.0 range, typically)

  • "raw" (Numeric, String)

    the raw score as reported

  • "min" (Numeric, String)

    the minimum possible score

  • "max" (Numeric, String)

    the maximum possible score



35
36
37
38
39
40
# File 'lib/active_lrs/xapi/score.rb', line 35

def initialize(attributes = {})
  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"]
end

Instance Attribute Details

#maxNumeric?

Returns the maximum possible score.

Returns:

  • (Numeric, nil)

    the maximum possible score



24
25
26
# File 'lib/active_lrs/xapi/score.rb', line 24

def max
  @max
end

#minNumeric?

Returns the minimum possible score.

Returns:

  • (Numeric, nil)

    the minimum possible score



21
22
23
# File 'lib/active_lrs/xapi/score.rb', line 21

def min
  @min
end

#rawNumeric?

Returns the raw score as reported.

Returns:

  • (Numeric, nil)

    the raw score as reported



18
19
20
# File 'lib/active_lrs/xapi/score.rb', line 18

def raw
  @raw
end

#scaledNumeric?

Returns the normalized score (0.0–1.0 range, typically).

Returns:

  • (Numeric, nil)

    the normalized score (0.0–1.0 range, typically)



15
16
17
# File 'lib/active_lrs/xapi/score.rb', line 15

def scaled
  @scaled
end

Instance Method Details

#to_hHash{String => Numeric}

Converts the Score object into a hash representation suitable for serialization in an xAPI Statement.

Examples:

score = ActiveLrs::Xapi::Score.new("scaled" => 0.8, "raw" => 80, "min" => 0, "max" => 100)
score.to_h
# => { "scaled" => 0.8, "raw" => 80, "min" => 0, "max" => 100 }

Returns:

  • (Hash{String => Numeric})

    a hash including only the present score attributes



51
52
53
54
55
56
57
58
# File 'lib/active_lrs/xapi/score.rb', line 51

def to_h
  node = {}
  node["scaled"] = scaled if scaled
  node["raw"] = raw if raw
  node["min"] = min if min
  node["max"] = max if max
  node
end