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
# File 'lib/pi_driver/utils/argument_helper.rb', line 11

def check(type, arg, valid_options)
  valid_options_for_message = valid_options.map { |value| "#{value.inspect}"}.join(', ')
  middle = "invalid argument #{arg.inspect} for #{type.inspect} expected to be one of #{valid_options_for_message}"
  message = "#{@prefix if @prefix} #{middle} #{@suffix if @suffix}"
  raise ArgumentError, message unless valid_options.include?(arg)
end