Class: CamTool::EdgeValidator

Inherits:
ProvJSONParser show all
Defined in:
lib/camtool/edge_validator.rb

Instance Method Summary collapse

Methods inherited from ProvJSONParser

#activity, #agent, #entity, #parse_json, #prefix, #read_json_file, #read_log_file

Constructor Details

#initializeEdgeValidator

Returns a new instance of EdgeValidator.



3
4
# File 'lib/camtool/edge_validator.rb', line 3

def initialize
end

Instance Method Details

#is_activity?(id) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'lib/camtool/edge_validator.rb', line 22

def is_activity? id
  id = id.gsub 'cf:', ''
  bytes = Base64.decode64(id).bytes.to_a
  type = bytes[7] & 0xF0
  return type == 0x40
end

#is_agent?(id) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'lib/camtool/edge_validator.rb', line 36

def is_agent? id
  id = id.gsub 'cf:', ''
  bytes = Base64.decode64(id).bytes.to_a
  type = bytes[7] & 0xF0
  return type == 0x10
end

#is_entity?(id) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/camtool/edge_validator.rb', line 29

def is_entity? id
  id = id.gsub 'cf:', ''
  bytes = Base64.decode64(id).bytes.to_a
  type = bytes[7] & 0xF0
  return type == 0x20
end

#is_relation?(id) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
# File 'lib/camtool/edge_validator.rb', line 15

def is_relation? id
  id = id.gsub 'cf:', ''
  bytes = Base64.decode64(id).bytes.to_a
  type = bytes[7] & 0xF0
  return type == 0x80
end


6
7
8
9
10
11
12
13
# File 'lib/camtool/edge_validator.rb', line 6

def print_relation_bytes id
  id = id.gsub 'cf:', ''
  bytes = Base64.decode64(id).bytes.to_a
  type = bytes[7] & 0xF0
  puts type.to_s(16)
  type = bytes[8]
  puts type.to_s(16)
end

#relation(k, v) ⇒ Object



68
69
70
71
72
# File 'lib/camtool/edge_validator.rb', line 68

def relation k, v
  print_relation_bytes k
  puts v
  abort "relation should not be used"
end

#used(k, v) ⇒ Object



43
44
45
46
# File 'lib/camtool/edge_validator.rb', line 43

def used k, v
  abort "used prov:entity is of wrong type:  #{v}." unless is_entity? v['prov:entity']
  abort "used prov:activity is of wrong type: #{v}." unless is_activity? v['prov:activity']
end

#wasAssociatedWith(k, v) ⇒ Object



63
64
65
66
# File 'lib/camtool/edge_validator.rb', line 63

def wasAssociatedWith k, v
  abort "wasAssociatedWith prov:activity is of wrong type:  #{v}." unless is_activity? v['prov:activity']
  abort "wasAssociatedWith prov:agent is of wrong type: #{v}." unless is_agent? v['prov:agent']
end

#wasDerivedFrom(k, v) ⇒ Object



53
54
55
56
# File 'lib/camtool/edge_validator.rb', line 53

def wasDerivedFrom k, v
  abort "wasDerivedFrom prov:usedEntity is of wrong type:  #{v}." unless is_entity? v['prov:usedEntity']
  abort "wasDerivedFrom prov:generatedEntity is of wrong type: #{v}." unless is_entity? v['prov:generatedEntity']
end

#wasGeneratedBy(k, v) ⇒ Object



48
49
50
51
# File 'lib/camtool/edge_validator.rb', line 48

def wasGeneratedBy k, v
  abort "wasGeneratedBy prov:entity is of wrong type:  #{v}." unless is_entity? v['prov:entity']
  abort "wasGeneratedBy prov:activity is of wrong type: #{v}." unless is_activity? v['prov:activity']
end

#wasInformedBy(k, v) ⇒ Object



58
59
60
61
# File 'lib/camtool/edge_validator.rb', line 58

def wasInformedBy k, v
  abort "wasInformedBy prov:informant is of wrong type:  #{v}." unless is_activity? v['prov:informant']
  abort "wasInformedBy prov:informed is of wrong type: #{v}." unless is_activity? v['prov:informed']
end