Class: XML::MappingExtensions::DateNode
- Inherits:
-
NodeBase
- Object
- XML::Mapping::SingleAttributeNode
- NodeBase
- XML::MappingExtensions::DateNode
- Defined in:
- lib/xml/mapping_extensions/date_node.rb
Overview
XML mapping for XML Schema dates.
Known limitation: loses time zone info (Ruby Date
doesn't
support it)
Instance Method Summary collapse
-
#to_value(xml_text) ⇒ Date
Converts an XML Schema date string to a
Date
object. -
#to_xml_text(value) ⇒ String
Converts a
Date
object to an XML schema string. -
#zulu ⇒ Boolean?
Whether date should be output with UTC "Zulu" time designator ("Z").
Methods inherited from NodeBase
#extract_attr_value, #initialize, #set_attr_value
Constructor Details
This class inherits a constructor from XML::MappingExtensions::NodeBase
Instance Method Details
#to_value(xml_text) ⇒ Date
Converts an XML Schema date string to a Date
object
22 23 24 |
# File 'lib/xml/mapping_extensions/date_node.rb', line 22 def to_value(xml_text) Date.xmlschema(xml_text) end |
#to_xml_text(value) ⇒ String
Converts a Date
object to an XML schema string
30 31 32 33 34 |
# File 'lib/xml/mapping_extensions/date_node.rb', line 30 def to_xml_text(value) value = value.to_date if value.respond_to?(:to_date) text = value.iso8601 # use iso8601 instead of xmlschema in case of ActiveSupport shenanigans zulu && !text.end_with?('Z') ? "#{text}Z" : text end |
#zulu ⇒ Boolean?
Whether date should be output with UTC "Zulu" time designator ("Z")
15 16 17 |
# File 'lib/xml/mapping_extensions/date_node.rb', line 15 def zulu @options[:zulu] end |