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

Inherits:
Object
  • Object
show all
Defined in:
lib/saxon/item_type/value_to_ruby.rb

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.



19
20
21
22
# File 'lib/saxon/item_type/value_to_ruby.rb', line 19

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.



17
18
19
# File 'lib/saxon/item_type/value_to_ruby.rb', line 17

def match
  @match
end

#timestringObject (readonly)

Returns the value of attribute timestring.



17
18
19
# File 'lib/saxon/item_type/value_to_ruby.rb', line 17

def timestring
  @timestring
end

Class Method Details

.call(xdm_atomic_value) ⇒ Object



13
14
15
# File 'lib/saxon/item_type/value_to_ruby.rb', line 13

def self.call(xdm_atomic_value)
  new(xdm_atomic_value).convert
end

Instance Method Details

#convertObject



24
25
26
27
# File 'lib/saxon/item_type/value_to_ruby.rb', line 24

def convert
  return timestring if match.nil?
  Time.new(*integer_parts, decimal_part, tz_part)
end

#decimal_partObject



33
34
35
# File 'lib/saxon/item_type/value_to_ruby.rb', line 33

def decimal_part
  Float(match[6])
end

#integer_partsObject



29
30
31
# File 'lib/saxon/item_type/value_to_ruby.rb', line 29

def integer_parts
  match[1..5].map { |n| Integer(n, 10) }
end

#tz_partObject



37
38
39
40
# File 'lib/saxon/item_type/value_to_ruby.rb', line 37

def tz_part
  tz_string = match[7]
  tz_string == 'Z' ? '+00:00' : tz_string
end