Class: Saxon::ItemType::ValueToRuby::DateTimeConvertor
- Inherits:
-
Object
- Object
- Saxon::ItemType::ValueToRuby::DateTimeConvertor
- Defined in:
- lib/saxon/item_type/value_to_ruby.rb
Overview
Helper class that converts XDM Date/Time strings into something Ruby’s Time class can handle
Instance Attribute Summary collapse
-
#match ⇒ Object
readonly
Returns the value of attribute match.
-
#timestring ⇒ Object
readonly
Returns the value of attribute timestring.
Class Method Summary collapse
-
.call(xdm_atomic_value) ⇒ Time, String
Convert an XDM Date/Time value into a native Ruby Time object.
Instance Method Summary collapse
-
#convert ⇒ Time, String
Return a Time instance if possible, otherwise return the string value from the XDM.
-
#initialize(xdm_atomic_value) ⇒ DateTimeConvertor
constructor
A new instance of DateTimeConvertor.
Constructor Details
#initialize(xdm_atomic_value) ⇒ DateTimeConvertor
Returns a new instance of DateTimeConvertor.
27 28 29 30 |
# File 'lib/saxon/item_type/value_to_ruby.rb', line 27 def initialize(xdm_atomic_value) @timestring = xdm_atomic_value.to_s @match = ValueToRuby::Patterns::DATE_TIME.match(@timestring) end |
Instance Attribute Details
#match ⇒ Object (readonly)
Returns the value of attribute match.
25 26 27 |
# File 'lib/saxon/item_type/value_to_ruby.rb', line 25 def match @match end |
#timestring ⇒ Object (readonly)
Returns the value of attribute timestring.
25 26 27 |
# File 'lib/saxon/item_type/value_to_ruby.rb', line 25 def timestring @timestring end |
Class Method Details
.call(xdm_atomic_value) ⇒ Time, String
Convert an XDM Date/Time value into a native Ruby Time object.
21 22 23 |
# File 'lib/saxon/item_type/value_to_ruby.rb', line 21 def self.call(xdm_atomic_value) new(xdm_atomic_value).convert end |
Instance Method Details
#convert ⇒ Time, String
Return a Time instance if possible, otherwise return the string value from the XDM.
34 35 36 37 |
# File 'lib/saxon/item_type/value_to_ruby.rb', line 34 def convert return timestring if match.nil? Time.new(*integer_parts, decimal_part, tz_part) end |