Class: RXSD::XSD::Element
- Inherits:
-
Object
- Object
- RXSD::XSD::Element
- Defined in:
- lib/rxsd/xsd/element.rb
Overview
XSD Element defintion www.w3schools.com/Schema/el_element.asp
Instance Attribute Summary collapse
-
#abstract ⇒ Object
element attribute values.
-
#complex_type ⇒ Object
complex type in element.
-
#default ⇒ Object
element attribute values.
-
#fixed ⇒ Object
element attribute values.
-
#form ⇒ Object
element attribute values.
-
#id ⇒ Object
element attribute values.
-
#maxOccurs ⇒ Object
element attribute values.
-
#minOccurs ⇒ Object
element attribute values.
-
#name ⇒ Object
element attribute values.
-
#nillable ⇒ Object
element attribute values.
-
#parent ⇒ Object
element parent.
-
#ref ⇒ Object
element attribute values.
-
#simple_type ⇒ Object
simple type in element.
-
#substitutionGroup ⇒ Object
element attribute values.
-
#type ⇒ Object
element attribute values.
Class Method Summary collapse
-
.from_xml(node) ⇒ Object
node passed in should be a xml node representing the element.
-
.tag_name ⇒ Object
xml tag name.
Instance Method Summary collapse
-
#child_attributes ⇒ Object
return all child attributes associated w/ element.
-
#children ⇒ Object
returns array of all children.
-
#info ⇒ Object
return xsd node info.
-
#resolve(node_objs) ⇒ Object
resolve hanging references given complete xsd node object array.
-
#to_class_builder ⇒ Object
convert element to class builder.
Instance Attribute Details
#abstract ⇒ Object
element attribute values
14 15 16 |
# File 'lib/rxsd/xsd/element.rb', line 14 def abstract @abstract end |
#complex_type ⇒ Object
complex type in element
23 24 25 |
# File 'lib/rxsd/xsd/element.rb', line 23 def complex_type @complex_type end |
#default ⇒ Object
element attribute values
14 15 16 |
# File 'lib/rxsd/xsd/element.rb', line 14 def default @default end |
#fixed ⇒ Object
element attribute values
14 15 16 |
# File 'lib/rxsd/xsd/element.rb', line 14 def fixed @fixed end |
#form ⇒ Object
element attribute values
14 15 16 |
# File 'lib/rxsd/xsd/element.rb', line 14 def form @form end |
#id ⇒ Object
element attribute values
14 15 16 |
# File 'lib/rxsd/xsd/element.rb', line 14 def id @id end |
#maxOccurs ⇒ Object
element attribute values
14 15 16 |
# File 'lib/rxsd/xsd/element.rb', line 14 def maxOccurs @maxOccurs end |
#minOccurs ⇒ Object
element attribute values
14 15 16 |
# File 'lib/rxsd/xsd/element.rb', line 14 def minOccurs @minOccurs end |
#name ⇒ Object
element attribute values
14 15 16 |
# File 'lib/rxsd/xsd/element.rb', line 14 def name @name end |
#nillable ⇒ Object
element attribute values
14 15 16 |
# File 'lib/rxsd/xsd/element.rb', line 14 def nillable @nillable end |
#parent ⇒ Object
element parent
26 27 28 |
# File 'lib/rxsd/xsd/element.rb', line 26 def parent @parent end |
#ref ⇒ Object
element attribute values
14 15 16 |
# File 'lib/rxsd/xsd/element.rb', line 14 def ref @ref end |
#simple_type ⇒ Object
simple type in element
20 21 22 |
# File 'lib/rxsd/xsd/element.rb', line 20 def simple_type @simple_type end |
#substitutionGroup ⇒ Object
element attribute values
14 15 16 |
# File 'lib/rxsd/xsd/element.rb', line 14 def substitutionGroup @substitutionGroup end |
#type ⇒ Object
element attribute values
14 15 16 |
# File 'lib/rxsd/xsd/element.rb', line 14 def type @type end |
Class Method Details
.from_xml(node) ⇒ Object
node passed in should be a xml node representing the element
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 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 |
# File 'lib/rxsd/xsd/element.rb', line 47 def self.from_xml(node) element = Element.new element.parent = node.parent. node. = element # TODO element attrs: | block / final # TODO element children: | key, keyref, unique element.id = node.attrs["id"] element.name = node.attrs["name"] element.type = node.attrs["type"] element.nillable = node.attrs.has_key?("nillable") ? node.attrs["nillable"].to_b : false element.abstract = node.attrs.has_key?("abstract") ? node.attrs["abstract"].to_b : false unless node.parent.name == Schema.tag_name # FIXME ignoring reference namepsace prefix (if any) for now ref = node.attrs["ref"] ref = ref.split(':')[1] if !(ref.nil? || ref.index(":").nil?) element.ref = ref element.substitutionGroup = node.attrs["substitutionGroup"] element.form = node.attrs.has_key?("form") ? node.attrs["form"] : node.root.attrs["elementFormDefault"] element.maxOccurs = node.attrs.has_key?("maxOccurs") ? (node.attrs["maxOccurs"] == "unbounded" ? "unbounded" : node.attrs["maxOccurs"].to_i) : 1 element.minOccurs = node.attrs.has_key?("minOccurs") ? (node.attrs["minOccurs"] == "unbounded" ? "unbounded" : node.attrs["minOccurs"].to_i) : 1 else element.form = node.parent.attrs["elementFormDefault"] end if node.text? || !node.children.find { |c| c.name == SimpleType.tag_name }.nil? element.default = node.attrs["default"] element.fixed = node.attrs["fixed"] end element.simple_type = node.child_obj SimpleType element.complex_type = node.child_obj ComplexType return element end |
.tag_name ⇒ Object
xml tag name
29 30 31 |
# File 'lib/rxsd/xsd/element.rb', line 29 def self.tag_name "element" end |
Instance Method Details
#child_attributes ⇒ Object
return all child attributes associated w/ element
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/rxsd/xsd/element.rb', line 146 def child_attributes if !@ref.nil? return @ref.child_attributes elsif[SimpleType, ComplexType].include? @type.class return @type.child_attributes elsif !@simple_type.nil? return @simple_type.child_attributes elsif !@complex_type.nil? return @complex_type.child_attributes end end |
#children ⇒ Object
returns array of all children
39 40 41 42 43 44 |
# File 'lib/rxsd/xsd/element.rb', line 39 def children c = [] c.push @simple_type unless @simple_type.nil? c.push @complex_type unless @complex_type.nil? return c end |
#info ⇒ Object
return xsd node info
34 35 36 |
# File 'lib/rxsd/xsd/element.rb', line 34 def info "element id: #{@id} name: #{@name} type: #{@type.class} ref: #{ref.nil? ? "" : ref.class == String ? ref : ref.name} " end |
#resolve(node_objs) ⇒ Object
resolve hanging references given complete xsd node object array
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/rxsd/xsd/element.rb', line 93 def resolve(node_objs) unless @type.nil? builtin = Parser.parse_builtin_type @type simple = node_objs[SimpleType].find { |no| no.name == @type } complex = node_objs[ComplexType].find { |no| no.name == @type } if !builtin.nil? @type = builtin elsif !simple.nil? @type = simple elsif !complex.nil? @type = complex end end unless @ref.nil? @ref = node_objs[Element].find { |no| no.name == @ref } end unless @substitutionGroup.nil? @substitutionGroup = node_objs[Element].find { |no| no.name == @substitutionGroup } end end |
#to_class_builder ⇒ Object
convert element to class builder
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/rxsd/xsd/element.rb', line 117 def to_class_builder unless defined? @class_builder @class_builder = nil if !@ref.nil? @class_builder = @ref.to_class_builder elsif !@type.nil? if @type.class == SimpleType || @type.class == ComplexType @class_builder = @type.to_class_builder.clone # need to clone here as we're refering to a type that may be used elsewhere else @class_builder = ClassBuilder.new :klass => @type end elsif !@simple_type.nil? @class_builder = @simple_type.to_class_builder elsif !@complex_type.nil? @class_builder = @complex_type.to_class_builder end @class_builder.klass_name = @name.camelize unless @class_builder.nil? || @name == "" || @name.nil? end return @class_builder end |