Class: XML::MappingExtensions::DateNode

Inherits:
NodeBase
  • Object
show all
Defined in:
lib/xml/mapping_extensions/date_node.rb

Overview

XML mapping for XML Schema dates. Known limitation: loses time zone info

Instance Method Summary collapse

Methods inherited from NodeBase

#extract_attr_value, #set_attr_value

Constructor Details

#initialize(*args) ⇒ DateNode

Returns a new instance of DateNode.



11
12
13
# File 'lib/xml/mapping_extensions/date_node.rb', line 11

def initialize(*args)
  super
end

Instance Method Details

#to_value(xml_text) ⇒ Date

param xml_text [String] an XML Schema date

Returns:

  • (Date)

    the value as a Date



25
26
27
# File 'lib/xml/mapping_extensions/date_node.rb', line 25

def to_value(xml_text)
  Date.xmlschema(xml_text)
end

#to_xml_text(value) ⇒ String

Returns the value as an XML Schema date string, without time zone information.

Parameters:

  • value (Date)

    the value as a Date

Returns:

  • (String)

    the value as an XML Schema date string, without time zone information



32
33
34
35
# File 'lib/xml/mapping_extensions/date_node.rb', line 32

def to_xml_text(value)
  text = value.xmlschema
  zulu ? "#{text}Z" : text
end

#zuluBoolean?

Whether date should be output with UTC "Zulu" time designator ("Z")

Returns:

  • (Boolean, nil)

    True if date should be output with "Z" time designator, false or nil otherwise



19
20
21
# File 'lib/xml/mapping_extensions/date_node.rb', line 19

def zulu
  @options[:zulu]
end