Sha256: a83751fed5c72d02b019217bebc3fc29b5ea78e803dc03d22c135c4d8ed4c52a

Contents?: true

Size: 993 Bytes

Versions: 50

Compression:

Stored size: 993 Bytes

Contents

require "cgi"
require "date"

module Gyoku
  module XMLValue
    class << self

      # 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"

      # Converts a given +object+ to an XML value.
      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

    end
  end
end

Version data entries

50 entries across 42 versions & 5 rubygems

Version Path
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-unbundled-2.2.0.0 vendor/bundle/ruby/2.5.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-unbundled-2.1.4.0 vendor/bundle/ruby/2.5.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-unbundled-2.1.2.0 vendor/bundle/ruby/2.3.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-unbundled-2.1.1.0 vendor/bundle/ruby/2.5.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-unbundled-2.0.4.0 vendor/bundle/ruby/2.5.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-unbundled-2.0.3.0 vendor/bundle/ruby/2.5.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.4.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.5.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-unbundled-2.0.1.0 vendor/bundle/ruby/2.4.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-unbundled-2.0.0.1 vendor/bundle/ruby/2.4.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-unbundled-1.9.8.1 vendor/bundle/ruby/2.4.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-unbundled-1.9.7.1 vendor/bundle/ruby/2.4.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/gems/gyoku-1.3.1/lib/gyoku/xml_value.rb