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/gloss_analyzer.rb', line 2
def self.isolate_gloss_differences(current_content, parent_content)
return {
changed: [],
removed: [],
added: []
} if current_content.nil? && parent_content.nil?
if current_content
current_glosses = current_content['glosses']
if current_glosses.nil? || current_glosses.is_a?(Array)
current_glosses = {}
end
else
current_glosses = {}
end
if parent_content
parent_glosses = parent_content['glosses']
if parent_glosses.nil? || parent_glosses.is_a?(Array)
parent_glosses = {}
end
else
parent_glosses = {}
end
changed = []
removed = []
added = []
if parent_content.nil?
current_glosses.each do |lang, label|
added << { lang: lang }
end
return {
changed: changed,
removed: removed,
added: added
}
else
(current_glosses || {}).each do |lang, current_gloss|
parent_gloss = parent_glosses[lang]
if parent_gloss.nil?
added << { lang: lang }
elsif current_gloss != parent_gloss
changed << { lang: lang }
end
end
(parent_glosses || {}).each do |lang, parent_gloss|
if current_glosses[lang].nil?
removed << { lang: lang }
end
end
end
{
changed: changed,
removed: removed,
added: added
}
end
|