Class: PiDriver::Utils::ArgumentHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/pi_driver/utils/argument_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ArgumentHelper

Returns a new instance of ArgumentHelper.



6
7
8
9
# File 'lib/pi_driver/utils/argument_helper.rb', line 6

def initialize(options = {})
  @prefix = options[:prefix]
  @suffix = options[:suffix]
end

Instance Attribute Details

#prefixObject

Returns the value of attribute prefix.



4
5
6
# File 'lib/pi_driver/utils/argument_helper.rb', line 4

def prefix
  @prefix
end

#suffixObject

Returns the value of attribute suffix.



4
5
6
# File 'lib/pi_driver/utils/argument_helper.rb', line 4

def suffix
  @suffix
end

Instance Method Details

#check(type, arg, valid_options) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
# File 'lib/pi_driver/utils/argument_helper.rb', line 11

def check(type, arg, valid_options)
  return if valid_options.include?(arg)
  options = valid_options.map(&:to_s).join(', ')
  middle = "invalid argument for #{type.inspect}, "
  middle += "#{arg.inspect} was given but expected to be one of #{options}"
  message = "#{@prefix if @prefix} #{middle} #{@suffix if @suffix}"
  raise ArgumentError, message
end