Class: Rfsms::BalanceAnswer

Inherits:
Answer
  • Object
show all
Defined in:
lib/rfsms.rb

Instance Attribute Summary collapse

Attributes inherited from Answer

#descr

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ BalanceAnswer

Returns a new instance of BalanceAnswer.



128
129
130
131
132
133
# File 'lib/rfsms.rb', line 128

def initialize(body)
  super(body) do |e|
    e[:account] =~ FLOAT_REGEXP
  end
  @account = @account.to_f
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



91
92
93
# File 'lib/rfsms.rb', line 91

def 
  @account
end

Instance Method Details

#+(other) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
# File 'lib/rfsms.rb', line 105

def +(other)
  case other
  when Float
    self.to_f + other
  when Integer, BalanceAnswer
    self.to_f + other.to_f
  else
    n1, n2 = other.coerce(self)
    n1 + n2
  end
end

#coerce(other) ⇒ Object



117
118
119
120
121
122
123
124
125
126
# File 'lib/rfsms.rb', line 117

def coerce(other)
  case other
  when Float
    return other, self.to_f
  when Integer
    return other.to_f, self
  when String
    return other, self.to_s
  end
end

#to_fObject



93
94
95
# File 'lib/rfsms.rb', line 93

def to_f
  self.
end

#to_sObject



97
98
99
# File 'lib/rfsms.rb', line 97

def to_s
  self.to_f.to_s
end

#to_strObject



101
102
103
# File 'lib/rfsms.rb', line 101

def to_str
  self.to_s
end