Class: Saxon::ItemType::ValueToRuby::DateTimeConvertor

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#matchObject (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

#timestringObject (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.

Returns:

  • (Time, String)

    the converted Time, or the original XDM lexical string if conversion isn’t possible



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

#convertTime, String

Return a Time instance if possible, otherwise return the string value from the XDM.

Returns:

  • (Time, String)

    the converted Time, or the original string



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