-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquestion.rb
54 lines (45 loc) · 1.95 KB
/
question.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Purpose: To Ask Questions and validate the Answers
module SmartGoals
class Question
# Ask for a name
def ask_for_name(question)
name = CLI.ask(question) do |q|
# Check if the friend's name is empty
q.validate = Helpers.not_empty?
# Friend name is empty
q.responses[:not_valid] = "\The name cannot be empty. Please enter a valid name.".light_white
end
end
# Ask for an email address
def ask_for_email(question)
email = CLI.ask(question) do |q|
# Check if the friend's email is empty
q.validate = Helpers.valid_email?
# Email is not valid
q.responses[:not_valid] = "\nInvalid email entered. Please enter a valid email. (e.g. [email protected])".light_white
end
end
# Ask for a description
def ask_for_description(question)
description = CLI.ask(question) do |q|
# Check if the description is empty
q.validate = Helpers.not_empty?
# Description is empty
q.responses[:not_valid] = "\nYour description cannot be empty. Please enter a valid description.".light_white
end
end
# Ask for a target date
def ask_for_target_date(question)
target_date = CLI.ask(question) do |q|
# Validate date
q.validate = Helpers.valid_date?
# Date should be a future date
q.responses[:not_valid] = "The date has to be later than today. Please enter a date in the future.".light_white
# Date should be in dd-mm-yyyy format
q.responses[:invalid_type] = "Please enter a valid date in dd-mn-yyyy format.".light_white
end
# Parse the date in dd-mm-yyyy
target_date = Time.strptime(target_date, "%d-%m-%Y")
end
end
end