Skip to content

Commit cd4983d

Browse files
committed
Returns birthday & age for first or last name input
1 parent ec0fb33 commit cd4983d

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

bin/birthday_helper.rb

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
require 'csv'
2+
3+
path_to_csv = '../../bin/birthday_data.csv'
4+
if ENV['DEV']
5+
path_to_csv = './bin/birthday_data.csv'
6+
end
7+
8+
puts "Please type a name"
9+
name = gets.chomp.capitalize
10+
11+
spreadsheet = CSV.read(path_to_csv, headers:true)
12+
13+
for x in 0...spreadsheet.length
14+
if spreadsheet[x][0] == name || spreadsheet[x][1] == name
15+
place = x
16+
end
17+
end
18+
19+
birthday = spreadsheet[place][2].split('/')
20+
age = 2014 - Integer(birthday[0])
21+
22+
if birthday[1] == "01"
23+
print "January "
24+
elsif birthday[1] == "02"
25+
print "February "
26+
elsif birthday[1] == "03"
27+
print "March "
28+
elsif birthday[1] == "04"
29+
print "April "
30+
elsif birthday[1] == "05"
31+
print "May "
32+
elsif birthday[1] == "06"
33+
print "June "
34+
elsif birthday[1] == "07"
35+
print "July "
36+
elsif birthday[1] == "08"
37+
print "August "
38+
elsif birthday[1] == "09"
39+
print "September "
40+
elsif birthday[1] == "10"
41+
print "October "
42+
elsif birthday[1] == "11"
43+
print "November "
44+
elsif birthday[1] == "12"
45+
print "December "
46+
end
47+
48+
print "#{Integer(birthday[2])}, #{birthday[0]},
49+
#{age} years old"
50+

spec/birthday_helper_spec.rb

-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
describe "BirthdayHelper" do
44
it "returns the birth date and age of the first name typed in" do
5-
pending
65
run_script("birthday_helper.rb")
76
type("Mike")
87

@@ -13,7 +12,6 @@
1312
end
1413

1514
it "returns the birth date and age of the last name typed in" do
16-
pending
1715
run_script("birthday_helper.rb")
1816
type("Dean")
1917

0 commit comments

Comments
 (0)