-
Notifications
You must be signed in to change notification settings - Fork 12
/
translation_item.rb
49 lines (42 loc) · 1.23 KB
/
translation_item.rb
1
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
require_relative './item.rb'
module ZendeskIntegration::V2::Zendesk
class TranslationItem < Item
def build
@translations = {}
return nil if @zendesk_obj.nil?
@zendesk_obj.send(:translations).to_a!.map do |t|
@translations[t.locale] = t
next nil if @crawler.locales[t.locale].nil? || ignore?(t)
[t.locale, translation(t)]
end.compact.to_h
end
def simple locale
type = self.class.name.split('::').last
not_found = !exists?(locale) || ignore?(@translations[locale])
return { title: "#{type} deleted" } if not_found
@data[locale].select { |k, _v| %i(id title).include? k }
end
def to_index
@data.values.compact
end
def exists? locale
super() && !@data[locale].nil?
end
def ignore? _t
super()
end
protected
def translation t
{
locale: @crawler.locales[t.locale],
objectID: t.id,
id: @zendesk_obj.id.to_s,
updated_at: t.updated_at.to_i / TIME_FRAME,
position: @zendesk_obj.position,
title: t.title,
body_safe: truncate(decode(t.body), @crawler.config['max_content_size']),
outdated: @zendesk_obj.outdated || t.outdated
}
end
end
end