Class: ActiveStix::ExternalReference

Inherits:
ApplicationRecord show all
Defined in:
app/models/active_stix/external_reference.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ingest_json(obj, parent_obj_id) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/active_stix/external_reference.rb', line 9

def self.ingest_json(obj, parent_obj_id)
  if obj.has_key?('url')
    external_reference = find_or_create_by(url:obj['url'])
  elsif obj.has_key?('source_name') and obj.has_key?('description')
    external_reference = find_or_create_by(source_name:obj['source_name'], description:obj['description'])
  elsif obj.has_key?('source_name') and obj.has_key?('external_id')
    external_reference = find_or_create_by(source_name:obj['source_name'], external_id:obj['external_id'])
  end

  if obj.has_key?('source_name')
    external_reference.source_name = obj['source_name']
  end
  if obj.has_key?('description')
    external_reference.description = obj['description']
  end
  if obj.has_key?('external_id')
    external_reference.external_id = obj['external_id']
  end
  external_reference.save
  external_reference
end

Instance Method Details

#as_stixObject



41
42
43
# File 'app/models/active_stix/external_reference.rb', line 41

def as_stix
  as_json(only: [:source_name, :url, :external_id, :description])
end

#convert_to_jsonObject



31
32
33
34
35
36
37
38
# File 'app/models/active_stix/external_reference.rb', line 31

def convert_to_json
  {
      :source_name => source_name,
      :url => url,
      :external_id => external_id,
      :description => description
  }
end