Class: Whats::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/whats/option.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#choiceObject

Returns the value of attribute choice.



5
6
7
# File 'lib/whats/option.rb', line 5

def choice
  @choice
end

#keyObject

Returns the value of attribute key.



5
6
7
# File 'lib/whats/option.rb', line 5

def key
  @key
end

#messageObject

Returns the value of attribute message.



5
6
7
# File 'lib/whats/option.rb', line 5

def message
  @message
end

Instance Method Details

#parseObject



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.banner = "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|
        @message = 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