Created
January 19, 2012 01:43
-
-
Save koriroys/1637069 to your computer and use it in GitHub Desktop.
Tom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require 'csv' | |
def is_suffix? name | |
case name | |
when "Jr" | |
true | |
when "JR" | |
true | |
when "II" | |
true | |
when "III" | |
true | |
when "IV" | |
true | |
else | |
false | |
end | |
end | |
first_names = [] | |
last_names = [] | |
CSV.foreach("doctor.csv", :encoding => "UTF-8") do |row| | |
full_name = row[0] | |
full_name = full_name.split(",").first.split(" ") | |
first_names << full_name[1] | |
last_name_or_suffix = full_name.slice(full_name.length-1) | |
last_name_or_middle_name = full_name.slice(full_name.length-2) | |
is_suffix?(last_name_or_suffix) ? last_names << last_name_or_middle_name : last_names << last_name_or_suffix | |
end | |
puts "FIRST NAMES" | |
puts first_names | |
puts "LAST NAMES" | |
puts last_names |
It's mostly the same as what you did really. Oh yeah, and ruby is smart enough to iterate over an array automatically if you just 'puts array_name'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like how you defined is_suffix?