Class: Whats::Option
- Inherits:
-
Object
- Object
- Whats::Option
- Defined in:
- lib/whats/option.rb
Instance Attribute Summary collapse
-
#choice ⇒ Object
Returns the value of attribute choice.
-
#key ⇒ Object
Returns the value of attribute key.
-
#message ⇒ Object
Returns the value of attribute message.
Instance Method Summary collapse
-
#initialize(args) ⇒ Option
constructor
A new instance of Option.
- #parse ⇒ Object
Constructor Details
#initialize(args) ⇒ Option
Returns a new instance of Option.
7 8 9 |
# File 'lib/whats/option.rb', line 7 def initialize args @args = args end |
Instance Attribute Details
#choice ⇒ Object
Returns the value of attribute choice.
5 6 7 |
# File 'lib/whats/option.rb', line 5 def choice @choice end |
#key ⇒ Object
Returns the value of attribute key.
5 6 7 |
# File 'lib/whats/option.rb', line 5 def key @key end |
#message ⇒ Object
Returns the value of attribute message.
5 6 7 |
# File 'lib/whats/option.rb', line 5 def end |
Instance Method Details
#parse ⇒ Object
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 40 41 42 43 44 |
# File 'lib/whats/option.rb', line 11 def parse if @args[0][0] == "-" OptionParser.new do |opts| opts. = "Usage: whats [options]" opts.on("-a", "--add VAL", "Adds an entry") do |val| @choice = :add @key = val end opts.on("-m", "--message M", String, "Memo's message") do |val| = val end opts.on("-d", "--delete K", String, "Delete a key") do |val| @choice = :delete @key = val end opts.on("-l", "--list", "List all memo keys") do @choice = :list end opts.on("-e", "--execute K", String, "Executes the given key") do |val| @choice = :execute @key = val end end.parse! @args else @choice = :lookup @key = @args[0] end end |