Class: POEditor::Configuration
- Inherits:
-
Object
- Object
- POEditor::Configuration
- Defined in:
- lib/poeditor/configuration.rb
Instance Attribute Summary collapse
-
#api_key ⇒ String
POEditor API key.
-
#filters ⇒ Array<String>
Filters by ‘translated’, ‘untranslated’, ‘fuzzy’, ‘not_fuzzy’, ‘automatic’, ‘not_automatic’, ‘proofread’, ‘not_proofread’ (optional).
-
#language_alias ⇒ Hash{Sting => String}
The languages aliases.
-
#languages ⇒ Array<String>
The languages codes.
-
#path ⇒ String
The path template.
-
#path_replace ⇒ Hash{Sting => String}
The path replacements.
-
#project_id ⇒ String
POEditor project ID.
-
#tags ⇒ Array<String>
Tag filters (optional).
-
#type ⇒ String
Export file type (po, apple_strings, android_strings).
Instance Method Summary collapse
- #from_env(value) ⇒ Object
-
#initialize(api_key:, project_id:, type:, tags: nil, filters: nil, languages:, language_alias: nil, path:, path_replace: nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #to_s ⇒ Object
Constructor Details
#initialize(api_key:, project_id:, type:, tags: nil, filters: nil, languages:, language_alias: nil, path:, path_replace: nil) ⇒ Configuration
Returns a new instance of Configuration.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/poeditor/configuration.rb', line 31 def initialize(api_key:, project_id:, type:, tags:nil, filters:nil, languages:, language_alias:nil, path:, path_replace:nil) @api_key = from_env(api_key) @project_id = from_env(project_id.to_s) @type = type = || [] @filters = filters || [] @languages = languages @language_alias = language_alias || {} @path = path @path_replace = path_replace || {} end |
Instance Attribute Details
#api_key ⇒ String
Returns POEditor API key.
5 6 7 |
# File 'lib/poeditor/configuration.rb', line 5 def api_key @api_key end |
#filters ⇒ Array<String>
Returns Filters by ‘translated’, ‘untranslated’, ‘fuzzy’, ‘not_fuzzy’, ‘automatic’, ‘not_automatic’, ‘proofread’, ‘not_proofread’ (optional).
17 18 19 |
# File 'lib/poeditor/configuration.rb', line 17 def filters @filters end |
#language_alias ⇒ Hash{Sting => String}
Returns The languages aliases.
23 24 25 |
# File 'lib/poeditor/configuration.rb', line 23 def language_alias @language_alias end |
#languages ⇒ Array<String>
Returns The languages codes.
20 21 22 |
# File 'lib/poeditor/configuration.rb', line 20 def languages @languages end |
#path ⇒ String
Returns The path template.
26 27 28 |
# File 'lib/poeditor/configuration.rb', line 26 def path @path end |
#path_replace ⇒ Hash{Sting => String}
Returns The path replacements.
29 30 31 |
# File 'lib/poeditor/configuration.rb', line 29 def path_replace @path_replace end |
#project_id ⇒ String
Returns POEditor project ID.
8 9 10 |
# File 'lib/poeditor/configuration.rb', line 8 def project_id @project_id end |
#tags ⇒ Array<String>
Returns Tag filters (optional).
14 15 16 |
# File 'lib/poeditor/configuration.rb', line 14 def end |
#type ⇒ String
Returns Export file type (po, apple_strings, android_strings).
11 12 13 |
# File 'lib/poeditor/configuration.rb', line 11 def type @type end |
Instance Method Details
#from_env(value) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/poeditor/configuration.rb', line 47 def from_env(value) if value.start_with?("$") key = value[1..-1] ENV[key] else value end end |
#to_s ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/poeditor/configuration.rb', line 56 def to_s values = { "type" => self.type, "tags" => self., "filters" => self.filters, "languages" => self.languages, "language_alias" => self.language_alias, "path" => self.path, "path_replace" => self.path_replace, } YAML.dump(values)[4..-2] .each_line .map { |line| if line.start_with?("-") or line.start_with?(" ") " #{line}" else " - #{line}" end } .join("") end |