Class: C::Rates

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(currency = :eur, opts = {}) ⇒ Rates

Returns a new instance of Rates.



25
26
27
28
29
30
# File 'lib/crates.rb', line 25

def initialize( currency = :eur, opts = {} )
  @save  = opts[:save ].nil? ? true : opts[:save]
  @print = opts[:print].nil? ? true : opts[:print]
  @coins = opts[:coins].nil? ? COINS : Array(opts[:coins])
  @currency = currency.to_s.upcase
end

Instance Attribute Details

#coinsObject

Returns the value of attribute coins.



18
19
20
# File 'lib/crates.rb', line 18

def coins
  @coins
end

#countObject (readonly)

Returns the value of attribute count.



17
18
19
# File 'lib/crates.rb', line 17

def count
  @count
end

#currencyObject

Returns the value of attribute currency.



18
19
20
# File 'lib/crates.rb', line 18

def currency
  @currency
end

#dataObject (readonly)

Returns the value of attribute data.



17
18
19
# File 'lib/crates.rb', line 17

def data
  @data
end

#pricesObject (readonly)

Returns the value of attribute prices.



17
18
19
# File 'lib/crates.rb', line 17

def prices
  @prices
end

#responseObject (readonly)

Returns the value of attribute response.



17
18
19
# File 'lib/crates.rb', line 17

def response
  @response
end

#tableObject (readonly)

Returns the value of attribute table.



17
18
19
# File 'lib/crates.rb', line 17

def table
  @table
end

#urlObject (readonly)

Returns the value of attribute url.



17
18
19
# File 'lib/crates.rb', line 17

def url
  @url
end

Class Method Details

.get!(currency = :eur, opts = {}) ⇒ Object



20
21
22
23
# File 'lib/crates.rb', line 20

def self.get!( currency = :eur, opts = {} )
  @rates = Rates.new currency, opts
  @rates.get
end

Instance Method Details

#get(currency = nil, opts = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/crates.rb', line 32

def get( currency = nil, opts = {} )
  @save  = opts[:save]  unless opts[:save].nil?
  @print = opts[:print] unless opts[:print].nil?
  opts[:coins] ||= @coins
  currency     ||= @currency
  @table = currency.to_s.downcase  + '_rates.csv'
  @count = 0
  execute_request(opts[:coins], currency)
end

#price(coin) ⇒ Object



42
43
44
# File 'lib/crates.rb', line 42

def price( coin )
  @prices[coin.to_s.upcase]
end

#print?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/crates.rb', line 50

def print?
  @print == true
end

#save?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/crates.rb', line 46

def save?
  @save == true
end