Class: Kerplutz::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/kerplutz/options.rb

Direct Known Subclasses

Action, Flag, Switch

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, desc) ⇒ Option

Returns a new instance of Option.



12
13
14
15
# File 'lib/kerplutz/options.rb', line 12

def initialize(name, desc)
  @name = name
  @desc = desc
end

Instance Attribute Details

#abbrevObject

Returns the value of attribute abbrev.



4
5
6
# File 'lib/kerplutz/options.rb', line 4

def abbrev
  @abbrev
end

#descObject (readonly)

Returns the value of attribute desc.



3
4
5
# File 'lib/kerplutz/options.rb', line 3

def desc
  @desc
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/kerplutz/options.rb', line 3

def name
  @name
end

Class Method Details

.build(name, desc, opts) ⇒ Object



6
7
8
9
10
# File 'lib/kerplutz/options.rb', line 6

def self.build(name, desc, opts)
  option = self.new(name, desc)
  option.abbrev = opts[:abbrev]
  option
end

Instance Method Details

#abbrev_sigObject



25
26
27
# File 'lib/kerplutz/options.rb', line 25

def abbrev_sig
  return "-#{abbrev[0]}" if abbrev
end

#configure(parser, &blk) ⇒ Object



33
34
35
# File 'lib/kerplutz/options.rb', line 33

def configure(parser, &blk)
  raise "You'll need to implement this one yourself, bub."
end

#display_nameObject



17
18
19
# File 'lib/kerplutz/options.rb', line 17

def display_name
  name.to_s.tr("_", "-")
end

#option_sigObject



21
22
23
# File 'lib/kerplutz/options.rb', line 21

def option_sig
  "--#{display_name}"
end

#parser_argsObject



29
30
31
# File 'lib/kerplutz/options.rb', line 29

def parser_args
  [abbrev_sig, option_sig, desc].compact
end