Class: Resync::XML::TimeNode

Inherits:
XML::Mapping::SingleAttributeNode
  • Object
show all
Defined in:
lib/resync/xml.rb

Overview

Maps Time objects.

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ TimeNode

Returns a new instance of TimeNode.



61
62
63
64
65
# File 'lib/resync/xml.rb', line 61

def initialize(*args)
  path, *args = super(*args)
  @path = ::XML::XXPath.new(path)
  args
end

Instance Method Details

#extract_attr_value(xml) ⇒ Object

Implements ::XML::Mapping::SingleAttributeNode#extract_attr_value.



68
69
70
71
# File 'lib/resync/xml.rb', line 68

def extract_attr_value(xml)
  value = default_when_xpath_err { @path.first(xml).text }
  value ? Time.iso8601(value).utc : nil
end

#set_attr_value(xml, value) ⇒ Object

Implements ::XML::Mapping::SingleAttributeNode#set_attr_value.



74
75
76
# File 'lib/resync/xml.rb', line 74

def set_attr_value(xml, value)
  @path.first(xml, ensure_created: true).text = value.iso8601
end