Skip to content

Instantly share code, notes, and snippets.

View francirp's full-sized avatar

Ryan Francis francirp

  • LaunchPad Lab
  • Chicago, IL
View GitHub Profile
@francirp
francirp / decorators_codeblock_17.md
Created August 8, 2016 16:25
Decorators Codeblock 17
def self.percent(*keys)
  keys.each do |key|    
    define_method(key) do
      h.number_with_precision(object.send(key) * 100.0, precision: 1)
    end

    define_method("display_#{key}") do
      h.number_to_percentage(object.send(column_name) * 100.0, precision: 1)
 end
@francirp
francirp / decorators_codeblock_16.md
Created August 8, 2016 16:24
Decorators Codeblock 16
class CompanyDecorator < BaseDecorator
  delegate_all

  currency :budget, :actual  
end
@francirp
francirp / decorators_codeblock_15.md
Last active August 8, 2016 16:23
Decorators Codeblock 15
class BaseDecorator < Draper::Decorator
  delegate_all

  def self.currency(*keys)
    keys.each do |key|
      define_method(key) do
        h.number_with_precision(object.send(key), precision: 2)
      end
@francirp
francirp / decorators_codeblock_14.md
Created August 8, 2016 16:22
Decorators Codeblock 14
class BaseDecorator < Draper::Decorator
  delegate_all

  def self.currency(*keys)
    keys.each do |key|
      define_method(key) do
      end

 define_method("display_#{key}") do
@francirp
francirp / decorators_codeblock_13.md
Created August 8, 2016 16:21
Decorators Codeblock 13
class BaseDecorator < Draper::Decorator
  delegate_all

  def self.currency(*keys)
  end
end
@francirp
francirp / decorators_codeblock_12.md
Created August 8, 2016 16:20
Decorators Codeblock 12
class CompanyDecorator < BaseDecorator
  delegate_all

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

  def display_budget
 h.number_to_currency(object.budget, precision: 0)
@francirp
francirp / decorators_codeblock_11.md
Created August 8, 2016 16:20
Decorators Codeblock 11
class CompanyDecorator < BaseDecorator
  delegate_all

  currency :budget
end
@francirp
francirp / decorators_codeblock_10.md
Created August 8, 2016 16:19
Decorators Codeblock 10
# app/decorators/company_decorator.rb

class CompanyDecorator < BaseDecorator
  delegate_all
end
@francirp
francirp / decorators_codeblock_9.md
Created August 8, 2016 16:18
Decorators Codeblock 9
# app/decorators/base_decorator.rb

class BaseDecorator < Draper::Decorator
  delegate_all
end
@francirp
francirp / decorators_codeblock_8.md
Created August 8, 2016 16:15
Decorators Codeblock 8
class CompanyDecorator < BaseDecorator
  delegate_all

  currency :budget, :actual
  percent :percent_budget_spent
end