Class: StixSchemaSpy::SimpleType
- Defined in:
- lib/stix_schema_spy/models/simple_type.rb
Instance Attribute Summary
Attributes inherited from Type
#documentation, #inline, #name, #schema
Class Method Summary collapse
Instance Method Summary collapse
-
#complex? ⇒ Boolean
Not a complex type.
- #elements ⇒ Object
-
#enumeration? ⇒ Boolean
Returns whether or not this simple type is an enumeration.
-
#enumeration_values ⇒ Object
Returns the list of values for this enumeration.
- #fields ⇒ Object
-
#has_example? ⇒ Boolean
A shortcut to checking whether there’s an example because simple types never have examples.
- #own_fields ⇒ Object
Methods inherited from Type
#abstract?, #ancestors, #child_types, counter, #doc_path, #example, find, #full_name, #get_extension, #has_own_fields?, #initialize, inline, #inspect, #own_usages, #parent_type, #prefix, #stix_version, #url, #usages, #use, #use_parent, #vocab?
Constructor Details
This class inherits a constructor from StixSchemaSpy::Type
Class Method Details
.build(xml, schema) ⇒ Object
6 7 8 |
# File 'lib/stix_schema_spy/models/simple_type.rb', line 6 def self.build(xml, schema) self.new(xml, schema) end |
Instance Method Details
#complex? ⇒ Boolean
Not a complex type
31 32 33 |
# File 'lib/stix_schema_spy/models/simple_type.rb', line 31 def complex? false end |
#elements ⇒ Object
43 44 45 |
# File 'lib/stix_schema_spy/models/simple_type.rb', line 43 def elements [] end |
#enumeration? ⇒ Boolean
Returns whether or not this simple type is an enumeration
11 12 13 |
# File 'lib/stix_schema_spy/models/simple_type.rb', line 11 def enumeration? @is_enumeration ||= @xml.xpath('./xs:restriction/xs:enumeration', {'xs' => 'http://www.w3.org/2001/XMLSchema'}).length > 0 end |
#enumeration_values ⇒ Object
Returns the list of values for this enumeration
16 17 18 19 20 21 22 23 |
# File 'lib/stix_schema_spy/models/simple_type.rb', line 16 def enumeration_values enumeration = @xml.xpath('./xs:restriction/xs:enumeration', {'xs' => 'http://www.w3.org/2001/XMLSchema'}) if enumeration.length > 0 return enumeration.map {|elem| [elem.attributes['value'].value, elem.xpath('./xs:annotation/xs:documentation', {'xs' => 'http://www.w3.org/2001/XMLSchema'}).text]} else raise "Not an enumeration" end end |
#fields ⇒ Object
35 36 37 |
# File 'lib/stix_schema_spy/models/simple_type.rb', line 35 def fields [] end |
#has_example? ⇒ Boolean
A shortcut to checking whether there’s an example because simple types never have examples
26 27 28 |
# File 'lib/stix_schema_spy/models/simple_type.rb', line 26 def has_example? false end |
#own_fields ⇒ Object
39 40 41 |
# File 'lib/stix_schema_spy/models/simple_type.rb', line 39 def own_fields [] end |