Class: Stix2::CustomObject

Inherits:
Common
  • Object
show all
Includes:
Hashie::Extensions::IgnoreUndeclared
Defined in:
lib/stix2/custom_object.rb

Instance Method Summary collapse

Methods inherited from Common

#confidence_scale, #method_missing, #respond_to_missing?

Constructor Details

#initialize(options) ⇒ CustomObject

Returns a new instance of CustomObject.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/stix2/custom_object.rb', line 7

def initialize(options)
  Hashie.symbolize_keys!(options)
  raise("A CustomObject must have at least one property") if options[:type] && options.count == 1
  errors = Hash.new { |k, v| k[v] = [] }
  options.each do |key, value|
    errors["Too short"] << key if key != :id && key.size < 3
    errors["Invalid name"] << key if !key.match?(/^[a-z0-9_]*$/)
    errors["Too long"] << key if key.size > 250
  end
  raise("Error creating CustomObject: #{errors}") if !errors.empty?
  super(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Stix2::Common