Class: Reporter::Record::Response::Numeric

Inherits:
Base
  • Object
show all
Defined in:
lib/reporter/record/response/numeric.rb

Overview

Public: Represents a response to a question with a numeric

answer.

Call #value to get a Float representing the value.

Instance Method Summary collapse

Methods included from BaseModule

#question_prompt

Methods inherited from Base

#==, #hash, #initialize

Constructor Details

This class inherits a constructor from Reporter::Record::Base

Instance Method Details

#to_fObject

Public: Returns the value of this Response as a Float.

Returns a Float representing the value of this Response.


29
30
31
# File 'lib/reporter/record/response/numeric.rb', line 29

def to_f
  @to_f ||= @data["numericResponse"].to_f
end

#to_iObject

Public: Returns the value of this Response as an Integer.

Returns an Integer representing the value of this Response.


36
37
38
# File 'lib/reporter/record/response/numeric.rb', line 36

def to_i
  to_f.to_i
end

#to_sObject

Public: Returns the string representation of this Response.

Returns a String representing the value of this Response.


43
44
45
# File 'lib/reporter/record/response/numeric.rb', line 43

def to_s
  value.to_s
end

#valueObject

Public: Returns the value of this Response.

If the value is a whole number, then an Integer is returned. Otherwise, a Float is returned.

Returns a Numeric representing the value of this Response.


17
18
19
20
21
22
23
24
# File 'lib/reporter/record/response/numeric.rb', line 17

def value
  @value ||= begin
    case to_f % 1
    when 0 then to_i
    else to_f
    end
  end
end