Module: CitizenBudgetModel::AdminHelper

Defined in:
app/helpers/citizen_budget_model/admin_helper.rb

Instance Method Summary collapse

Instance Method Details

#currency_formatter(options = {}) ⇒ Object



21
22
23
24
25
# File 'app/helpers/citizen_budget_model/admin_helper.rb', line 21

def currency_formatter(options = {})
  lambda{|v|
    number_to_currency(v, {strip_insignificant_zeros: true}.merge(options))
  }
end

#percentage_formatter(options = {}) ⇒ Object



15
16
17
18
19
# File 'app/helpers/citizen_budget_model/admin_helper.rb', line 15

def percentage_formatter(options = {})
  lambda{|v|
    number_to_percentage(v, {strip_insignificant_zeros: true}.merge(options))
  }
end

#precision_formatter(options = {}) ⇒ Object



27
28
29
30
31
# File 'app/helpers/citizen_budget_model/admin_helper.rb', line 27

def precision_formatter(options = {})
  lambda{|v|
    number_with_precision(v, {strip_insignificant_zeros: true}.merge(options))
  }
end

#present?(record, *attributes) ⇒ Boolean

Returns whether any of the given attributes are present.

Parameters:

  • record
  • attributes

Returns:

  • (Boolean)

    whether any of the given attributes are present



50
51
52
53
54
# File 'app/helpers/citizen_budget_model/admin_helper.rb', line 50

def present?(record, *attributes)
  attributes.any? do |attribute|
    record[attribute].present?
  end
end

#value_formatter(question, options = {}) ⇒ Object

Formats as a percentage if the unit name is “%”, as a currency if the unit name is “$” and as a number otherwise.



5
6
7
8
9
10
11
12
13
# File 'app/helpers/citizen_budget_model/admin_helper.rb', line 5

def value_formatter(question, options = {})
  if question.unit_name == '%'
    percentage_formatter(options)
  elsif question.unit_name == '$'
    currency_formatter(options)
  else
    precision_formatter(options)
  end
end

#visible?(record, *attributes) ⇒ Boolean

Returns whether any of the given attributes are not hidden fields.

Parameters:

  • record
  • attributes

Returns:

  • (Boolean)

    whether any of the given attributes are not hidden fields

See Also:

  • CitizenBudgetModel.hidden_fields


39
40
41
42
43
# File 'app/helpers/citizen_budget_model/admin_helper.rb', line 39

def visible?(record, *attributes)
  attributes.any? do |attribute|
    !CitizenBudgetModel.hidden_fields.fetch(record.class.model_name.param_key.to_sym, []).include?(attribute)
  end
end