Class: Stix2::Common

Inherits:
Base
  • Object
show all
Defined in:
lib/stix2/common.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Common

Returns a new instance of Common.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/stix2/common.rb', line 21

def initialize(options = {})
  Hashie.symbolize_keys!(options)
  type = to_dash(self.class.name.split('::').last)
  if options[:type]
    if !options[:type].start_with?('x-') && options[:type] != type
      raise("Property 'type' must be '#{type}'")
    end
  else
    options[:type] = type
  end
  process_toplevel_property_extension(options[:extensions])
  super(options)
  process_extensions(options)
  Stix2::Storage.add(self)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/stix2/common.rb', line 37

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_scaleObject



51
52
53
# File 'lib/stix2/common.rb', line 51

def confidence_scale
  Stix2::ConfidenceScale.new(confidence)
end