Created
February 8, 2012 13:44
-
-
Save phudgins/1769614 to your computer and use it in GitHub Desktop.
Sort collection of job_postings by 'status' and 'posted_at DESC' on Orion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def status_value(status) | |
return 1 if status=='pending' | |
return 2 if status=='active' | |
return 3 if status=='closed' | |
end | |
# Sort collection of job_postings by 'status' and 'posted_at DESC' on Orion | |
@jps = User.find_by_email("jane.doe@example.com").job_postings | |
@jps.sort! { |a,b| [status_value(a.status), b.posted_at] <=> [status_value(b.status), a.posted_at] } | |
ap @jps.map { |jp| "#{jp.status} - #{Time.parse(jp.posted_at).to_s(:db)}" } | |
nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment