Class: XmlParsable::Elements::DateElement

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

Overview

Parses content into a ruby Date value

Defined Under Namespace

Classes: Date

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractElement

#comment, #open, parsable

Constructor Details

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

Returns a new instance of DateElement.



16
17
18
19
# File 'lib/xmlparsable/elements/date.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/date.rb', line 14

def name
  @name
end

Instance Method Details

#finalizeObject



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

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

  @parent.close(self, date)
end

#read(text) ⇒ Object



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

def read(text)
  @string << text
end