Class: OptionGrouper::Group
- Inherits:
-
Object
- Object
- OptionGrouper::Group
- Includes:
- Blockenspiel::DSL
- Defined in:
- lib/optiongrouper.rb
Overview
A Group contains some parameters
Instance Method Summary collapse
- #header(*args) ⇒ Object
-
#initialize(name) ⇒ Group
constructor
Initialize a new group.
-
#invoke(&blk) ⇒ Object
Invoke Group in a block to configure.
-
#long(*args) ⇒ Object
Defines the name used in command line.
-
#opt(name, desc, opts = {}) ⇒ void
Define a new option.
Constructor Details
#initialize(name) ⇒ Group
Initialize a new group
15 16 17 18 19 |
# File 'lib/optiongrouper.rb', line 15 def initialize name @name = name @long = name.to_s.gsub(/_/, '-') @opts = {} end |
Instance Method Details
#header ⇒ String #header(str) ⇒ String
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/optiongrouper.rb', line 76 def header *args if args.size == 0 if @header "#{@header} (#{@long}):" else "#{@long}:" end else @header = args[0] end end |
#invoke(&blk) ⇒ Object
Invoke Group in a block to configure
22 23 24 |
# File 'lib/optiongrouper.rb', line 22 def invoke &blk Blockenspiel.invoke blk, self end |
#long ⇒ String #long(str) ⇒ String
Defines the name used in command line. By default it's the normal name with underscores replaced with hyphens. It's not advised to change it.
61 62 63 64 65 66 67 |
# File 'lib/optiongrouper.rb', line 61 def long *args if args.size == 0 @long else @long = args[0] end end |
#opt(name, desc, opts = {}) ⇒ void
This method returns an undefined value.
Define a new option
46 47 48 49 50 51 |
# File 'lib/optiongrouper.rb', line 46 def opt name, desc, opts = {} opts[:desc] = desc opts[:long] ||= name.to_s.gsub(/_/, '-') opts[:set] ||= true @opts[name] = opts end |