Class: Owldiff::OntologyDiff

Inherits:
Object
  • Object
show all
Defined in:
lib/owldiff/ontology_diff.rb

Constant Summary collapse

SINGLE_CHANGE_TYPES =
[:format,:ontology_id].map{ |type| "#{type}_change".to_sym }
SET_CHANGE_TYPES =
[:prefix,:import,:annotation,:axiom].map{ |type| "#{type}_changes".to_sym }
ENTITIES =
[:new,:modified,:removed].map{ |type| "#{type}_entities".to_sym }
ALL_TYPES =
SINGLE_CHANGE_TYPES + SET_CHANGE_TYPES + ENTITIES
FROM_JSON =
{
  SINGLE_CHANGE_TYPES => lambda { |change| OntologyChange.from_hash(change) },
  SET_CHANGE_TYPES => lambda { |changes| OntologyDiff.from_array(OntologyChange, changes)},
  ENTITIES => lambda { |entities| OntologyDiff.from_array(OntologyEntity, entities) }
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(binary_identical) ⇒ OntologyDiff

Returns a new instance of OntologyDiff.



19
20
21
# File 'lib/owldiff/ontology_diff.rb', line 19

def initialize binary_identical
  @binary_identical = binary_identical
end

Class Method Details

.from_json(json) ⇒ Object

Raises:



35
36
37
38
39
40
41
42
43
# File 'lib/owldiff/ontology_diff.rb', line 35

def self.from_json json
  ontology_changes = JSON.parse(json)
  raise OwldiffError.new, ontology_changes["error"] if ontology_changes["error"]
  diff = OntologyDiff.new ontology_changes["binary_identical"]
  FROM_JSON.each do |types, block|
    diff.type_from_hash types, ontology_changes, block
  end
  diff
end

Instance Method Details

#binary_identical?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/owldiff/ontology_diff.rb', line 23

def binary_identical?
  @binary_identical
end

#to_json(*opts) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/owldiff/ontology_diff.rb', line 27

def to_json(*opts)
  diff = { binary_identical: @binary_identical }
  ALL_TYPES.each do |type|
    diff[type] = self.send(type)
  end
  diff.to_json(*opts)
end

#type_from_hash(types, hash, block) ⇒ Object



45
46
47
48
49
50
# File 'lib/owldiff/ontology_diff.rb', line 45

def type_from_hash types, hash, block
  types.each do |type|
    value = hash[type.to_s]
    self.send "#{type}=", block.call(value) if value
  end
end