Module: YamlTranslate

Defined in:
lib/yaml_translate.rb,
lib/yaml_translate/version.rb

Defined Under Namespace

Classes: Translator

Constant Summary collapse

VERSION =
"0.1"
@@defaults =
{
    #:from => 'en',
    #:to => 'es',
    #:verbose => false,
    #:file => nil
}

Class Method Summary collapse

Class Method Details

.parse!(arguments = ARGV, defaults = @@defaults) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/yaml_translate.rb', line 16

def parse! arguments=ARGV, defaults=@@defaults
  @@defaults.dup.tap do |options|
    OptionParser.new do |parser|
      parser.banner = 'Usage: yaml_translate [options]'
      parser.version = YamlTranslate::VERSION

      parser.on('-lf', '--from LANG', 'Set the language to translate from') do |from|
        options[:from] = from
      end

      parser.on('-lt', '--to LANG1,LANG2,...', Array, 'Set the language(s) to translate to') do |to|
        options[:to] = to
      end

      parser.on('-f', '--file FILE', 'Specify the yaml-file to translate') do |file|
        options[:file] = file
      end

      parser.on_tail('-h', '--help', 'Display this help information') do
        puts parser
        exit!
      end
    end.parse!
  end
end

.run!(options = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/yaml_translate.rb', line 42

def run! options=nil
  options &&= @@defaults.merge options
  options ||= parse!

  # TODO: bail out on missing options

  puts "Starting YamlTranslate\n"
  Translator.new(options[:from], options[:to], options[:file]).translate!
end