I am not yet a big friend of reegxp… and I don’t actually know if I
should use it or any other function
but I’d like to know the easiest path to do the following :
I get a string person = 'Clara Mint" which is a full name
and I would like to find the object “id” in a collection using this
full name :
people = [ [“id” => “1”, “first” => “Jack”, “last” => “Johnson”], [“id”
=> “2”, “first” => “Ben”, “last” => “Kenneth”], [“id” => “3”, “first”
=> “Ken”, “last” => “Olsen”], [“id” => “4”, “first” => “Howard”, “last”
=> “Wong”], [“id” => “5”, “first” => “Clara”, “last” => “Mint”], [“id”
=> “7”, “first” => “Che”, “last” => “Guevara”]]
any hint to start ?
Joss
Josselin wrote:
“Ken”, “last” => “Olsen”], [“id” => “4”, “first” => “Howard”, “last” =>
“Wong”], [“id” => “5”, “first” => “Clara”, “last” => “Mint”], [“id” =>
“7”, “first” => “Che”, “last” => “Guevara”]]
any hint to start ?
Joss
first, last = person.split(/\s+/)
found_person = people.find { | person |
person[“first”] == first and person[“last”] = last
}
Also, do yourself a favour and use a Person class - hashes where the
elements have heterogenous meanings make Baby Data Model Design Jesus
cry. And index them in a hash by the first name and last name string
pair.
David V.
Hi,
- Josselin wrote (2006-08-24 04:05):
I get a string person = 'Clara Mint" which is a full name
and I would like to find the object “id” in a collection using this
full name :
people = [ [“id” => “1”, “first” => “Jack”, “last” => “Johnson”], [“id”
=> “2”, “first” => “Ben”, “last” => “Kenneth”], [“id” => “3”, “first”
=> “Ken”, “last” => “Olsen”], [“id” => “4”, “first” => “Howard”, “last”
=> “Wong”], [“id” => “5”, “first” => “Clara”, “last” => “Mint”], [“id”
=> “7”, “first” => “Che”, “last” => “Guevara”]]
Use regexes to get first and last name, then iterate over the
collection. Untested:
person =~ /^(.) (.)$/
first = $1
last = $2
people.each do |peop|
if first == peop[“first”] and last == peop[“last”]
print peop[“id”]
end
end
Thorsten French Kicks: Also
Ran
James Edward G. II wrote:
Be warned, parsing names correctly is a non-trivial task…
James Edward G. II (Hint, hint!)
Silly Merkin people with yer middle names. Why, in my day, we only had
one name and we were fine, FINE ya hear me?! We only got them last names
after the onions we wore at our belts went out of style… Now geroff my
lawn!
P.S. My wife’s name is Dana Ann Leslie Gray, so don’t forget to handle
that too. 
headschplode
P.P.S. I smell Ruby Q. material… 
Wooerr… I -should- join in the fun one of these days, and that sounds
like it might not require shudder maths.
David V.
Hi –
On Thu, 24 Aug 2006, Josselin wrote:
“last” => “Olsen”], [“id” => “4”, “first” => “Howard”, “last” => “Wong”],
[“id” => “5”, “first” => “Clara”, “last” => “Mint”], [“id” => “7”, “first” =>
“Che”, “last” => “Guevara”]]
any hint to start ?
I’m wondering whether your data structure is what you want. Right now
you’ve got an array of arrays of hashes. Are you sure you don’t just
want an array of hashes?
David
On Aug 23, 2006, at 2:16 PM, David V. wrote:
=> “Howard”, “last” => “Wong”], [“id” => “5”, “first” => “Clara”,
“last” => “Mint”], [“id” => “7”, “first” => “Che”, “last” =>
“Guevara”]]
any hint to start ?
Joss
first, last = person.split(/\s+/)
found_person = people.find { | person |
person[“first”] == first and person[“last”] = last
}
Be warned, parsing names correctly is a non-trivial task…
James Edward G. II (Hint, hint!)
P.S. My wife’s name is Dana Ann Leslie Gray, so don’t forget to
handle that too. 
P.P.S. I smell Ruby Q. material… 
David V. wrote:
[“id” => “2”, “first” => “Ben”, “last” => “Kenneth”], [“id” => “3”,
first, last = person.split(/\s+/)
found_person = people.find { | person |
person[“first”] == first and person[“last”] = last
}
Also, do yourself a favour and use a Person class - hashes where the
elements have heterogenous meanings make Baby Data Model Design Jesus
cry. And index them in a hash by the first name and last name string pair.
Fully agree. And take care to use the correct number of equal signs in
all places. 
Cheers
robert
Robert K. wrote:
Fully agree. And take care to use the correct number of equal signs in
all places. 
Pwnt. sigh
(Shh: Ixnay on the bug introduction. All part of the conspiracy.)
David V.
On 2006-08-23 21:55:11 +0200, [email protected] said:
full name :
you’ve got an array of arrays of hashes. Are you sure you don’t just
want an array of hashes?
David
Your are right…
well, the problem is maybe less complicated that it seems…
the structure doesn’t exist per se, all data are in a DB, I know that
the full name is a concatenation of existing data in the DB (first +
last) and I need to get the object.
it’s an sql problem ( views… ) sorry for raising up a non-ending
story ;-))
joss
James Edward G. II wrote:
[“id” => “2”, “first” => “Ben”, “last” => “Kenneth”], [“id” => “3”,
Be warned, parsing names correctly is a non-trivial task…
James Edward G. II (Hint, hint!)
P.S. My wife’s name is Dana Ann Leslie Gray, so don’t forget to handle
that too. 
P.P.S. I smell Ruby Q. material… 
Working for a collection agency in the SW I found this a very big
problem, especially with Hispanic names where you can have the name
given to us as Juanita Garcia Rodriguez or worse. And of course we may
get it differently from another client. I have to try and split them
properly for Credit Reporting and with hundreds of thousands of names it
has to be done by computer.
On 8/23/06, James Edward G. II [email protected] wrote:
people = [ [“id” => “1”, “first” => “Jack”, “last” => “Johnson”],
person[“first”] == first and person[“last”] = last
}
Be warned, parsing names correctly is a non-trivial task…
James Edward G. II (Hint, hint!)
P.S. My wife’s name is Dana Ann Leslie Gray, so don’t forget to
handle that too. 
P.P.S. I smell Ruby Q. material… 
You bet you do there are Italian and Hungarien names, which are the
other
way round, Spanish names where you can assume that there are two
surnames…
And I do not even know the rules (yet) on Alpha Centauri.
Cheers
Robert
–
Deux choses sont infinies : l’univers et la bêtise humaine ; en ce qui
concerne l’univers, je n’en ai pas acquis la certitude absolue.