Skip to content

Commit c4c5869

Browse files
committed
Refactored birthday_helper code for readability
refactored to better utilize CSV::ROWs
1 parent 7cdebda commit c4c5869

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

bin/birthday_helper.rb

+8-6
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
path_to_csv = './bin/birthday_data.csv'
66
end
77

8-
puts "Please type a name"
9-
name = gets.chomp
8+
109

1110
spreadsheet = CSV.read(path_to_csv, headers:true)
11+
place = nil
1212

13-
for x in 0...spreadsheet.length
14-
if spreadsheet[x][0] == name || spreadsheet[x][1] == name || "#{spreadsheet[x][1]} #{spreadsheet[x][0]}" == name
15-
place = x
13+
puts "Please type a name"
14+
name = gets.chomp
15+
spreadsheet.each do |row|
16+
if row["first_name"] == name || row["last_name"] == name || "#{row["first_name"]} #{row["last_name"]}" == name
17+
place =row
1618
end
1719
end
1820

19-
birthday = spreadsheet[place][2].split('/')
21+
birthday = place[2].split('/')
2022
age = 2014 - Integer(birthday[0])
2123

2224
if birthday[1] == "01"

0 commit comments

Comments
 (0)