Skip to content

Instantly share code, notes, and snippets.

@sclinede
Last active August 29, 2015 14:01
Show Gist options
  • Save sclinede/f53c778b310c8ea44def to your computer and use it in GitHub Desktop.
Save sclinede/f53c778b310c8ea44def to your computer and use it in GitHub Desktop.
nice product name decorator
def product_info
product_name_reg = /^#{I18n.t('pages.dashboard.messages.order.new', product: '(.*)', amount: '(.*)', price: '(.*)')}$/
total_reg = /^#{I18n.t('pages.dashboard.messages.order.total', total: '')}(.*)$/
product_name = content.match(product_name_reg).try(:[], 1)
total = content.match(total_reg).try(:[], 1)
result = total.present? ? '%s (%s)' : '%s'
result % [product_name, total]
end
@dkron
Copy link

dkron commented May 13, 2014

result = []
result << product_name
result << "(#{total})" if total.present?
result.join(' ')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment