Class: CLI::Switches
- Inherits:
-
Array
- Object
- Array
- CLI::Switches
- Defined in:
- lib/cli/switches.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #<<(switch_dsl) ⇒ Object
- #find(arg) ⇒ Object
- #find_long(arg) ⇒ Object
- #find_short(arg) ⇒ Object
- #has_long?(switch_dsl) ⇒ Boolean
- #has_short?(switch_dsl) ⇒ Boolean
-
#initialize ⇒ Switches
constructor
A new instance of Switches.
Constructor Details
#initialize ⇒ Switches
Returns a new instance of Switches.
2 3 4 5 |
# File 'lib/cli/switches.rb', line 2 def initialize @long = {} @short = {} end |
Class Method Details
.is_switch?(arg) ⇒ Boolean
13 14 15 |
# File 'lib/cli/switches.rb', line 13 def self.is_switch?(arg) arg =~ /^-/ end |
Instance Method Details
#<<(switch_dsl) ⇒ Object
7 8 9 10 11 |
# File 'lib/cli/switches.rb', line 7 def <<(switch_dsl) super(switch_dsl) @long[switch_dsl.name] = switch_dsl @short[switch_dsl.short] = switch_dsl if switch_dsl.has_short? end |
#find(arg) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/cli/switches.rb', line 17 def find(arg) if arg =~ /^--/ find_long(arg) else find_short(arg) end end |
#find_long(arg) ⇒ Object
25 26 27 |
# File 'lib/cli/switches.rb', line 25 def find_long(arg) @long[arg.sub(/^--/, '').tr('-', '_').to_sym] end |
#find_short(arg) ⇒ Object
29 30 31 |
# File 'lib/cli/switches.rb', line 29 def find_short(arg) @short[arg.sub(/^-/, '').tr('-', '_').to_sym] end |
#has_long?(switch_dsl) ⇒ Boolean
33 34 35 |
# File 'lib/cli/switches.rb', line 33 def has_long?(switch_dsl) @long.member?(switch_dsl.name) end |
#has_short?(switch_dsl) ⇒ Boolean
37 38 39 |
# File 'lib/cli/switches.rb', line 37 def has_short?(switch_dsl) @short.member?(switch_dsl.short) if switch_dsl.has_short? end |