Class: Samovar::One

Inherits:
Object
  • Object
show all
Defined in:
lib/samovar/one.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, description, pattern: //, default: nil) ⇒ One

Returns a new instance of One.



23
24
25
26
27
28
# File 'lib/samovar/one.rb', line 23

def initialize(key, description, pattern: //, default: nil)
  @key = key
  @description = description
  @pattern = pattern
  @default = default
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



30
31
32
# File 'lib/samovar/one.rb', line 30

def key
  @key
end

Instance Method Details

#parse(input, default = @default) ⇒ Object



46
47
48
49
50
# File 'lib/samovar/one.rb', line 46

def parse(input, default = @default)
  if input.first =~ @pattern
    input.shift
  end || default
end

#to_aObject



36
37
38
39
40
41
42
43
44
# File 'lib/samovar/one.rb', line 36

def to_a
  usage = [to_s, @description]
  
  if @default
    usage << "Default: #{@default.inspect}"
  end
  
  return usage
end

#to_sObject



32
33
34
# File 'lib/samovar/one.rb', line 32

def to_s
  "<#{@key}>"
end