Class: Samovar::ValueFlag
Instance Attribute Summary collapse
-
#alternatives ⇒ Object
readonly
Returns the value of attribute alternatives.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from Flag
Instance Method Summary collapse
- #boolean? ⇒ Boolean
-
#initialize(text, prefix, value) ⇒ ValueFlag
constructor
A new instance of ValueFlag.
- #parse(input) ⇒ Object
- #prefix?(token) ⇒ Boolean
Methods inherited from Flag
Constructor Details
#initialize(text, prefix, value) ⇒ ValueFlag
Returns a new instance of ValueFlag.
82 83 84 85 86 87 88 |
# File 'lib/samovar/flags.rb', line 82 def initialize(text, prefix, value) super(text, prefix) @value = value *@alternatives, @prefix = @prefix.split('/') end |
Instance Attribute Details
#alternatives ⇒ Object (readonly)
Returns the value of attribute alternatives.
90 91 92 |
# File 'lib/samovar/flags.rb', line 90 def alternatives @alternatives end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
91 92 93 |
# File 'lib/samovar/flags.rb', line 91 def value @value end |
Instance Method Details
#boolean? ⇒ Boolean
93 94 95 |
# File 'lib/samovar/flags.rb', line 93 def boolean? @value.nil? end |
#parse(input) ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/samovar/flags.rb', line 101 def parse(input) if prefix?(input.first) if @value return input.shift(2).last else input.shift return key end end end |
#prefix?(token) ⇒ Boolean
97 98 99 |
# File 'lib/samovar/flags.rb', line 97 def prefix?(token) @prefix == token or @alternatives.include?(token) end |