Class: MagicSheet::Currency

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

Constant Summary collapse

LIST =
%w(USD EUR)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject (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