Module: Gyoku::XMLValue

Defined in:
lib/gyoku/xml_value.rb

Constant Summary collapse

XS_DATE_FORMAT =

xs:date format

"%Y-%m-%d"
XS_TIME_FORMAT =

xs:time format

"%H:%M:%S"
XS_DATETIME_FORMAT =

xs:dateTime format

"%Y-%m-%dT%H:%M:%S%Z"

Class Method Summary collapse

Class Method Details

.create(object, escape_xml = true, options = {}) ⇒ Object

Converts a given object to an XML value.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gyoku/xml_value.rb', line 18

def create(object, escape_xml = true, options = {})
  if Time === object
    object.strftime XS_TIME_FORMAT
  elsif DateTime === object
    object.strftime XS_DATETIME_FORMAT
  elsif Date === object
    object.strftime XS_DATE_FORMAT
  elsif String === object
    escape_xml ? CGI.escapeHTML(object) : object
  elsif object.respond_to?(:to_datetime)
    create object.to_datetime
  elsif object.respond_to?(:call)
    create object.call
  elsif ::Hash === object
    Gyoku::Hash.to_xml(object, options)
  else
    object.to_s
  end
end