Class: Poesie::Exporter

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

Instance Method Summary collapse

Constructor Details

#initialize(api_token, project_id) ⇒ Exporter

Returns a new instance of Exporter.

Parameters:

  • api_token (String)

    POEditor API Token

  • project_id (String)

    ID of the project in your POEditor Dashboard



10
11
12
13
# File 'lib/exporter.rb', line 10

def initialize(api_token, project_id)
  @api_token = api_token
  @project_id = project_id
end

Instance Method Details

#run(lang) ⇒ Object

Use the POEditor API to download the terms for a given language, then call a block to post-process those terms (exported as a JSON structure)

Parameters:

  • lang (String)

    The language to export



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/exporter.rb', line 24

def run(lang)
    Log::info(' - Generating export...')
    uri = generate_export_uri(lang)
    Log::info(' - Downloading exported file...')
    json_string = Net::HTTP.get(URI(uri))
    json = JSON.parse(json_string)
    terms = json.sort { |item1, item2| item1['term'] <=> item2['term'] }
    if block_given?
      Log::info(' - Processing generated strings...')
      yield terms
    end
end