Class: Any2Tmx::Options
- Inherits:
-
Object
- Object
- Any2Tmx::Options
- Defined in:
- lib/any2tmx/options.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #after_validate ⇒ Object
-
#before_validate ⇒ Object
allow derived classes to add additional validation routines.
- #help? ⇒ Boolean
-
#initialize(executable_name) ⇒ Options
constructor
A new instance of Options.
- #output ⇒ Object
- #print_help ⇒ Object
- #source ⇒ Object
- #targets ⇒ Object
- #valid? ⇒ Boolean
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. = "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
#errors ⇒ Object (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_validate ⇒ Object
69 70 |
# File 'lib/any2tmx/options.rb', line 69 def after_validate end |
#before_validate ⇒ Object
allow derived classes to add additional validation routines
66 67 |
# File 'lib/any2tmx/options.rb', line 66 def before_validate end |
#help? ⇒ Boolean
57 58 59 |
# File 'lib/any2tmx/options.rb', line 57 def help? @options[:help] end |
#output ⇒ Object
53 54 55 |
# File 'lib/any2tmx/options.rb', line 53 def output @options[:output] end |
#print_help ⇒ Object
61 62 63 |
# File 'lib/any2tmx/options.rb', line 61 def print_help puts @opts end |
#source ⇒ Object
45 46 47 |
# File 'lib/any2tmx/options.rb', line 45 def source @options[:source] end |
#targets ⇒ Object
49 50 51 |
# File 'lib/any2tmx/options.rb', line 49 def targets @options[:targets] end |
#valid? ⇒ Boolean
39 40 41 42 43 |
# File 'lib/any2tmx/options.rb', line 39 def valid? errors.clear validate errors.empty? end |