Class: Rfsms::BalanceAnswer
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
Attributes inherited from Answer
Instance Method Summary collapse
- #+(other) ⇒ Object
- #coerce(other) ⇒ Object
-
#initialize(body) ⇒ BalanceAnswer
constructor
A new instance of BalanceAnswer.
- #to_f ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
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
#account ⇒ Object (readonly)
Returns the value of attribute account.
91 92 93 |
# File 'lib/rfsms.rb', line 91 def account @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_f ⇒ Object
93 94 95 |
# File 'lib/rfsms.rb', line 93 def to_f self.account end |
#to_s ⇒ Object
97 98 99 |
# File 'lib/rfsms.rb', line 97 def to_s self.to_f.to_s end |
#to_str ⇒ Object
101 102 103 |
# File 'lib/rfsms.rb', line 101 def to_str self.to_s end |