Class: Samovar::BooleanFlag

Inherits:
Flag
  • Object
show all
Defined in:
lib/samovar/flags.rb

Instance Attribute Summary

Attributes inherited from Flag

#alternatives, #prefix, #text

Instance Method Summary collapse

Methods inherited from Flag

#boolean?, #key, parse, #to_s

Constructor Details

#initialize(text, prefix, value = nil) ⇒ BooleanFlag

Returns a new instance of BooleanFlag.



114
115
116
117
118
119
120
121
# File 'lib/samovar/flags.rb', line 114

def initialize(text, prefix, value = nil)
  super(text, prefix)
  
  @value = value
  
  @negated = @prefix.sub(/^--/, '--no-')
  @alternatives = [@negated]
end

Instance Method Details

#parse(input) ⇒ Object



127
128
129
130
131
132
133
134
135
# File 'lib/samovar/flags.rb', line 127

def parse(input)
  if input.first == @prefix
    input.shift
    return true
  elsif input.first == @negated
    input.shift
    return false
  end
end

#prefix?(token) ⇒ Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/samovar/flags.rb', line 123

def prefix?(token)
  @prefix == token or @negated == token
end