class Samovar::Split
Attributes
Public Class Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.3.0/lib/samovar/split.rb, line 8 def initialize(key, description, marker: '--', default: nil, required: false) @key = key @description = description @marker = marker @default = default @required = required end
Public Instance Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.3.0/lib/samovar/split.rb, line 38 def parse(input, parent = nil, default = nil) if offset = input.index(@marker) input.pop(input.size - offset).tap(&:shift) elsif default ||= @default return default elsif @required raise MissingValueError.new(parent, self) end end
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.3.0/lib/samovar/split.rb, line 26 def to_a usage = [to_s, @description] if @default usage << "(default: #{@default.inspect})" elsif @required usage << "(required)" end return usage end
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.3.0/lib/samovar/split.rb, line 22 def to_s "#{@marker} <#{@key}...>" end