Class: Samovar::Flag
- Inherits:
-
Object
- Object
- Samovar::Flag
- Defined in:
- lib/samovar/flags.rb
Instance Attribute Summary collapse
-
#alternatives ⇒ Object
readonly
Returns the value of attribute alternatives.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(text) ⇒ Flag
constructor
A new instance of Flag.
- #key ⇒ Object
- #parse(input) ⇒ Object
- #prefix?(token) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(text) ⇒ Flag
Returns a new instance of Flag.
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/samovar/flags.rb', line 62 def initialize(text) @text = text if text =~ /(.*?)\s(\<.*?\>)/ @prefix = $1 @value = $2 else @prefix = @text end *@alternatives, @prefix = @prefix.split('/') end |
Instance Attribute Details
#alternatives ⇒ Object (readonly)
Returns the value of attribute alternatives.
77 78 79 |
# File 'lib/samovar/flags.rb', line 77 def alternatives @alternatives end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
76 77 78 |
# File 'lib/samovar/flags.rb', line 76 def prefix @prefix end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
75 76 77 |
# File 'lib/samovar/flags.rb', line 75 def text @text end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
78 79 80 |
# File 'lib/samovar/flags.rb', line 78 def value @value end |
Instance Method Details
#key ⇒ Object
88 89 90 |
# File 'lib/samovar/flags.rb', line 88 def key @key ||= @prefix.sub(/^-*/, '').gsub('-', '_').to_sym end |
#parse(input) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/samovar/flags.rb', line 92 def parse(input) if prefix?(input.first) if @value input.shift(2).last else input.shift; key end end end |
#prefix?(token) ⇒ Boolean
84 85 86 |
# File 'lib/samovar/flags.rb', line 84 def prefix?(token) @prefix == token or @alternatives.include?(token) end |
#to_s ⇒ Object
80 81 82 |
# File 'lib/samovar/flags.rb', line 80 def to_s @text end |