Class: RXSD::XSD::Attribute
- Inherits:
-
Object
- Object
- RXSD::XSD::Attribute
- Defined in:
- lib/rxsd/xsd/attribute.rb
Overview
XSD Attribute defintion www.w3schools.com/Schema/el_attribute.asp
Instance Attribute Summary collapse
-
#default ⇒ Object
attribute attributes.
-
#fixed ⇒ Object
attribute attributes.
-
#form ⇒ Object
attribute attributes.
-
#id ⇒ Object
attribute attributes.
-
#name ⇒ Object
attribute attributes.
-
#parent ⇒ Object
attribute parent.
-
#ref ⇒ Object
attribute attributes.
-
#simple_type ⇒ Object
attribute children.
-
#type ⇒ Object
attribute attributes.
-
#use ⇒ Object
attribute attributes.
Class Method Summary collapse
-
.from_xml(node) ⇒ Object
node passed in should be a xml node representing the attribute.
-
.tag_name ⇒ Object
xml tag name.
Instance Method Summary collapse
-
#child_attributes ⇒ Object
return this attribute (or ref if appropriate) in array.
-
#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 complex type to class builder.
Instance Attribute Details
#default ⇒ Object
attribute attributes
14 15 16 |
# File 'lib/rxsd/xsd/attribute.rb', line 14 def default @default end |
#fixed ⇒ Object
attribute attributes
14 15 16 |
# File 'lib/rxsd/xsd/attribute.rb', line 14 def fixed @fixed end |
#form ⇒ Object
attribute attributes
14 15 16 |
# File 'lib/rxsd/xsd/attribute.rb', line 14 def form @form end |
#id ⇒ Object
attribute attributes
14 15 16 |
# File 'lib/rxsd/xsd/attribute.rb', line 14 def id @id end |
#name ⇒ Object
attribute attributes
14 15 16 |
# File 'lib/rxsd/xsd/attribute.rb', line 14 def name @name end |
#parent ⇒ Object
attribute parent
20 21 22 |
# File 'lib/rxsd/xsd/attribute.rb', line 20 def parent @parent end |
#ref ⇒ Object
attribute attributes
14 15 16 |
# File 'lib/rxsd/xsd/attribute.rb', line 14 def ref @ref end |
#simple_type ⇒ Object
attribute children
17 18 19 |
# File 'lib/rxsd/xsd/attribute.rb', line 17 def simple_type @simple_type end |
#type ⇒ Object
attribute attributes
14 15 16 |
# File 'lib/rxsd/xsd/attribute.rb', line 14 def type @type end |
#use ⇒ Object
attribute attributes
14 15 16 |
# File 'lib/rxsd/xsd/attribute.rb', line 14 def use @use end |
Class Method Details
.from_xml(node) ⇒ Object
node passed in should be a xml node representing the attribute
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rxsd/xsd/attribute.rb', line 40 def self.from_xml(node) attribute = Attribute.new attribute.parent = node.parent. node. = attribute # TODO attribute attributes: | anyAttributes attribute.id = node.attrs["id"] attribute.name = node.attrs["name"] attribute.use = node.attrs["use"] attribute.form = node.attrs.has_key?("form") ? node.attrs["form"] : node.parent.attrs["attributeFormDefault"] attribute.default = node.attrs["default"] attribute.fixed = node.attrs["fixed"] # FIXME ignoring reference namepsace prefix (if any) for now ref = node.attrs["ref"] ref = ref.split(':')[1] if !(ref.nil? || ref.index(":").nil?) attribute.ref = ref if node.children.find { |c| c.name == SimpleType.tag_name }.nil? attribute.type = node.attrs["type"] else attribute.simple_type = node.child_obj SimpleType end return attribute end |
.tag_name ⇒ Object
xml tag name
23 24 25 |
# File 'lib/rxsd/xsd/attribute.rb', line 23 def self.tag_name "attribute" end |
Instance Method Details
#child_attributes ⇒ Object
return this attribute (or ref if appropriate) in array
111 112 113 114 |
# File 'lib/rxsd/xsd/attribute.rb', line 111 def child_attributes return [@ref] unless @ref.nil? return [self] end |
#children ⇒ Object
returns array of all children
33 34 35 36 37 |
# File 'lib/rxsd/xsd/attribute.rb', line 33 def children c = [] c.push @simple_type unless @simple_type.nil? return c end |
#info ⇒ Object
return xsd node info
28 29 30 |
# File 'lib/rxsd/xsd/attribute.rb', line 28 def info "attribute id: #{@id} name: #{@name} type: #{@type.class} ref: #{ref.nil? ? "" : ref.name} " end |
#resolve(node_objs) ⇒ Object
resolve hanging references given complete xsd node object array
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rxsd/xsd/attribute.rb', line 71 def resolve(node_objs) unless @type.nil? builtin = Parser.parse_builtin_type @type @type = !builtin.nil? ? builtin : node_objs[SimpleType].find { |no| no.name == @type } end unless @ref.nil? @ref = node_objs[Attribute].find { |no| no.name == @ref } end end |
#to_class_builder ⇒ Object
convert complex type to class builder
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rxsd/xsd/attribute.rb', line 83 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 @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 end unless @class_builder.nil? || @name == "" || @name.nil? @class_builder.attribute_name = @name @class_builder.klass_name = @name.camelize if @class_builder.klass.nil? && @class_builder.klass_name.nil? end end return @class_builder end |