-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumerology_refactored.rb
74 lines (61 loc) · 3.68 KB
/
numerology_refactored.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Numerology App
# the numbers below are out of order because it's good practice to first define the methods you need
# and then to actually create the script that uses the methods
# this method accepts the birthdate as an argument and adds all the numbers together;
# the result is the return value
def add_birthdate(birthdate)
birthdate[0].to_i + birthdate[1].to_i + birthdate[2].to_i + birthdate[3].to_i + birthdate[4].to_i + birthdate[5].to_i + birthdate[6].to_i + birthdate[7].to_i
end
# this method reduces the birth path down to a single digit
# the return value is the single-digit birth path number
def reduce_num(number)
number = number.to_s
number = number[0].to_i + number[1].to_i
if number > 9
number = number.to_s
number = number[0].to_i + number[1].to_i
end
return number
end
# this method accepts the birthdate as an argument and determines the birth path number;
# the birth path number is the return value
def get_birth_path_num(birthdate)
number = add_birthdate(birthdate)
number = reduce_num(number)
end
# this method accepts the birth path number as an argument and determines the correct message;
# the message is the return value
def get_message(birth_path_num)
# use a case statement to display the correct meaning
case birth_path_num
when 1
message = "Your numerology number is #{birth_path_num}.\nOne is the leader. The number one indicates the ability to stand alone, and is a strong vibration. Ruled by the Sun."
when 2
message = "Your numerology number is #{birth_path_num}.\nThis is the mediator and peace-lover. The number two indicates the desire for harmony. It is a gentle, considerate, and sensitive vibration. Ruled by the Moon."
when 3
message = "Your numerology number is #{birth_path_num}.\nNumber Three is a sociable, friendly, and outgoing vibration. Kind, positive, and optimistic, Three's enjoy life and have a good sense of humor. Ruled by Jupiter."
when 4
message = "Your numerology number is #{birth_path_num}.\nThis is the worker. Practical, with a love of detail, Fours are trustworthy, hard-working, and helpful. Ruled by Uranus."
when 5
message = "Your numerology number is #{birth_path_num}.\nThis is the freedom lover. The number five is an intellectual vibration. These are 'idea' people with a love of variety and the ability to adapt to most situations. Ruled by Mercury."
when 6
message = "Your numerology number is #{birth_path_num}.\nThis is the peace lover. The number six is a loving, stable, and harmonious vibration. Ruled by Venus."
when 7
message = "Your numerology number is #{birth_path_num}.\nThis is the deep thinker. The number seven is a spiritual vibration. These people are not very attached to material things, are introspective, and generally quiet. Ruled by Neptune."
when 8
message = "Your numerology number is #{birth_path_num}.\nThis is the manager. Number Eight is a strong, successful, and material vibration. Ruled by Saturn."
when 9
message = "Your numerology number is #{birth_path_num}.\nThis is the teacher. Number Nine is a tolerant, somewhat impractical, and sympathetic vibration. Ruled by Mars."
else
message = "Uh oh! Your birth path number is not 1-9!"
end
end
# ask the user for their birthdate & assign response to variable
puts "What is your birthdate? Please write it like this: MMDDYYYY"
birthdate = gets
# get birth path number using the method & assign to variable
birth_path_num = get_birth_path_num(birthdate)
# get the correct message using the method & assign to variable
message = get_message(birth_path_num)
# display the number and message to the user
puts message