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
- #source_locale ⇒ Object
- #target ⇒ Object
- #target_locale ⇒ 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 38 39 |
# File 'lib/any2tmx/options.rb', line 7 def initialize(executable_name) = {} @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(':') [:source] = file [: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(':') [:target] = file [: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| [:output] = output end opts.on('-h', '--help', 'Prints this help message.') do [: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
79 80 |
# File 'lib/any2tmx/options.rb', line 79 def after_validate end |
#before_validate ⇒ Object
allow derived classes to add additional validation routines
76 77 |
# File 'lib/any2tmx/options.rb', line 76 def before_validate end |
#help? ⇒ Boolean
67 68 69 |
# File 'lib/any2tmx/options.rb', line 67 def help? [:help] end |
#output ⇒ Object
63 64 65 |
# File 'lib/any2tmx/options.rb', line 63 def output [:output] end |
#print_help ⇒ Object
71 72 73 |
# File 'lib/any2tmx/options.rb', line 71 def print_help puts @opts end |
#source ⇒ Object
47 48 49 |
# File 'lib/any2tmx/options.rb', line 47 def source [:source] end |
#source_locale ⇒ Object
55 56 57 |
# File 'lib/any2tmx/options.rb', line 55 def source_locale [:source_locale] end |
#target ⇒ Object
51 52 53 |
# File 'lib/any2tmx/options.rb', line 51 def target [:target] end |
#target_locale ⇒ Object
59 60 61 |
# File 'lib/any2tmx/options.rb', line 59 def target_locale [:target_locale] end |
#valid? ⇒ Boolean
41 42 43 44 45 |
# File 'lib/any2tmx/options.rb', line 41 def valid? errors.clear validate errors.empty? end |