Class: MagicSheet::Currency
- Inherits:
-
Object
- Object
- MagicSheet::Currency
- Defined in:
- lib/magicsheet.rb
Constant Summary collapse
- LIST =
%w(USD EUR)
Instance Attribute Summary collapse
-
#name ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #conversion_rate_to(other) ⇒ Object
-
#initialize(name) ⇒ Currency
constructor
A new instance of Currency.
Constructor Details
#initialize(name) ⇒ Currency
Returns a new instance of Currency.
17 18 19 |
# File 'lib/magicsheet.rb', line 17 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute name.
5 6 7 |
# File 'lib/magicsheet.rb', line 5 def name @name end |
Class Method Details
.[](str) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/magicsheet.rb', line 10 def self.[](str) name = LIST.find do |name| str.upcase.strip.end_with?(name) end return name ? self.new(name) : nil end |
Instance Method Details
#==(other) ⇒ Object
21 22 23 |
# File 'lib/magicsheet.rb', line 21 def ==(other) self.name == other.name end |
#conversion_rate_to(other) ⇒ Object
25 26 27 28 |
# File 'lib/magicsheet.rb', line 25 def conversion_rate_to(other) symbol = "#{self.name}#{other.name}=X".upcase YahooFinance.quotes(symbol).first.last_trade_price.to_f end |