Class: RXSD::XSD::Choice

Inherits:
Object
  • Object
show all
Defined in:
lib/rxsd/xsd/choice.rb

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#choicesObject

choice children



17
18
19
# File 'lib/rxsd/xsd/choice.rb', line 17

def choices
  @choices
end

#elementsObject

choice children



17
18
19
# File 'lib/rxsd/xsd/choice.rb', line 17

def elements
  @elements
end

#groupsObject

choice children



17
18
19
# File 'lib/rxsd/xsd/choice.rb', line 17

def groups
  @groups
end

#idObject

choice attributes



14
15
16
# File 'lib/rxsd/xsd/choice.rb', line 14

def id
  @id
end

#maxOccursObject

choice attributes



14
15
16
# File 'lib/rxsd/xsd/choice.rb', line 14

def maxOccurs
  @maxOccurs
end

#minOccursObject

choice attributes



14
15
16
# File 'lib/rxsd/xsd/choice.rb', line 14

def minOccurs
  @minOccurs
end

#parentObject

choice parent



20
21
22
# File 'lib/rxsd/xsd/choice.rb', line 20

def parent
  @parent
end

#sequencesObject

choice children



17
18
19
# File 'lib/rxsd/xsd/choice.rb', line 17

def sequences
  @sequences
end

Class Method Details

.from_xml(node) ⇒ Object

node passed in should be a xml node representing the group



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rxsd/xsd/choice.rb', line 38

def self.from_xml(node)
   choice = Choice.new
   choice.parent = node.parent.related
   node.related = choice

   # TODO choice attributes: | anyAttributes
   choice.id       = node.attrs["id"]

   choice.maxOccurs  = node.attrs.has_key?("maxOccurs") ? 
                            (node.attrs["maxOccurs"] == "unbounded" ? "unbounded" : node.attrs["maxOccurs"].to_i) : 1
   choice.minOccurs  = node.attrs.has_key?("minOccurs") ? 
                            (node.attrs["minOccurs"] == "unbounded" ? "unbounded" : node.attrs["minOccurs"].to_i) : 1

   # TODO choice children: | any
   choice.elements      = node.children_objs Element
   choice.groups        = node.children_objs Group
   choice.choices       = node.children_objs Choice
   choice.sequences     = node.children_objs Sequence

   return choice
end

.tag_nameObject

xml tag name



23
24
25
# File 'lib/rxsd/xsd/choice.rb', line 23

def self.tag_name
  "choice"
end

Instance Method Details

#child_attributesObject

return all child attributes assocaited w/ choice



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/rxsd/xsd/choice.rb', line 94

def child_attributes
   atts = []
   @elements.each  { |elem|
       eca = elem.child_attributes
       atts += eca unless eca.nil?
   }  unless @elements.nil?
   @sequences.each { |seq| atts += seq.child_attributes }    unless @sequences.nil?
   @choices.each   { |ch| atts += ch.child_attributes }      unless @choices.nil?
   @groups.each    { |gr| atts += gr.child_attributes }      unless @groups.nil?
   return atts
end

#childrenObject

returns array of all children



33
34
35
# File 'lib/rxsd/xsd/choice.rb', line 33

def children
   @elements + @groups + @choices + @sequences
end

#infoObject

return xsd node info



28
29
30
# File 'lib/rxsd/xsd/choice.rb', line 28

def info
  "choice id: #{@id}"
end

#resolve(node_objs) ⇒ Object

resolve hanging references given complete xsd node object array



61
62
# File 'lib/rxsd/xsd/choice.rb', line 61

def resolve(node_objs)
end

#to_class_buildersObject

convert choice to array of class builders



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/rxsd/xsd/choice.rb', line 65

def to_class_builders
   # FIXME enforce "only one attribute must be set"

   unless defined? @class_builders
     @class_builders = []
     @elements.each { |e|
        @class_builders.push e.to_class_builder
     }
     @groups.each { |g|
        g.to_class_builders.each { |gcb|
          @class_builders.push gcb
        }
     }
     @choices.each { |c|
        c.to_class_builders.each { |ccb|
          @class_builders.push ccb
        }
     }
     @sequences.each { |s|
        s.to_class_builders.each { |scb|
          @class_builders.push scb
        }
     }
   end

   return @class_builders
end