Class: Samovar::BooleanFlag
Overview
Represents a boolean flag with ‘–flag` and `–no-flag` variants.
Instance Attribute Summary
Attributes inherited from Flag
Instance Method Summary collapse
-
#initialize(text, prefix, value = nil) ⇒ BooleanFlag
constructor
Initialize a new boolean flag.
-
#parse(input) ⇒ Object
Parse this flag from the input.
-
#prefix?(token) ⇒ Boolean
Check if the token matches this flag.
Methods inherited from Flag
Constructor Details
#initialize(text, prefix, value = nil) ⇒ BooleanFlag
Initialize a new boolean flag.
204 205 206 207 208 209 210 211 |
# File 'lib/samovar/flags.rb', line 204 def initialize(text, prefix, value = nil) super(text, prefix) @value = value @negated = @prefix.sub(/^--/, "--no-") @alternatives = [@negated] end |
Instance Method Details
#parse(input) ⇒ Object
Parse this flag from the input.
225 226 227 228 229 230 231 232 233 |
# File 'lib/samovar/flags.rb', line 225 def parse(input) if input.first == @prefix input.shift return true elsif input.first == @negated input.shift return false end end |
#prefix?(token) ⇒ Boolean
Check if the token matches this flag.
217 218 219 |
# File 'lib/samovar/flags.rb', line 217 def prefix?(token) @prefix == token or @negated == token end |