Class: SrtShifter::Options
- Inherits:
-
Object
- Object
- SrtShifter::Options
- Defined in:
- lib/srtshifter/options.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(args) ⇒ Options
constructor
A new instance of Options.
- #parse_options ⇒ Object
- #validate_args ⇒ Object
Constructor Details
#initialize(args) ⇒ Options
Returns a new instance of Options.
8 9 10 11 12 13 14 |
# File 'lib/srtshifter/options.rb', line 8 def initialize(args) @arguments = args @operations = ["ADD", "SUB"] @options = {} end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/srtshifter/options.rb', line 6 def @options end |
Instance Method Details
#parse_options ⇒ 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 41 42 43 44 |
# File 'lib/srtshifter/options.rb', line 16 def @arguments. do |opts| opts. = "Usage: #{File.basename($PROGRAM_NAME)} [OPTIONS] input_file output_file" opts.separator "" opts.separator "Common Options:" opts.on("-o","--operation (ADD|SUB)", String, "Type ADD to increase time or SUB to decrease time.") do |o| @options[:operation] = o.upcase end opts.on("-t","--time (VALUE)", Float, "Time in milliseconds.") do |n| @options[:time] = n end opts.on_tail('-h', '--help', 'Show this help message.') do puts(opts) # exit(0) end opts.on_tail("-v","--version", "Show version") do puts SrtShifter::VERSION exit end opts.parse! end end |
#validate_args ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/srtshifter/options.rb', line 46 def validate_args begin raise "Operation option is missing" if @options[:operation].nil? raise "Unknown operation: #{@options[:operation]}" unless @operations.include? @options[:operation].upcase raise "Time option is missing" if @options[:time].nil? raise "Input file is missing" if @arguments[0].nil? @options[:input] = @arguments[0] raise "Output file is missing" if @arguments[1].nil? @options[:output] = @arguments[1] rescue Exception => ex puts "#{ex.}. Please use -h or --help for usage." # exit(1) end end |