Class: HG::Finance::Currency
- Inherits:
-
Object
- Object
- HG::Finance::Currency
- Defined in:
- lib/hg/finance/currency.rb
Instance Attribute Summary collapse
-
#buy ⇒ Object
Public: Price to buy.
-
#iso_code ⇒ Object
Public: ISO code.
-
#name ⇒ Object
Public: Name.
-
#sell ⇒ Object
Public: Price to seel.
-
#source ⇒ Object
Public: Source currency.
-
#variation ⇒ Object
Public: Last day variation.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Currency
constructor
A new instance of Currency.
- #inspect ⇒ Object
- #to_s(separator = ' - ') ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Currency
Returns a new instance of Currency.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/hg/finance/currency.rb', line 25 def initialize( = {}) if .count != 0 @name = [:name] if [:name] @iso_code = [:iso_code] if [:iso_code] @source = [:source] if [:source] @buy = [:buy].to_f if [:buy] @sell = [:sell].to_f if [:sell] @variation = [:variation].to_f if [:variation] end end |
Instance Attribute Details
#buy ⇒ Object
Public: Price to buy
17 18 19 |
# File 'lib/hg/finance/currency.rb', line 17 def buy @buy end |
#iso_code ⇒ Object
Public: ISO code
11 12 13 |
# File 'lib/hg/finance/currency.rb', line 11 def iso_code @iso_code end |
#name ⇒ Object
Public: Name
8 9 10 |
# File 'lib/hg/finance/currency.rb', line 8 def name @name end |
#sell ⇒ Object
Public: Price to seel
20 21 22 |
# File 'lib/hg/finance/currency.rb', line 20 def sell @sell end |
#source ⇒ Object
Public: Source currency
14 15 16 |
# File 'lib/hg/finance/currency.rb', line 14 def source @source end |
#variation ⇒ Object
Public: Last day variation
23 24 25 |
# File 'lib/hg/finance/currency.rb', line 23 def variation @variation end |
Instance Method Details
#inspect ⇒ Object
48 49 50 |
# File 'lib/hg/finance/currency.rb', line 48 def inspect self.to_s end |
#to_s(separator = ' - ') ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hg/finance/currency.rb', line 36 def to_s separator = ' - ' to_return = [] to_return << self.name.to_s + ' (' + self.iso_code.to_s + ')' to_return << "#{Locale.get_format(:buy).to_s.capitalize}: " + "#{self.source} #{self.buy}" if self.buy to_return << "#{Locale.get_format(:sell).to_s.capitalize}: " + "#{self.source} #{self.sell}" if self.sell to_return << "#{Locale.get_format(:variation).to_s.capitalize}: " + self.variation.to_s if self.variation return to_return.join(separator) end |