Class: Samovar::Many
- Inherits:
-
Object
- Object
- Samovar::Many
- Defined in:
- lib/samovar/many.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(key, description, stop: /^-/, default: nil) ⇒ Many
constructor
A new instance of Many.
- #parse(input, default = @default) ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(key, description, stop: /^-/, default: nil) ⇒ Many
Returns a new instance of Many.
23 24 25 26 27 28 |
# File 'lib/samovar/many.rb', line 23 def initialize(key, description, stop: /^-/, default: nil) @key = key @description = description @stop = stop @default = default end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
30 31 32 |
# File 'lib/samovar/many.rb', line 30 def key @key end |
Instance Method Details
#parse(input, default = @default) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/samovar/many.rb', line 46 def parse(input, default = @default) if @stop and stop_index = input.index{|item| @stop === item} input.shift(stop_index) else input.shift(input.size) end || default end |
#to_a ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/samovar/many.rb', line 36 def to_a usage = [to_s, @description] if @default usage << "Default: #{@default.inspect}" end return usage end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/samovar/many.rb', line 32 def to_s "<#{key}...>" end |