Created
August 2, 2013 17:45
-
-
Save brandonc/6141837 to your computer and use it in GitHub Desktop.
Generate a compound success message
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 create_success_message | |
result = @created_events.reduce("Post updated,") do |m, ev| | |
case ev.class | |
when PostAssignedEvent | |
m += " assigned to #{ev.assignee.name}," | |
when PostArchivedEvent | |
m += " archived," | |
when PostUnassignedEvent | |
m += " assigned user cleared," | |
when PostProposedEvent | |
m += " proposed," | |
end | |
m | |
end.chomp(",") | |
if result.count(",") > 0 | |
result[result.rindex(',')...(result.rindex(',') + 1)] = "#{result.count(",") > 1 ? ',' : ''} and" | |
end | |
result + "." | |
end | |
# > Post updated, archived, and assigned user cleared. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment