Class: Txgh::TxResource
- Inherits:
-
Object
- Object
- Txgh::TxResource
- Defined in:
- lib/txgh/tx_resource.rb
Instance Attribute Summary collapse
-
#project_slug ⇒ Object
readonly
Returns the value of attribute project_slug.
-
#resource_slug ⇒ Object
(also: #original_resource_slug)
readonly
Returns the value of attribute resource_slug.
-
#source_file ⇒ Object
readonly
Returns the value of attribute source_file.
-
#source_lang ⇒ Object
readonly
Returns the value of attribute source_lang.
-
#translation_file ⇒ Object
readonly
Returns the value of attribute translation_file.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #branch ⇒ Object
-
#initialize(project_slug, resource_slug, type, source_lang, source_file, lang_map, translation_file) ⇒ TxResource
constructor
A new instance of TxResource.
- #L10N_resource_slug ⇒ Object
- #lang_map(tx_lang) ⇒ Object
- #slugs ⇒ Object
- #to_api_h ⇒ Object
- #to_h ⇒ Object
- #translation_path(language) ⇒ Object
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_slug ⇒ Object (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_slug ⇒ Object (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_file ⇒ Object (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_lang ⇒ Object (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_file ⇒ Object (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 |
#type ⇒ Object (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
#branch ⇒ Object
66 67 68 |
# File 'lib/txgh/tx_resource.rb', line 66 def branch nil end |
#L10N_resource_slug ⇒ Object
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 |
#slugs ⇒ Object
42 43 44 |
# File 'lib/txgh/tx_resource.rb', line 42 def slugs [project_slug, resource_slug] end |
#to_api_h ⇒ Object
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_h ⇒ Object
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 |