Sha256: f9259deb683ac3daa3b69d87796a964f5d9415196ff800ff349c2dd94c23dc2d

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 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)
          when 'simpleType'
            Junoser::Xsd::SimpleType.new(child, depth: @depth+1)
          when 'attribute'
          else
            raise "ERROR: unknown element: #{child.name}"
          end
        }.compact
      end

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
junoser-0.3.3 lib/junoser/xsd/restriction.rb
junoser-0.3.2 lib/junoser/xsd/restriction.rb
junoser-0.3.1 lib/junoser/xsd/restriction.rb
junoser-0.3.0 lib/junoser/xsd/restriction.rb