Class: Nanook::Util
- Inherits:
-
Object
- Object
- Nanook::Util
- Defined in:
- lib/nanook/util.rb
Overview
Set of class utility methods.
Constant Summary
- STEP =
Constant used to convert back and forth between raw and NANO.
BigDecimal.new("10")**BigDecimal.new("30")
Class Method Summary collapse
-
.coerce_empty_string_to_type(response, type) ⇒ Object
Converts an empty String value into an empty version of another type.
-
.NANO_to_raw(nano) ⇒ Integer
Converts an amount of NANO to an amount of raw.
-
.raw_to_NANO(raw) ⇒ Float|Integer
Converts an amount of raw to an amount of NANO.
Class Method Details
.coerce_empty_string_to_type(response, type) ⇒ Object
Converts an empty String value into an empty version of another type.
The RPC often returns an empty String (""
) as a
value, when a nil
, or empty Array ([]
), or empty
Hash ({}
) would be better. If the response might be
35 36 37 38 39 40 41 |
# File 'lib/nanook/util.rb', line 35 def self.coerce_empty_string_to_type(response, type) if response == "" || response.nil? return type.new end response end |
.NANO_to_raw(nano) ⇒ Integer
Converts an amount of NANO to an amount of raw.
15 16 17 |
# File 'lib/nanook/util.rb', line 15 def self.NANO_to_raw(nano) (BigDecimal.new(nano.to_s) * STEP).to_i end |
.raw_to_NANO(raw) ⇒ Float|Integer
Converts an amount of raw to an amount of NANO.
23 24 25 |
# File 'lib/nanook/util.rb', line 23 def self.raw_to_NANO(raw) (raw.to_f / STEP).to_f end |