Class: Stix2::RelationshipObject::Relationship

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

Instance Method Summary collapse

Methods inherited from Common

#confidence_scale, #method_missing, #respond_to_missing?

Constructor Details

#initialize(args) ⇒ Relationship

Returns a new instance of Relationship.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/stix2/relationship_objects/relationship.rb', line 11

def initialize(args)
  if !args[:relationship_type] && args[:source_ref] && args[:target_ref]
    objects = DOMAIN_OBJECTS + CYBEROBSERVABLE_OBJECTS
    source_type = type_by_id(args[:source_ref])
    target_type = type_by_id(args[:target_ref])
    relationships = Array(RELATIONSHIP_TYPES.dig(source_type, target_type))
    relationships += COMMON_RELATIONSHIPS if objects.include?(source_type) && objects.include?(target_type)
    args[:relationship_type] = relationships.first unless relationships.empty?
  end

  super(args)
end

Dynamic Method Handling

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