Class: Stix2::Common

Inherits:
Base
  • Object
show all
Includes:
Hashie::Extensions::Dash::PropertyTranslation
Defined in:
lib/stix2/common.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Common

Returns a new instance of Common.



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

def initialize(options = {})
  options_ = options.dup
  Hashie.symbolize_keys!(options_)
  set_strict(options_)
  guess_type(options_)
  autogenerate_id(options_)
  process_toplevel_property_extension(options[:extensions])
  super(options_)
  process_extensions(options_)
  validate_confidence! if @strict
  Stix2::Storage.add(self)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

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_id = public_send(ref_method)
  Stix2::Storage.find(obj_id)
end

Instance Method Details

#confidence_scaleObject



55
56
57
# File 'lib/stix2/common.rb', line 55

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

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


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

def respond_to_missing?(method_name, include_private = false)
  method_name.to_s.start_with?("_instance") || super
end