Sha256: 292f57ab8260adf83b75ce704f7f5564e6ffcd63af92c6fe6882967dd3a1b725

Contents?: true

Size: 1.18 KB

Versions: 17

Compression:

Stored size: 1.18 KB

Contents

require 'junoser/xsd/base'
require 'junoser/xsd/enumeration'
require 'junoser/xsd/simple_type'

module Junoser
  module Xsd
    class Restriction
      include Base

      def children
        @children||= xml.xpath('./*[not(self::xsd:annotation or ' +
                               'self::xsd:minInclusive or self::xsd:maxInclusive or ' +
                               'self::xsd:minLength or self::xsd:maxLength)]')
      end

      def config
        @config ||= children.map {|child|
          case child.name
          when 'enumeration'
            Junoser::Xsd::Enumeration.new(child, depth: @depth+1, parent: self)
          when 'simpleType'
            Junoser::Xsd::SimpleType.new(child, depth: @depth+1, parent: self)
          when 'attribute'
          else
            raise "ERROR: unknown element: #{child.name}"
          end
        }.compact
      end

      def to_s
        return format('arg') if config.empty?

        str = enumeration? ? 'enum' : ''
        str += '(' + config.map {|c| c.to_s.strip }.join(' | ') + ')'
        format(str)
      end


      private

      def enumeration?
        children.reject {|c| c.name != 'enumeration'}.empty?
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
junoser-0.6.0 lib/junoser/xsd/restriction.rb
junoser-0.5.6 lib/junoser/xsd/restriction.rb
junoser-0.5.5 lib/junoser/xsd/restriction.rb
junoser-0.5.4 lib/junoser/xsd/restriction.rb
junoser-0.5.3 lib/junoser/xsd/restriction.rb
junoser-0.5.2 lib/junoser/xsd/restriction.rb
junoser-0.5.1 lib/junoser/xsd/restriction.rb
junoser-0.5.0 lib/junoser/xsd/restriction.rb
junoser-0.4.7 lib/junoser/xsd/restriction.rb
junoser-0.4.6 lib/junoser/xsd/restriction.rb
junoser-0.4.5 lib/junoser/xsd/restriction.rb
junoser-0.4.4 lib/junoser/xsd/restriction.rb
junoser-0.4.3 lib/junoser/xsd/restriction.rb
junoser-0.4.2 lib/junoser/xsd/restriction.rb
junoser-0.4.1 lib/junoser/xsd/restriction.rb
junoser-0.4.0 lib/junoser/xsd/restriction.rb
junoser-0.3.13 lib/junoser/xsd/restriction.rb