Class: Junoser::Xsd::Restriction

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/junoser/xsd/restriction.rb

Constant Summary

Constants included from Base

Base::OFFSET

Instance Attribute Summary

Attributes included from Base

#parent, #xml

Instance Method Summary collapse

Methods included from Base

#initialize, #inspect, #oneliner?, #root?

Instance Method Details

#childrenObject



10
11
12
13
14
# File 'lib/junoser/xsd/restriction.rb', line 10

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

#configObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/junoser/xsd/restriction.rb', line 16

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

#to_sObject



30
31
32
33
34
35
36
# File 'lib/junoser/xsd/restriction.rb', line 30

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

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