Hello Rubyist, I am new here and looking forward to talk Ruby!
I wrote this gem a while ago to make my job of collecting data from deeply nested hashes easier (i.e. the kind of hashes you might get back from the savon gem for example because they represent some underlying XML)
Do you have any feedback on it?
https://github.com/mottalrd/hash_dig_and_collect
I wrote about the rationale here
http://www.alfredo.motta.name/making-ruby-hashdig-even-more-awesome-introducing-hashdig_and_collect/
Here is an example where I want the latitude of all the addresses of a given client.
Thank you for your help,
have a nice day
client_with_many_addresses = {
details: {
first_name: "Florentino",
last_name: "Perez"
},
addresses: [
{
type: "home",
postcode: "SE1 9SG",
street: "London Bridge St",
number: 32,
city: "London",
location: {
latitude: 51.504382,
longitude: -0.086279
}
},
{
type: "office",
postcode: "SW1A 1AA",
street: "Buckingham Palace Road",
number: nil,
city: "London",
location: {
latitude: 51.5013673,
longitude: -0.1440787
}
}
]
}
client_with_many_addresses.dig_and_collect(:addresses, :location, :latitude)
#=> [51.504382, 51.5013673]
···
--
Alfredo Motta, Ph.D. Software Engineering
About me: https://www.alfredo.motta.name<https://www.alfredo.motta.name/>
Linkedin: https://linkedin.com/in/alfredomotta