Module: MtGox::Value
Constant Summary collapse
- INT_MULTIPLIERS =
We assume here that any other currency than :jpy uses :usd
{btc: 100000000, usd: 100000, jpy: 1000}
Instance Method Summary collapse
-
#floatify(int, currency) ⇒ Object
Convert an int value to a float using the MtGox conversion rules.
-
#intify(float, currency) ⇒ Object
Convert a float value to an int using the MtGox conversion rules.
-
#value_bitcoin(value, key = 'value_int') ⇒ Float
Takes a hash return by the API and convert some value_int to [Float] BitCoin value .
-
#value_currency(value, key = 'value_int') ⇒ Float
Takes a hash return by the API and convert some value_int to a currency value using USD conversion rule.
Instance Method Details
#floatify(int, currency) ⇒ Object
Convert an int value to a float using the MtGox conversion rules.
param int [Fixnum] to convert param currency [Symbol] currency conversion rule to use amongst [:btc, :usd, :jpy] return a [Float]
49 50 51 |
# File 'lib/mtgox/value.rb', line 49 def floatify(int, currency) (int.to_f / INT_MULTIPLIERS[currency]) end |
#intify(float, currency) ⇒ Object
Convert a float value to an int using the MtGox conversion rules.
param float [Float] to convert param currency [Symbol] currency conversion rule to use amongst [:btc, :usd, :jpy] return an int
40 41 42 |
# File 'lib/mtgox/value.rb', line 40 def intify(float, currency) (float * INT_MULTIPLIERS[currency]).to_i end |
#value_bitcoin(value, key = 'value_int') ⇒ Float
Takes a hash return by the API and convert some value_int to [Float] BitCoin value . You can specify which key to convert
params key [String] the key from the previous hash to convert, default to 'value_int'
31 32 33 |
# File 'lib/mtgox/value.rb', line 31 def value_bitcoin(value, key = 'value_int') floatify(value[key], :btc) end |
#value_currency(value, key = 'value_int') ⇒ Float
Takes a hash return by the API and convert some value_int to a currency value using USD conversion rule. You can specify which key to convert
params key [String] the key from the previous hash to convert, default to 'value_int'
20 21 22 |
# File 'lib/mtgox/value.rb', line 20 def value_currency(value, key = 'value_int') floatify(value[key].to_i, :usd) end |