Module: Checker

Included in:
Calcpace
Defined in:
lib/calcpace/checker.rb

Overview

Module to check if the input is valid or of the correct type

Instance Method Summary collapse

Instance Method Details

#check_positive(number) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
# File 'lib/calcpace/checker.rb', line 5

def check_positive(number)
  raise ArgumentError, 'It must be a positive number' unless number.is_a?(Numeric) && number.positive?
end

#check_time(time_string) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
# File 'lib/calcpace/checker.rb', line 9

def check_time(time_string)
  return if time_string =~ /\A\d{1,2}:\d{2}:\d{2}\z/

  raise ArgumentError,
        'It must be a valid time in the format XX:XX:XX'
end