Class: C::Rates
- Inherits:
-
Object
- Object
- C::Rates
- Defined in:
- lib/crates.rb
Instance Attribute Summary collapse
-
#coins ⇒ Object
Returns the value of attribute coins.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#prices ⇒ Object
readonly
Returns the value of attribute prices.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #get(currency = nil, opts = {}) ⇒ Object
-
#initialize(currency = :eur, opts = {}) ⇒ Rates
constructor
A new instance of Rates.
- #price(coin) ⇒ Object
- #print? ⇒ Boolean
- #save? ⇒ Boolean
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
#coins ⇒ Object
Returns the value of attribute coins.
18 19 20 |
# File 'lib/crates.rb', line 18 def coins @coins end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
17 18 19 |
# File 'lib/crates.rb', line 17 def count @count end |
#currency ⇒ Object
Returns the value of attribute currency.
18 19 20 |
# File 'lib/crates.rb', line 18 def currency @currency end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
17 18 19 |
# File 'lib/crates.rb', line 17 def data @data end |
#prices ⇒ Object (readonly)
Returns the value of attribute prices.
17 18 19 |
# File 'lib/crates.rb', line 17 def prices @prices end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
17 18 19 |
# File 'lib/crates.rb', line 17 def response @response end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
17 18 19 |
# File 'lib/crates.rb', line 17 def table @table end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
17 18 19 |
# File 'lib/crates.rb', line 17 def url @url end |
Class Method Details
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
50 51 52 |
# File 'lib/crates.rb', line 50 def print? @print == true end |
#save? ⇒ Boolean
46 47 48 |
# File 'lib/crates.rb', line 46 def save? @save == true end |