Class: HG::Finance::Currency

Inherits:
Object
  • Object
show all
Defined in:
lib/hg/finance/currency.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  if options.count != 0
    @name      = options[:name] if options[:name]
    @iso_code  = options[:iso_code] if options[:iso_code]
    @source    = options[:source] if options[:source]
    @buy       = options[:buy].to_f if options[:buy]
    @sell      = options[:sell].to_f if options[:sell]
    @variation = options[:variation].to_f if options[:variation]
  end
end

Instance Attribute Details

#buyObject

Public: Price to buy



17
18
19
# File 'lib/hg/finance/currency.rb', line 17

def buy
  @buy
end

#iso_codeObject

Public: ISO code



11
12
13
# File 'lib/hg/finance/currency.rb', line 11

def iso_code
  @iso_code
end

#nameObject

Public: Name



8
9
10
# File 'lib/hg/finance/currency.rb', line 8

def name
  @name
end

#sellObject

Public: Price to seel



20
21
22
# File 'lib/hg/finance/currency.rb', line 20

def sell
  @sell
end

#sourceObject

Public: Source currency



14
15
16
# File 'lib/hg/finance/currency.rb', line 14

def source
  @source
end

#variationObject

Public: Last day variation



23
24
25
# File 'lib/hg/finance/currency.rb', line 23

def variation
  @variation
end

Instance Method Details

#inspectObject



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