Class: OptParseBuilder::RequiredOperandArgument

Inherits:
Argument
  • Object
show all
Includes:
FormatsOperandName, HasValue
Defined in:
lib/opt_parse_builder/required_operand_argument.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes included from HasValue

#key, #value

Instance Method Summary collapse

Methods included from HasValue

#init_value, #reset

Methods included from FormatsOperandName

#format_operand_name

Methods inherited from Argument

#apply_option, #banner_lines, #footer_lines, #key, #reset, #separator_lines, #to_a, #value, #value=

Constructor Details

#initialize(key, default, help_name) ⇒ RequiredOperandArgument

Returns a new instance of RequiredOperandArgument.



7
8
9
10
# File 'lib/opt_parse_builder/required_operand_argument.rb', line 7

def initialize(key, default, help_name)
  init_value(key, default)
  @help_name = help_name || key
end

Instance Method Details

#operand_notationObject



12
13
14
# File 'lib/opt_parse_builder/required_operand_argument.rb', line 12

def operand_notation
  "<#{format_operand_name(@help_name)}>"
end

#optionalObject



23
24
25
# File 'lib/opt_parse_builder/required_operand_argument.rb', line 23

def optional
  OptionalOperandArgument.new(@key, @default, @help_name)
end

#requiredObject



27
28
29
# File 'lib/opt_parse_builder/required_operand_argument.rb', line 27

def required
  self
end

#shift_operand(argv) ⇒ Object



16
17
18
19
20
21
# File 'lib/opt_parse_builder/required_operand_argument.rb', line 16

def shift_operand(argv)
  @value = argv.shift
  unless @value
    raise OptionParser::MissingArgument, operand_notation
  end
end