Sha256: 07988549bfef944d8baef7743359053e82508dc31333513d698ae9f7ba1b8394

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module CitizenBudgetModel
  module AdminHelper
    # Formats as a percentage if the unit name is "%", as a currency if the unit
    # name is "$" and as a number otherwise.
    def value_formatter(question)
      if question.unit_name == '%'
        percentage_formatter
      elsif question.unit_name == '$'
        currency_formatter
      else
        precision_formatter
      end
    end

    def percentage_formatter
      lambda{|v|
        number_to_percentage(v, strip_insignificant_zeros: true)
      }
    end

    def currency_formatter
      lambda{|v|
        number_to_currency(v, strip_insignificant_zeros: true)
      }
    end

    def precision_formatter
      lambda{|v|
        number_with_precision(v, strip_insignificant_zeros: true)
      }
    end

    # Returns whether any of the given attributes are not hidden fields.
    #
    # @param record
    # @param attributes
    # @see CitizenBudgetModel.hidden_fields
    def visible?(record, *attributes)
      attributes.any? do |attribute|
        !CitizenBudgetModel.hidden_fields.fetch(record.class.model_name.param_key.to_sym, []).include?(attribute)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
citizen_budget_model-0.0.1 app/helpers/citizen_budget_model/admin_helper.rb