Class: L43::OptParser::Keyword

Inherits:
Object
  • Object
show all
Defined in:
lib/l43/opt_parser/keyword.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#initializerObject (readonly)

Returns the value of attribute initializer.



6
7
8
# File 'lib/l43/opt_parser/keyword.rb', line 6

def initializer
  @initializer
end

#multipleObject (readonly)

Returns the value of attribute multiple.



6
7
8
# File 'lib/l43/opt_parser/keyword.rb', line 6

def multiple
  @multiple
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/l43/opt_parser/keyword.rb', line 6

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/l43/opt_parser/keyword.rb', line 6

def type
  @type
end

Instance Method Details

#on_multiple(&blk) ⇒ Object



8
9
10
11
# File 'lib/l43/opt_parser/keyword.rb', line 8

def on_multiple(&blk)
  @on_multiple = blk
  self
end

#update(value, old_value) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/l43/opt_parser/keyword.rb', line 13

def update(value, old_value)
  if old_value && !multiple
    [:error, "keyword #{name} has already been specified but is not a multiple keyword"]
  elsif old_value
    value = make_value(value)
    [:ok, @on_multiple.(old_value, value)]
  elsif multiple
    [:ok, [make_value(value)]]
  else
    [:ok, make_value(value)]
  end
end