module Ubcbooker::CLI::Validator
Public Class Methods
is_required_missing(options)
click to toggle source
# File lib/ubcbooker/cli_validator.rb, line 39 def self.is_required_missing(options) return options[:name].nil? || options[:date].nil? || options[:time].nil? || options[:department].nil? end
is_valid_date(d)
click to toggle source
# File lib/ubcbooker/cli_validator.rb, line 8 def self.is_valid_date(d) date = nil begin date = Date.parse(d) # Expect MM/DD rescue ArgumentError return false end return /^\d\d\/\d\d$/.match?(d) && # Match format date.weekday? && # Not on weekend !date.past? && # Not in the past (date < Date.today + 7) # Within a week end
is_valid_department(d)
click to toggle source
# File lib/ubcbooker/cli_validator.rb, line 4 def self.is_valid_department(d) return BOOKING_URL.keys.include?(d.to_sym) end
is_valid_name(name)
click to toggle source
False if the name contains any profanity
# File lib/ubcbooker/cli_validator.rb, line 45 def self.is_valid_name(name) return !Obscenity.profane?(name) end
is_valid_time(t)
click to toggle source
# File lib/ubcbooker/cli_validator.rb, line 22 def self.is_valid_time(t) if /^\d\d:\d\d-\d\d:\d\d$/.match?(t) times = t.split("-") times.each do |time| begin DateTime.parse(time) # Expect HH:MM rescue ArgumentError return false end end return true else return false end end