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



12
13
14
15
16
# File 'lib/junoser/xsd/restriction.rb', line 12

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



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

def config
  @config ||= children.map do |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'
      nil
    else
      raise "ERROR: unknown element: #{child.name}"
    end
  end.compact
end

#to_sObject



33
34
35
36
37
38
39
# File 'lib/junoser/xsd/restriction.rb', line 33

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

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