Module: Junoser::Xsd::Base

Included in:
Choice, ComplexType, Element, Enumeration, Restriction, Sequence, SimpleContent, SimpleType, Union
Defined in:
lib/junoser/xsd/base.rb

Constant Summary collapse

OFFSET =
'  '

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



6
7
8
# File 'lib/junoser/xsd/base.rb', line 6

def parent
  @parent
end

#xmlObject (readonly)

Returns the value of attribute xml.



6
7
8
# File 'lib/junoser/xsd/base.rb', line 6

def xml
  @xml
end

Instance Method Details

#childrenObject



20
21
22
# File 'lib/junoser/xsd/base.rb', line 20

def children
  @children ||= xml.xpath('./*[not(self::xsd:annotation)]')
end

#configObject



16
17
18
# File 'lib/junoser/xsd/base.rb', line 16

def config
  raise 'ERROR: no implementation'
end

#initialize(xml, options = {}) ⇒ Object



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

def initialize(xml, options = {})
  @xml = xml
  @depth = options[:depth] || 0
  @parent = options[:parent]
end

#inspectObject



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

def inspect
  ["#<#{self.class}:0x#{object_id}",
   "xml=#{xml.namespace.prefix}:#{xml.name} " \
   "attributes=#{xml.attributes.transform_values(&:value)}" <<
     (respond_to?(:label) ? " label=#{label}" : ''),
   'config=[',
   *config.map(&:inspect),
   ']>'].join("\n#{OFFSET * (@depth + 1)}")
end

#oneliner?Boolean

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/junoser/xsd/base.rb', line 38

def oneliner?
  # don't use "/flag" as xsd manipulation automatically add "xsd:" prefix
  @oneliner ||= !xml.xpath('./xsd:annotation/xsd:appinfo/*[local-name()="flag" and text()="oneliner"]').empty?
end

#root?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/junoser/xsd/base.rb', line 24

def root?
  @depth == 1
end