Class: MagicSheet::Cost
- Inherits:
-
Object
- Object
- MagicSheet::Cost
- Defined in:
- lib/magicsheet.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(amount, currency) ⇒ Cost
constructor
A new instance of Cost.
- #to_s ⇒ Object
Constructor Details
#initialize(amount, currency) ⇒ Cost
Returns a new instance of Cost.
45 46 47 48 |
# File 'lib/magicsheet.rb', line 45 def initialize(amount,currency) @amount = amount @currency = currency end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
32 33 34 |
# File 'lib/magicsheet.rb', line 32 def amount @amount end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
32 33 34 |
# File 'lib/magicsheet.rb', line 32 def currency @currency end |
Class Method Details
.[](arg) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/magicsheet.rb', line 34 def self.[](arg) arg = arg.to_s.strip currency = Currency[arg] if currency amount = (arg[/\d+(\.\d+)?/,0] || 0).to_f return self.new(amount,currency) else return nil end end |
Instance Method Details
#to_s ⇒ Object
50 51 52 |
# File 'lib/magicsheet.rb', line 50 def to_s "#{"%.2f" % @amount} #{@currency}" end |