class Samovar::One
Attributes
Public Class Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.3.0/lib/samovar/one.rb, line 8 def initialize(key, description, pattern: //, default: nil, required: false) @key = key @description = description @pattern = pattern @default = default @required = required end
Public Instance Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.3.0/lib/samovar/one.rb, line 38 def parse(input, parent = nil, default = nil) if input.first =~ @pattern input.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/one.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/one.rb, line 22 def to_s "<#{@key}>" end