<div dir="ltr">A quick go at this: <div><br></div><div>catalogue.select{|k,v| v =~ /sns/}.sort_by{|k,v| Date.parse(v.gsub(/.w{2}\-example /, ''))}<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
2014-06-17 11:46 GMT+01:00 Stephen Nelson-Smith <span dir="ltr"><<a href="mailto:sanelson@gmail.com" target="_blank">sanelson@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<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 class="HOEnZb"><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>_______________________________________________<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>