Module: CitizenBudgetModel::AdminHelper
- Defined in:
- app/helpers/citizen_budget_model/admin_helper.rb
Instance Method Summary collapse
- #currency_formatter(options = {}) ⇒ Object
- #percentage_formatter(options = {}) ⇒ Object
- #precision_formatter(options = {}) ⇒ Object
-
#present?(record, *attributes) ⇒ Boolean
Returns whether any of the given attributes are present.
-
#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.
-
#visible?(record, *attributes) ⇒ Boolean
Returns whether any of the given attributes are not hidden fields.
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( = {}) lambda{|v| number_to_currency(v, {strip_insignificant_zeros: true}.merge()) } end |
#percentage_formatter(options = {}) ⇒ Object
15 16 17 18 19 |
# File 'app/helpers/citizen_budget_model/admin_helper.rb', line 15 def percentage_formatter( = {}) lambda{|v| number_to_percentage(v, {strip_insignificant_zeros: true}.merge()) } end |
#precision_formatter(options = {}) ⇒ Object
27 28 29 30 31 |
# File 'app/helpers/citizen_budget_model/admin_helper.rb', line 27 def precision_formatter( = {}) lambda{|v| number_with_precision(v, {strip_insignificant_zeros: true}.merge()) } end |
#present?(record, *attributes) ⇒ Boolean
Returns 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, = {}) if question.unit_name == '%' percentage_formatter() elsif question.unit_name == '$' currency_formatter() else precision_formatter() end end |
#visible?(record, *attributes) ⇒ Boolean
Returns whether any of the given attributes are not 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 |