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
# File 'lib/any2tmx/options.rb', line 7

def initialize(executable_name)
  @options = { targets: [] }
  @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: file, 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[:targets] << { file: file, 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



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

def after_validate
end

#before_validateObject

allow derived classes to add additional validation routines



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

def before_validate
end

#help?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/any2tmx/options.rb', line 57

def help?
  @options[:help]
end

#outputObject



53
54
55
# File 'lib/any2tmx/options.rb', line 53

def output
  @options[:output]
end


61
62
63
# File 'lib/any2tmx/options.rb', line 61

def print_help
  puts @opts
end

#sourceObject



45
46
47
# File 'lib/any2tmx/options.rb', line 45

def source
  @options[:source]
end

#targetsObject



49
50
51
# File 'lib/any2tmx/options.rb', line 49

def targets
  @options[:targets]
end

#valid?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/any2tmx/options.rb', line 39

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