Class: XlsFunction::Converters::NumberConverter
- Inherits:
-
Object
- Object
- XlsFunction::Converters::NumberConverter
- Defined in:
- lib/xls_function/converters/number_converter.rb
Class Method Summary collapse
- .decimal_to_date(decimal) ⇒ Object
- .decimal_to_time(decimal, now: ::XlsFunction::Converters::DateSerialConverter::ORIGIN) ⇒ Object
- .numberable_string?(input) ⇒ Boolean
- .try_convert(input) ⇒ Object
Class Method Details
.decimal_to_date(decimal) ⇒ Object
16 17 18 |
# File 'lib/xls_function/converters/number_converter.rb', line 16 def decimal_to_date(decimal) ::XlsFunction::Converters::DateSerialConverter.serial_to_date(decimal.fix) end |
.decimal_to_time(decimal, now: ::XlsFunction::Converters::DateSerialConverter::ORIGIN) ⇒ Object
20 21 22 23 24 |
# File 'lib/xls_function/converters/number_converter.rb', line 20 def decimal_to_time(decimal, now: ::XlsFunction::Converters::DateSerialConverter::ORIGIN) days = decimal.fix.to_i date = now.to_date + days ::XlsFunction::Converters::TimeSerialConverter.serial_to_time(decimal, date) end |
.numberable_string?(input) ⇒ Boolean
12 13 14 |
# File 'lib/xls_function/converters/number_converter.rb', line 12 def numberable_string?(input) input.to_s =~ /\A-?[0-9.]+\z/ end |
.try_convert(input) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/xls_function/converters/number_converter.rb', line 5 def try_convert(input) [false, nil] unless input.respond_to?(:to_d) [false, nil] if input.is_a?(String) && !numberable_string?(input) [true, input.to_d] end |