class StixSchemaSpy::Node
Attributes
containing_type[R]
documentation[R]
schema[R]
Public Class Methods
new(xml, schema, containing_type = nil)
click to toggle source
# 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
Public Instance Methods
element?()
click to toggle source
# File lib/stix_schema_spy/models/node.rb, line 22 def element? !attribute? end
inspect()
click to toggle source
# File lib/stix_schema_spy/models/node.rb, line 68 def inspect "#<#{self.class.to_s}:#{object_id} @name=\"#{name}\">" end
link()
click to toggle source
# File lib/stix_schema_spy/models/node.rb, line 14 def link type.url end
name()
click to toggle source
# File lib/stix_schema_spy/models/node.rb, line 45 def name @name ||= name! end
name!()
click to toggle source
# 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?()
click to toggle source
# File lib/stix_schema_spy/models/node.rb, line 18 def reference? @xml.attributes['ref'] != nil end
referenced_element()
click to toggle source
Only valid if this is a reference. Also works for attributes, this was a crappy name
# 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()
click to toggle source
# File lib/stix_schema_spy/models/node.rb, line 72 def stix_version schema.stix_version end
type()
click to toggle source
# File lib/stix_schema_spy/models/node.rb, line 26 def type @type ||= type! end
type!()
click to toggle source
# 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