Skip to content

Instantly share code, notes, and snippets.

@koriroys
Created January 19, 2012 01:43
Show Gist options
  • Save koriroys/1637069 to your computer and use it in GitHub Desktop.
Save koriroys/1637069 to your computer and use it in GitHub Desktop.
Tom
# 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
@koriroys
Copy link
Author

line 35 is a 'ternary operator' if you haven't seen it before.

@tom-brown
Copy link

I like how you defined is_suffix?

@koriroys
Copy link
Author

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