Class: RXSD::XSD::Attribute

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

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defaultObject

attribute attributes



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

def default
  @default
end

#fixedObject

attribute attributes



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

def fixed
  @fixed
end

#formObject

attribute attributes



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

def form
  @form
end

#idObject

attribute attributes



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

def id
  @id
end

#nameObject

attribute attributes



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

def name
  @name
end

#parentObject

attribute parent



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

def parent
  @parent
end

#refObject

attribute attributes



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

def ref
  @ref
end

#simple_typeObject

attribute children



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

def simple_type
  @simple_type
end

#typeObject

attribute attributes



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

def type
  @type
end

#useObject

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.related
   node.related = 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_nameObject

xml tag name



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

def self.tag_name
  "attribute"
end

Instance Method Details

#child_attributesObject

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

#childrenObject

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

#infoObject

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_builderObject

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