Class: Txgh::TxResource

Inherits:
Object
  • Object
show all
Defined in:
lib/txgh/tx_resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_slug, resource_slug, type, source_lang, source_file, lang_map, translation_file) ⇒ TxResource

Returns a new instance of TxResource.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/txgh/tx_resource.rb', line 8

def initialize(project_slug, resource_slug, type, source_lang, source_file,
    lang_map, translation_file)
  @project_slug = project_slug
  @resource_slug = resource_slug
  @type = type
  @source_lang = source_lang
  @source_file = source_file
  @lang_map = {}

  if lang_map
    result = {}
    lang_map.split(',').each do |m|
      key_value = m.split(':', 2)
      result[key_value[0].strip] = key_value[1].strip
    end

    @lang_map = result
  end

  @translation_file = translation_file
end

Instance Attribute Details

#project_slugObject (readonly)

Returns the value of attribute project_slug.



3
4
5
# File 'lib/txgh/tx_resource.rb', line 3

def project_slug
  @project_slug
end

#resource_slugObject (readonly) Also known as: original_resource_slug

Returns the value of attribute resource_slug.



3
4
5
# File 'lib/txgh/tx_resource.rb', line 3

def resource_slug
  @resource_slug
end

#source_fileObject (readonly)

Returns the value of attribute source_file.



4
5
6
# File 'lib/txgh/tx_resource.rb', line 4

def source_file
  @source_file
end

#source_langObject (readonly)

Returns the value of attribute source_lang.



3
4
5
# File 'lib/txgh/tx_resource.rb', line 3

def source_lang
  @source_lang
end

#translation_fileObject (readonly)

Returns the value of attribute translation_file.



4
5
6
# File 'lib/txgh/tx_resource.rb', line 4

def translation_file
  @translation_file
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/txgh/tx_resource.rb', line 3

def type
  @type
end

Instance Method Details

#branchObject



66
67
68
# File 'lib/txgh/tx_resource.rb', line 66

def branch
  nil
end

#L10N_resource_slugObject



30
31
32
# File 'lib/txgh/tx_resource.rb', line 30

def L10N_resource_slug
  "L10N#{resource_slug}"
end

#lang_map(tx_lang) ⇒ Object



34
35
36
# File 'lib/txgh/tx_resource.rb', line 34

def lang_map(tx_lang)
  @lang_map.fetch(tx_lang, tx_lang)
end

#slugsObject



42
43
44
# File 'lib/txgh/tx_resource.rb', line 42

def slugs
  [project_slug, resource_slug]
end

#to_api_hObject



57
58
59
60
61
62
63
64
# File 'lib/txgh/tx_resource.rb', line 57

def to_api_h
  {
    'slug' => resource_slug,
    'i18n_type' => type,
    'source_language_code' => source_lang,
    'name' => translation_file
  }
end

#to_hObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/txgh/tx_resource.rb', line 46

def to_h
  {
    project_slug: project_slug,
    resource_slug: resource_slug,
    type: type,
    source_lang: source_lang,
    source_file: source_file,
    translation_file: translation_file
  }
end

#translation_path(language) ⇒ Object



38
39
40
# File 'lib/txgh/tx_resource.rb', line 38

def translation_path(language)
  translation_file.gsub('<lang>', language)
end