Skip to content

Instantly share code, notes, and snippets.

@francirp
Created August 8, 2016 15:47
Show Gist options
  • Save francirp/3db5251580bab241c4b03349fe69ad76 to your computer and use it in GitHub Desktop.
Save francirp/3db5251580bab241c4b03349fe69ad76 to your computer and use it in GitHub Desktop.
Decorators Codeblock 6
# app/decorators/company_decorator.rb

class CompanyDecorator < Draper::Decorator
  delegate_all

  def budget
    h.number_with_precision(object.budget, precision: 2)
  end

  def display_budget
    h.number_to_currency(object.budget, precision: 0)
  end

  def actual
    h.number_with_precision(object.actual, precision: 2)
  end

  def display_actual
    h.number_to_currency(object.actual, precision: 0)
  end

  def display_percent_budget_spent
    h.number_to_percentage(object.percent_budget_spent, precision: 1)
  end

  def percent_budget_spent
    h.number_with_precision(object.percent_budget_spent, precision: 1)
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment