Module: Ubcbooker::CLI::Validator
- Defined in:
- lib/ubcbooker/cli_validator.rb
Class Method Summary collapse
- .is_required_missing(options) ⇒ Object
- .is_valid_date(d) ⇒ Object
- .is_valid_department(d) ⇒ Object
-
.is_valid_name(name) ⇒ Object
False if the name contains any profanity.
- .is_valid_time(t) ⇒ Object
Class Method Details
.is_required_missing(options) ⇒ Object
39 40 41 42 |
# File 'lib/ubcbooker/cli_validator.rb', line 39 def self.is_required_missing() return [:name].nil? || [:date].nil? || [:time].nil? || [:department].nil? end |
.is_valid_date(d) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# 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) ⇒ Object
4 5 6 |
# 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) ⇒ Object
False if the name contains any profanity
45 46 47 |
# File 'lib/ubcbooker/cli_validator.rb', line 45 def self.is_valid_name(name) return !Obscenity.profane?(name) end |
.is_valid_time(t) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 |