Class: Samovar::Split
- Inherits:
-
Object
- Object
- Samovar::Split
- Defined in:
- lib/samovar/split.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(key, description, marker: '--', default: nil) ⇒ Split
constructor
A new instance of Split.
- #parse(input, default = @default) ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(key, description, marker: '--', default: nil) ⇒ Split
Returns a new instance of Split.
23 24 25 26 27 28 |
# File 'lib/samovar/split.rb', line 23 def initialize(key, description, marker: '--', default: nil) @key = key @description = description @marker = marker @default = default end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
30 31 32 |
# File 'lib/samovar/split.rb', line 30 def key @key end |
Instance Method Details
#parse(input, default = @default) ⇒ Object
46 47 48 49 50 |
# File 'lib/samovar/split.rb', line 46 def parse(input, default = @default) if offset = input.index(@marker) input.pop(input.size - offset).tap(&:shift) end || default end |
#to_a ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/samovar/split.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/split.rb', line 32 def to_s "#{@marker} <#{@key}...>" end |