Class: RXSD::XSD::Group

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

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#choiceObject

group children



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

def choice
  @choice
end

#idObject

group attributes



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

def id
  @id
end

#maxOccursObject

group attributes



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

def maxOccurs
  @maxOccurs
end

#minOccursObject

group attributes



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

def minOccurs
  @minOccurs
end

#nameObject

group attributes



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

def name
  @name
end

#parentObject

group parent



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

def parent
  @parent
end

#refObject

group attributes



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

def ref
  @ref
end

#sequenceObject

group children



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

def sequence
  @sequence
end

Class Method Details

.from_xml(node) ⇒ Object

node passed in should be a xml node representing the group



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rxsd/xsd/group.rb', line 41

def self.from_xml(node)
   group = Group.new
   group.parent = node.parent.related
   node.related = group

   # TODO group attributes: | anyAttributes
   group.id       = node.attrs["id"]
   group.name     = node.attrs["name"]
   group.ref      = node.attrs["ref"]

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


   # TODO group children: | element(?)
   group.choice   = node.child_obj Choice
   group.sequence = node.child_obj Sequence

   return group
end

.tag_nameObject

xml tag name



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

def self.tag_name
  "group"
end

Instance Method Details

#child_attributesObject

return all child attributes assocaited w/ group



90
91
92
93
94
95
# File 'lib/rxsd/xsd/group.rb', line 90

def child_attributes
   atts = []
   atts += @sequence.child_attributes  unless @sequence.nil?
   atts += @choice.child_attributes    unless @choice.nil?
   return atts
end

#childrenObject

returns array of all children



33
34
35
36
37
38
# File 'lib/rxsd/xsd/group.rb', line 33

def children
  c = []
  c.push @choice unless @choice.nil?
  c.push @sequence unless @sequence.nil?
  return c
end

#infoObject

return xsd node info



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

def info
  "group id: #{@id} name: #{@name} ref: #{ref.nil? ? "" : ref.class == String ? ref : ref.name} "
end

#resolve(node_objs) ⇒ Object

resolve hanging references given complete xsd node object array



65
66
67
68
69
# File 'lib/rxsd/xsd/group.rb', line 65

def resolve(node_objs)
  unless @ref.nil?
    @ref = node_objs[Group].find { |no| no.name == @ref }
  end
end

#to_class_buildersObject

convert group to array of class builders



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rxsd/xsd/group.rb', line 72

def to_class_builders
  unless defined? @class_builder
    # just dispatch to ref or child
    @class_builder = []

    if !@ref.nil?
       @class_builder = @ref.to_class_builders
    elsif !@choice.nil?
       @class_builder =  @choice.to_class_builders
    elsif !@sequence.nil?
       @class_builder =  @sequence.to_class_builders
    end
  end

  return @class_builder
end