Class: XmlParsable::Elements::TimeElement

Inherits:
AbstractElement show all
Defined in:
lib/xmlparsable/elements/time.rb

Overview

Parses content into a ruby Time value

Defined Under Namespace

Classes: Time

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractElement

#comment, #open, parsable

Constructor Details

#initialize(name, attributes, parent, arguments) ⇒ TimeElement

Returns a new instance of TimeElement.



16
17
18
19
# File 'lib/xmlparsable/elements/time.rb', line 16

def initialize(name, attributes, parent, arguments)
  @name, @attributes, @parent, @string =
    name, attributes, parent, ""
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/xmlparsable/elements/time.rb', line 14

def name
  @name
end

Instance Method Details

#finalizeObject



25
26
27
28
29
30
31
# File 'lib/xmlparsable/elements/time.rb', line 25

def finalize
  stripped = @string.strip
  time     = stripped == "" ? nil : Time.parse(stripped)
  time.instance_variable_set(:@xmlattrs, @attributes)

  @parent.close(self, time)
end

#read(text) ⇒ Object



21
22
23
# File 'lib/xmlparsable/elements/time.rb', line 21

def read(text)
  @string << text
end