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.



4
5
6
# File 'lib/junoser/xsd/base.rb', line 4

def parent
  @parent
end

#xmlObject (readonly)

Returns the value of attribute xml.



4
5
6
# File 'lib/junoser/xsd/base.rb', line 4

def xml
  @xml
end

Instance Method Details

#childrenObject



18
19
20
# File 'lib/junoser/xsd/base.rb', line 18

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

#configObject



14
15
16
# File 'lib/junoser/xsd/base.rb', line 14

def config
  raise "ERROR: no implementation"
end

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



8
9
10
11
12
# File 'lib/junoser/xsd/base.rb', line 8

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

#inspectObject



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

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

#oneliner?Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/junoser/xsd/base.rb', line 36

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)


22
23
24
# File 'lib/junoser/xsd/base.rb', line 22

def root?
  @depth == 1
end