Class: Emendate::Translator

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(processed) ⇒ Translator

Returns a new instance of Translator.

Parameters:

  • processed (Emendate::ProcessingManager)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/emendate/translator.rb', line 17

def initialize(processed)
  @dialect = Emendate.options.dialect
  unless dialect
    puts "ERROR: You must pass in a `dialect` option when using `translate`"
    exit
  end
  extend dialect_module.constantize
  @processed = processed

  @translation = Translation.new(pm: processed)
end

Class Method Details

.callObject



11
12
13
# File 'lib/emendate/translator.rb', line 11

def call(...)
  new(...).call
end

Instance Method Details

#callObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/emendate/translator.rb', line 29

def call
  if processed.state == :final_check_failure
    return translate_failure(processed)
  end

  dates_to_map(processed.result.dates)
    .map { |pdate| translate_date(pdate) }
    .each { |result| translation.add_value(result) }

  translation
end