Class: POEditor::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/poeditor/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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
  @tags = tags || []
  @filters = filters || []

  @languages = languages
  @language_alias = language_alias || {}

  @path = path
  @path_replace = path_replace || {}
end

Instance Attribute Details

#api_keyString

Returns POEditor API key.

Returns:

  • (String)

    POEditor API key

See Also:



5
6
7
# File 'lib/poeditor/configuration.rb', line 5

def api_key
  @api_key
end

#filtersArray<String>

Returns Filters by ‘translated’, ‘untranslated’, ‘fuzzy’, ‘not_fuzzy’, ‘automatic’, ‘not_automatic’, ‘proofread’, ‘not_proofread’ (optional).

Returns:

  • (Array<String>)

    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_aliasHash{Sting => String}

Returns The languages aliases.

Returns:

  • (Hash{Sting => String})

    The languages aliases



23
24
25
# File 'lib/poeditor/configuration.rb', line 23

def language_alias
  @language_alias
end

#languagesArray<String>

Returns The languages codes.

Returns:

  • (Array<String>)

    The languages codes



20
21
22
# File 'lib/poeditor/configuration.rb', line 20

def languages
  @languages
end

#pathString

Returns The path template.

Returns:

  • (String)

    The path template



26
27
28
# File 'lib/poeditor/configuration.rb', line 26

def path
  @path
end

#path_replaceHash{Sting => String}

Returns The path replacements.

Returns:

  • (Hash{Sting => String})

    The path replacements



29
30
31
# File 'lib/poeditor/configuration.rb', line 29

def path_replace
  @path_replace
end

#project_idString

Returns POEditor project ID.

Returns:

  • (String)

    POEditor project ID



8
9
10
# File 'lib/poeditor/configuration.rb', line 8

def project_id
  @project_id
end

#tagsArray<String>

Returns Tag filters (optional).

Returns:

  • (Array<String>)

    Tag filters (optional)



14
15
16
# File 'lib/poeditor/configuration.rb', line 14

def tags
  @tags
end

#typeString

Returns Export file type (po, apple_strings, android_strings).

Returns:

  • (String)

    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_sObject



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.tags,
    "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