<div dir="ltr"><div>My solution</div><div><br></div><div>#######</div><div><br></div><div>require 'ostruct'</div><div><br></div><div><div>collection = {</div><div>  "ami-c3c73c7f"=>"tn-example 1980-09-12T17:53:25Z",</div>
<div>  "ami-600925fe"=>"sns-example 1983-01-05T16:21:08Z",</div><div>  "ami-131f1007"=>"dk-example 2005-01-27T23:03:01Z",</div><div>  "ami-98d4ddef"=>"tn-example 2002-10-27T11:52:26Z",</div>
<div>  "ami-fe6af742"=>"sns-example 1998-11-22T09:54:51Z",</div><div>  "ami-09966e45"=>"dk-example 1993-01-09T13:23:45Z",</div><div>  "ami-44e6ee6a"=>"tn-example 2013-12-23T20:52:28Z",</div>
<div>  "ami-cbf7f1a9"=>"sns-example 1979-09-09T07:15:47Z",</div><div>  "ami-fcd2e7ac"=>"dk-example 2007-09-02T18:34:05Z"</div><div>}</div><div><br></div><div>collection_hash = collection.map do |id, value|</div>
<div>  type, timestamp = value.split(' ')</div><div><br></div><div>  OpenStruct.new(</div><div>    id: id,</div><div>    type: type,</div><div>    timestamp: Time.new(timestamp)</div><div>  )</div><div>end</div><div>
<br></div><div>collection_hash.select { |item| item.type == 'sns-example' }.sort_by(&:timestamp)</div><div><br></div><div>#######<br></div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Tue, Jun 17, 2014 at 10:16 PM, Gerhard Lazu <span dir="ltr"><<a href="mailto:gerhard@lazu.co.uk" target="_blank">gerhard@lazu.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">I really like Tom's approach, I'm somewhat expanding on it: <a href="https://gist.github.com/gerhard/7203f3bb51d1ad59c886" target="_blank">https://gist.github.com/gerhard/7203f3bb51d1ad59c886</a><br>


</div><div class="gmail_extra">

<br clear="all"><div><div dir="ltr"><br><hr style="font-family:arial,helvetica,sans-serif"><font color="#3333ff"><font face="arial, helvetica, sans-serif"><a href="http://twitter.com/#!/gerhardlazu" target="_blank">Twitter</a> <a href="https://github.com/gerhard" target="_blank">Github</a> </font><a href="http://gerhard.lazu.co.uk/" style="font-family:arial,helvetica,sans-serif" target="_blank">Blog</a></font></div>




</div>
<br><br><div class="gmail_quote"><div><div class="h5">On Tue, Jun 17, 2014 at 11:46 AM, Stephen Nelson-Smith <span dir="ltr"><<a href="mailto:sanelson@gmail.com" target="_blank">sanelson@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">



<div dir="ltr">I have a hash that looks like this:<div><br></div><div><div>{"ami-c3c73c7f"=>"tn-example 1980-09-12T17:53:25Z",</div><div> "ami-600925fe"=>"sns-example 1983-01-05T16:21:08Z",</div>





<div> "ami-131f1007"=>"dk-example 2005-01-27T23:03:01Z",</div><div> "ami-98d4ddef"=>"tn-example 2002-10-27T11:52:26Z",</div><div> "ami-fe6af742"=>"sns-example 1998-11-22T09:54:51Z",</div>





<div> "ami-09966e45"=>"dk-example 1993-01-09T13:23:45Z",</div><div> "ami-44e6ee6a"=>"tn-example 2013-12-23T20:52:28Z",</div><div> "ami-cbf7f1a9"=>"sns-example 1979-09-09T07:15:47Z",</div>





<div> "ami-fcd2e7ac"=>"dk-example 2007-09-02T18:34:05Z"}</div><div><br></div><div>I want to filter this hash by value and return them in sorted date order.  The implementation I have just seems ugly:</div>





<div><br></div><div><div>catalogue.select {|id, name| name.match /sns-example/ }.sort { |id, name| name[1] <=> id[1] }</div><div>=> [["ami-a65e21cc", "sns-example 2011-10-03T11:15:49Z"],</div>





<div> ["ami-9a401c41", "sns-example 1983-09-22T15:26:00Z"],</div><div> ["ami-9f9ae4d8", "sns-example 1971-03-06T03:58:52Z"]]</div></div><div><br></div><div><br></div><div>I don't like the way sort takes my hash and makes it into an array of tuples... and I'd really like it to return an array of single key/value hashes... </div>





<div><br></div><div>Also, is there a more elegant way to perform the filter/search?</div><span><font color="#888888"><div><br></div><div>S.</div><div><br></div>-- <br>Stephen Nelson-Smith<br>Technical Director<br>
Atalanta Systems Ltd<br><a href="http://www.atalanta-systems.com" target="_blank">www.atalanta-systems.com</a>
</font></span></div></div>
<br></div></div><div class="">_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
<br></div></blockquote></div><br></div></div>
<br>_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
<br></blockquote></div><br></div>