currently I'm about to learn this awesome language and want to build a small calculator for the online game "Eve Online".
I'm struggling with this part of code
orders = Hash.new
orders = {typeid: "type1", value: {order1: {:stationName=>"Jita IV - Moon 4 - Caldari Navy Assembly Plant", price: 3599.99, volRemain: 28},
order2: {:stationName=>"Jita IV - Moon 4 - Caldari Navy Assembly Plant", price: 3600.00, volRemain: 13}}}
{typeid: "type2", value: {order3: {:stationName=>"Jita IV - Moon 4 - Caldari Navy Assembly Plant", price: 3500.00, volRemain: 43}}}
p orders.select {|key, value| value[:order1][:price].to_i < 3600}
Obviously the "p orders.select" doesn't work.
What I want to achieve is to retrieve, say 10 cheapest prices, for a certain typeid.
I do like the approach given here: How do I search within an array of hashes by hash values in ruby?
However this forces me to keep hashes in an array and then again, I can't nest them.
What I don't want to do, is to nest 3 ".each do |key, value|", because (I suppose at least) it would lead to complexity of O(n^3), which should be quite bad.
So is there a way to retrieve all :price - values for a certain type in a smart way?
Thanks to everybody in advance!