Module: RDO::Util
- Defined in:
- lib/rdo/util.rb
Overview
This file contains methods useful for drivers to convert complex types.
Performing these operations in C would not be any cheaper, since the data must first be converted into Ruby types anyway.
Constant Summary collapse
- DEV_NULL =
A suitable NULL device for writing nothing
if defined? IO::NULL IO::NULL else ENV["OS"] =~ /Windows/ ? "NUL" : "/dev/null" end
Class Method Summary collapse
-
.date(s) ⇒ Date
Convert a date string into a Date.
-
.date_time_with_zone(s) ⇒ DateTime
Convert a date & time string, with a time zone, into a DateTime.
-
.date_time_without_zone(s) ⇒ DateTime
Convert a date & time string, without a time zone, into a DateTime.
-
.decimal(s) ⇒ BigDecimal
Convert a String to a BigDecimal.
-
.float(s) ⇒ Float
Convert a String to a Float, taking into account Infinity and NaN.
-
.system_time_zone ⇒ String
Get the time zone of the local system.
Class Method Details
.date(s) ⇒ Date
Convert a date string into a Date.
This method understands AD and BC.
91 92 93 |
# File 'lib/rdo/util.rb', line 91 def date(s) Date.parse(s) end |
.date_time_with_zone(s) ⇒ DateTime
Convert a date & time string, with a time zone, into a DateTime.
78 79 80 |
# File 'lib/rdo/util.rb', line 78 def date_time_with_zone(s) DateTime.parse(s) end |
.date_time_without_zone(s) ⇒ DateTime
Convert a date & time string, without a time zone, into a DateTime.
This method will parse the DateTime using the system time zone.
67 68 69 |
# File 'lib/rdo/util.rb', line 67 def date_time_without_zone(s) date_time_with_zone(s + system_time_zone) end |
.decimal(s) ⇒ BigDecimal
Convert a String to a BigDecimal.
54 55 56 |
# File 'lib/rdo/util.rb', line 54 def decimal(s) BigDecimal(s) end |
.float(s) ⇒ Float
Convert a String to a Float, taking into account Infinity and NaN.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rdo/util.rb', line 34 def float(s) case s when "Infinity" Float::INFINITY when "-Infinity" -Float::INFINITY when "NaN" Float::NAN else Float(s) end end |
.system_time_zone ⇒ String
Get the time zone of the local system.
This is useful—in fact crucial—for ensuring times are represented correctly.
Driver developers should use this, where possible, to notify the DBMS of the client’s time zone.
105 106 107 |
# File 'lib/rdo/util.rb', line 105 def system_time_zone DateTime.now.zone end |