Let's put the first 15 lines in a helper. I've been fond of decorators (like https://github.com/drapergem/draper) lately. But since \@ticket is also available in the helper it could be as simple as turning the variables into functions.