Class: Any2Tmx::Options

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(executable_name) ⇒ Options

Returns a new instance of Options.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/any2tmx/options.rb', line 7

def initialize(executable_name)
  @options = {}
  @errors = []

  OptionParser.new do |opts|
    opts.banner = "Usage: #{executable_name} [options]"

    opts.on('-s', '--source [file]:[locale]', 'File containing phrases in the source locale (locale appended with colon).') do |source|
      file, locale = source.split(':')
      @options[:source] = file
      @options[:source_locale] = locale
    end

    opts.on('-t', '--target [file]:[locale]', 'File containing translations in the target locale (locale appended with colon).') do |target|
      file, locale = target.split(':')
      @options[:target] = file
      @options[:target_locale] = locale
    end

    opts.on('-o', '--output [file]', 'The TMX output file to write. If not specified, output is printed to stdout.') do |output|
      @options[:output] = output
    end

    opts.on('-h', '--help', 'Prints this help message.') do
      @options[:help] = true
    end

    @opts = opts

    # give derived classes the opportunity to add additional options
    yield opts if block_given?
  end.parse!
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/any2tmx/options.rb', line 5

def errors
  @errors
end

Instance Method Details

#after_validateObject



79
80
# File 'lib/any2tmx/options.rb', line 79

def after_validate
end

#before_validateObject

allow derived classes to add additional validation routines



76
77
# File 'lib/any2tmx/options.rb', line 76

def before_validate
end

#help?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/any2tmx/options.rb', line 67

def help?
  @options[:help]
end

#outputObject



63
64
65
# File 'lib/any2tmx/options.rb', line 63

def output
  @options[:output]
end


71
72
73
# File 'lib/any2tmx/options.rb', line 71

def print_help
  puts @opts
end

#sourceObject



47
48
49
# File 'lib/any2tmx/options.rb', line 47

def source
  @options[:source]
end

#source_localeObject



55
56
57
# File 'lib/any2tmx/options.rb', line 55

def source_locale
  @options[:source_locale]
end

#targetObject



51
52
53
# File 'lib/any2tmx/options.rb', line 51

def target
  @options[:target]
end

#target_localeObject



59
60
61
# File 'lib/any2tmx/options.rb', line 59

def target_locale
  @options[:target_locale]
end

#valid?Boolean

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/any2tmx/options.rb', line 41

def valid?
  errors.clear
  validate
  errors.empty?
end