Skip to content

Instantly share code, notes, and snippets.

@courte
Created June 4, 2015 20:26
Show Gist options
  • Save courte/8b492d782fea7d05c8f2 to your computer and use it in GitHub Desktop.
Save courte/8b492d782fea7d05c8f2 to your computer and use it in GitHub Desktop.
Timesheet#human_readable_billable_time
def human_readable_billable_time
billable_entries_by_rate_type = entries.select(&:billable?).group_by(&:rate_type)
human_readable_time_string = billable_entries_by_rate_type.map do |type, entries|
"#{entries.map(&:amount).sum} #{type == "weekly" ? 'days' : 'hours'}"
end.join(" + ")
human_readable_time_string.empty? ? "No billable time" : human_readable_time_string
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment