Class: AfterNotifier::OptionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/after_notifier/option_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ OptionParser

Returns a new instance of OptionParser.

Raises:



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/after_notifier/option_parser.rb', line 9

def initialize(argv)
  @pid = argv.shift
  @terminal_notifier_options = argv

  raise OptionParseError, 'Required PID' unless valid_pid?

  # When unset -message option, set default message.
  unless @terminal_notifier_options.include?("-message")
    @terminal_notifier_options.push(*["-message", "AFTER_NOTIFIER"])
  end
end

Instance Attribute Details

#pidObject (readonly)

Returns the value of attribute pid.



7
8
9
# File 'lib/after_notifier/option_parser.rb', line 7

def pid
  @pid
end

#terminal_notifier_optionsObject (readonly)

Returns the value of attribute terminal_notifier_options.



7
8
9
# File 'lib/after_notifier/option_parser.rb', line 7

def terminal_notifier_options
  @terminal_notifier_options
end

Instance Method Details

#valid_pid?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/after_notifier/option_parser.rb', line 21

def valid_pid?
  # PID is number above 0.
  @pid.to_i > 0
end