Sha256: 5993c23b6084955fda4d1e20dbecf14ec012e5bdf8309edbfe1761535ba4a443

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

module Schematic
  module Generator
    class Types
      COMPLEX = {
        :integer  => { :complex_type => 'Integer',  :xsd_type => 'xs:integer' }.freeze,
        :float    => { :complex_type => 'Float',    :xsd_type => 'xs:float' }.freeze,
        :decimal  => { :complex_type => 'Decimal',  :xsd_type => 'xs:decimal' }.freeze,
        :string   => { :complex_type => 'String',   :xsd_type => 'xs:string' }.freeze,
        :text     => { :complex_type => 'Text',     :xsd_type => 'xs:string' }.freeze,
        :datetime => { :complex_type => 'DateTime', :xsd_type => 'xs:dateTime' }.freeze,
        :date     => { :complex_type => 'Date',     :xsd_type => 'xs:date' }.freeze,
        :boolean  => { :complex_type => 'Boolean',  :xsd_type => 'xs:boolean' }.freeze,
        :uuid     => { :complex_type => 'String',   :xsd_type => 'xs:string' }.freeze,
      }.freeze

      def self.xsd(builder)
        Types::COMPLEX.values.uniq.each do |value|
          complex_type_name = value[:complex_type]
          xsd_type = value[:xsd_type]
          builder.xs :complexType, 'name' => complex_type_name do |complex_type|
            complex_type.xs :simpleContent do |simple_content|
              simple_content.xs :extension, 'base' => xsd_type do |extension|
                extension.xs :attribute, 'name' => 'type', 'type' => 'xs:string', 'use' => 'optional'
                extension.xs :attribute, 'name' => 'nil', 'type' => 'xs:boolean', 'use' => 'optional'
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
schematic-0.7.1 lib/schematic/generator/types.rb