Skip to content

Instantly share code, notes, and snippets.

@brandonc
Created August 2, 2013 17:45
Show Gist options
  • Save brandonc/6141837 to your computer and use it in GitHub Desktop.
Save brandonc/6141837 to your computer and use it in GitHub Desktop.
Generate a compound success message
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