Module: VoltRb::Utils
- Defined in:
- lib/voltrb/utils.rb
Overview
Set of utility functions.
Class Method Summary collapse
-
.dec_from_str(str) ⇒ Object
Converts a string to a Big Decimal.
-
.ruby_from_volt(val, type) ⇒ Object
Converts a val of type into its Ruby equivalent.
-
.time_from_milli_epoch(num) ⇒ Object
Converts an integer (millisecond value since epoch) to a Time object.
Class Method Details
.dec_from_str(str) ⇒ Object
Converts a string to a Big Decimal.
7 8 9 |
# File 'lib/voltrb/utils.rb', line 7 def dec_from_str(str) BigDecimal.new(str) end |
.ruby_from_volt(val, type) ⇒ Object
Converts a val of type into its Ruby equivalent.
17 18 19 20 21 22 23 24 25 |
# File 'lib/voltrb/utils.rb', line 17 def ruby_from_volt(val, type) return nil if val.nil? case type when Types::DECIMAL then dec_from_str(val) when Types::TIMESTAMP then time_from_milli_epoch(val) else val end end |
.time_from_milli_epoch(num) ⇒ Object
Converts an integer (millisecond value since epoch) to a Time object.
12 13 14 |
# File 'lib/voltrb/utils.rb', line 12 def time_from_milli_epoch(num) Time.at(num/1000) end |