Skip to content

Instantly share code, notes, and snippets.

@phudgins
Created February 8, 2012 13:44
Show Gist options
  • Save phudgins/1769614 to your computer and use it in GitHub Desktop.
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
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