Module: CommandTranslate

Defined in:
lib/command_translate.rb,
lib/command_translate/logger.rb,
lib/command_translate/version.rb

Defined Under Namespace

Modules: Logger

Constant Summary collapse

VERSION =
'0.0.2'

Class Method Summary collapse

Class Method Details

.helpObject



32
33
34
# File 'lib/command_translate.rb', line 32

def self.help
  instructions
end

.instructionsObject



26
27
28
29
30
# File 'lib/command_translate.rb', line 26

def self.instructions
  Logger.info "Translator command line"
  Logger.info "To use just run: translate from:to text"
  Logger.info "e.g.: translate en:es \"My dog is crazy\""
end

.languagesObject



36
37
38
39
40
# File 'lib/command_translate.rb', line 36

def self.languages
  rows = LANGUAGES.collect {|k,v| [v, k] }
  languages_table = Terminal::Table.new :headings => ['Language', 'Symbol'], :rows => rows
  Logger.info languages_table
end

.translateObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/command_translate.rb', line 9

def self.translate
  options = ARGV
  begin
    from, to = options.shift.split(":")
    if validate_languages(from, to)
      text = options.join(" ")
      Logger.print("Translating: #{text} (#{LANGUAGES[from.to_sym]} to #{LANGUAGES[to.to_sym]})")
      result = Translation.new(text, from, to).translation
      Logger.print(result)
    else
      Logger.info "Invalid language(s)! View all supported languages typing 'translate languages'."
    end
  rescue Exception => e
    instructions
  end
end

.validate_languages(from, to) ⇒ Object



42
43
44
# File 'lib/command_translate.rb', line 42

def self.validate_languages(from, to)
  LANGUAGES.has_key?(from.to_sym) && LANGUAGES.has_key?(to.to_sym)
end