Class: BBLib::OptsParser::Toggle

Inherits:
Option
  • Object
show all
Defined in:
lib/bblib/cli/options/toggle.rb

Direct Known Subclasses

Untoggle

Instance Method Summary collapse

Methods inherited from Option

#flag_match?, #multi_value?, #retrieve, #split, #to_s, types, #valid!, #valid?

Methods included from TypeInit

included

Methods included from Effortless

#_attrs, included

Instance Method Details

#extract(index, args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/bblib/cli/options/toggle.rb', line 5

def extract(index, args)
  value = args[index].to_s
  if value =~ /^\-[\w\d]$|^\-{2}/ || flags.include?(value)
    args[index] = nil
  elsif value =~ /^\-[\w\d]+$/
    flag = flags.find do |flag|
      next unless flag =~ /^\-[\w\d]$/
      value.include?(flag[1])
    end
    args[index] = value.sub(flag[1], '')
  end
  true
end