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
# 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 = lang_map
  @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



51
52
53
# File 'lib/txgh/tx_resource.rb', line 51

def branch
  nil
end

#has_branch?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/txgh/tx_resource.rb', line 55

def has_branch?
  false
end

#lang_map(tx_lang) ⇒ Object



19
20
21
# File 'lib/txgh/tx_resource.rb', line 19

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

#slugsObject



27
28
29
# File 'lib/txgh/tx_resource.rb', line 27

def slugs
  [project_slug, resource_slug]
end

#to_api_hObject



42
43
44
45
46
47
48
49
# File 'lib/txgh/tx_resource.rb', line 42

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

#to_hObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/txgh/tx_resource.rb', line 31

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



23
24
25
# File 'lib/txgh/tx_resource.rb', line 23

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