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: '--') ⇒ Split
constructor
A new instance of Split.
- #parse(input) ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(key, description, marker: '--') ⇒ Split
Returns a new instance of Split.
23 24 25 26 27 |
# File 'lib/samovar/split.rb', line 23 def initialize(key, description, marker: '--') @key = key @description = description @marker = marker end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
29 30 31 |
# File 'lib/samovar/split.rb', line 29 def key @key end |
Instance Method Details
#parse(input) ⇒ Object
39 40 41 42 43 |
# File 'lib/samovar/split.rb', line 39 def parse(input) if offset = input.index(@marker) input.pop(input.size - offset).tap(&:shift) end end |
#to_a ⇒ Object
35 36 37 |
# File 'lib/samovar/split.rb', line 35 def to_a [to_s, @description] end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/samovar/split.rb', line 31 def to_s "#{@marker} <#{@key}...>" end |