2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/wikidata/diff/description_analyzer.rb', line 2
def self.isolate_descriptions_differences(current_content, parent_content)
return {
changed_descriptions: [],
removed_descriptions: [],
added_descriptions: []
} if current_content.nil? && parent_content.nil?
if current_content
current_descriptions = current_content['descriptions']
if current_descriptions.nil? || current_descriptions.is_a?(Array)
current_descriptions = {}
end
else
current_descriptions = {}
end
if parent_content
parent_descriptions = parent_content['descriptions']
if parent_descriptions.nil? || parent_descriptions.is_a?(Array)
parent_descriptions = {}
end
else
parent_descriptions = {}
end
changed_descriptions = [] removed_descriptions = [] added_descriptions = []
if parent_content.nil?
if !current_descriptions.empty?
current_descriptions.each do |lang, description|
added_descriptions << { lang: lang }
end
end
return {
changed_descriptions: changed_descriptions,
removed_descriptions: removed_descriptions,
added_descriptions: added_descriptions
}
else
(current_descriptions).each do |lang, current_description|
if parent_descriptions.empty?
added_descriptions << { lang: lang }
elsif parent_descriptions[lang].nil?
added_descriptions << { lang: lang }
elsif current_description != parent_descriptions[lang]
changed_descriptions << { lang: lang }
end
end
(parent_descriptions).each do |lang, parent_description|
if current_descriptions.empty?
removed_descriptions << { lang: lang }
end
end
end
{
changed_descriptions: changed_descriptions,
removed_descriptions: removed_descriptions,
added_descriptions: added_descriptions
}
end
|