Class: Stix2::Common
- Includes:
- Hashie::Extensions::Dash::PropertyTranslation
- Defined in:
- lib/stix2/common.rb
Direct Known Subclasses
Bundle, CustomObject, Stix2::CyberobservableObject::Base, DomainObject::Base, ExtensionDefinition, MetaObject::Base, MetaObject::DataMarking::MarkingDefinition, RelationshipObject::Base
Instance Method Summary collapse
- #confidence_scale ⇒ Object
-
#initialize(options = {}) ⇒ Common
constructor
A new instance of Common.
- #method_missing(m, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Common
Returns a new instance of Common.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/stix2/common.rb', line 29 def initialize( = {}) Hashie.symbolize_keys!() type = to_dash(self.class.name.split("::").last) if [:type] if ![:type].start_with?("x-") && [:type] != type raise("Property 'type' must be '#{type}'") end else [:type] = type end [:id] ||= "#{type}--#{SecureRandom.uuid}" process_toplevel_property_extension([:extensions]) super() process_extensions() Stix2::Storage.add(self) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/stix2/common.rb', line 48 def method_missing(m, *args, &block) if !m.to_s.end_with?("_instance") # :nocov: super(m, args, block) return # :nocov: end # Retrieve the original method ref_method = m.to_s.gsub(/_instance$/, "") obj = send(ref_method) raise("Can't get a Stix2::Identifier from #{ref_method}") if !obj.is_a?(Stix2::Identifier) Stix2::Storage.find(obj) end |
Instance Method Details
#confidence_scale ⇒ Object
66 67 68 |
# File 'lib/stix2/common.rb', line 66 def confidence_scale Stix2::ConfidenceScale.new(confidence) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
62 63 64 |
# File 'lib/stix2/common.rb', line 62 def respond_to_missing?(method_name, include_private = false) method_name.to_s.start_with?("_instance") || super end |