Class: StixSchemaSpy::Node
- Inherits:
-
Object
- Object
- StixSchemaSpy::Node
- Defined in:
- lib/stix_schema_spy/models/node.rb
Instance Attribute Summary collapse
-
#containing_type ⇒ Object
readonly
Returns the value of attribute containing_type.
-
#documentation ⇒ Object
readonly
Returns the value of attribute documentation.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #element? ⇒ Boolean
-
#initialize(xml, schema, containing_type = nil) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #link ⇒ Object
- #name ⇒ Object
- #name! ⇒ Object
- #reference? ⇒ Boolean
-
#referenced_element ⇒ Object
Only valid if this is a reference.
- #stix_version ⇒ Object
- #type ⇒ Object
- #type! ⇒ Object
Constructor Details
#initialize(xml, schema, containing_type = nil) ⇒ Node
7 8 9 10 11 12 |
# File 'lib/stix_schema_spy/models/node.rb', line 7 def initialize(xml, schema, containing_type = nil) @xml = xml @schema = schema @containing_type = containing_type @documentation = @xml.xpath('xs:annotation/xs:documentation', {'xs' => 'http://www.w3.org/2001/XMLSchema'}).to_a.map {|node| node.text}.join("\n") end |
Instance Attribute Details
#containing_type ⇒ Object (readonly)
Returns the value of attribute containing_type.
5 6 7 |
# File 'lib/stix_schema_spy/models/node.rb', line 5 def containing_type @containing_type end |
#documentation ⇒ Object (readonly)
Returns the value of attribute documentation.
5 6 7 |
# File 'lib/stix_schema_spy/models/node.rb', line 5 def documentation @documentation end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
5 6 7 |
# File 'lib/stix_schema_spy/models/node.rb', line 5 def schema @schema end |
Instance Method Details
#element? ⇒ Boolean
22 23 24 |
# File 'lib/stix_schema_spy/models/node.rb', line 22 def element? !attribute? end |
#inspect ⇒ Object
68 69 70 |
# File 'lib/stix_schema_spy/models/node.rb', line 68 def inspect "#<#{self.class.to_s}:#{object_id} @name=\"#{name}\">" end |
#link ⇒ Object
14 15 16 |
# File 'lib/stix_schema_spy/models/node.rb', line 14 def link type.url end |
#name ⇒ Object
45 46 47 |
# File 'lib/stix_schema_spy/models/node.rb', line 45 def name @name ||= name! end |
#name! ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/stix_schema_spy/models/node.rb', line 49 def name! if reference? @xml.attributes['ref'].value.split(':').last else @xml.attributes['name'].value end end |
#reference? ⇒ Boolean
18 19 20 |
# File 'lib/stix_schema_spy/models/node.rb', line 18 def reference? @xml.attributes['ref'] != nil end |
#referenced_element ⇒ Object
Only valid if this is a reference. Also works for attributes, this was a crappy name
58 59 60 61 62 63 64 65 66 |
# File 'lib/stix_schema_spy/models/node.rb', line 58 def referenced_element ref = @xml.attributes['ref'].value @referenced_element ||= if ref =~ /:/ prefix, element = ref.split(':') schema.find_element(element) || schema.find_attribute("@#{element}") if schema = Schema.find(prefix) else self.schema.find_element(ref) || self.schema.find_attribute("@#{ref}") end end |
#stix_version ⇒ Object
72 73 74 |
# File 'lib/stix_schema_spy/models/node.rb', line 72 def stix_version schema.stix_version end |
#type ⇒ Object
26 27 28 |
# File 'lib/stix_schema_spy/models/node.rb', line 26 def type @type ||= type! end |
#type! ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/stix_schema_spy/models/node.rb', line 30 def type! if reference? if referenced_element referenced_element.type.use(self) else ExternalType.new(*@xml.attributes['ref'].value.split(':')).use(self) end elsif named_type = @xml.attributes['type'] type = schema.find_type(named_type.value) || Type.find(named_type.value, nil, stix_version) type.use(self) else Type.inline(@xml, self.schema, self.name).use(self) end end |