Class: HG::Finance::CryptoCurrency

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CryptoCurrency

Returns a new instance of CryptoCurrency.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/hg/finance/crypto_currency.rb', line 31

def initialize(options = {})
  if options.count != 0
    @exchange    = options[:exchange] if options[:exchange]
    @name        = options[:name] if options[:name]
    @iso_code    = options[:iso_code] if options[:iso_code]
    @to_currency = options[:to_currency] if options[:to_currency]
    @buy         = options[:buy].to_f if options[:buy]
    @sell        = options[:sell].to_f if options[:sell]
    @last        = options[:last].to_f if options[:last]
    @variation   = options[:variation].to_f if options[:variation]
  end
end

Instance Attribute Details

#buyObject

Public: Price to buy



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

def buy
  @buy
end

#exchangeObject

Public: Exchange



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

def exchange
  @exchange
end

#iso_codeObject

Public: ISO code



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

def iso_code
  @iso_code
end

#lastObject

Public: Last ticker



26
27
28
# File 'lib/hg/finance/crypto_currency.rb', line 26

def last
  @last
end

#nameObject

Public: Name



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

def name
  @name
end

#sellObject

Public: Price to seel



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

def sell
  @sell
end

#to_currencyObject

Public: To currency



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

def to_currency
  @to_currency
end

#variationObject

Public: Last day variation



29
30
31
# File 'lib/hg/finance/crypto_currency.rb', line 29

def variation
  @variation
end

Instance Method Details

#inspectObject



57
58
59
# File 'lib/hg/finance/crypto_currency.rb', line 57

def inspect
  self.to_s
end

#to_s(separator = ' - ') ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/hg/finance/crypto_currency.rb', line 44

def to_s separator = ' - '
  to_return = []

  to_return << self.exchange.to_s + ' (' + self.iso_code.to_s + ' to ' + self.to_currency + ')'

  to_return << "#{Locale.get_format(:last).to_s.capitalize}: " + "#{self.to_currency} #{self.last}" if self.last
  to_return << "#{Locale.get_format(:buy).to_s.capitalize}: " + "#{self.to_currency} #{self.buy}" if self.buy
  to_return << "#{Locale.get_format(:sell).to_s.capitalize}: " + "#{self.to_currency} #{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