Class: CitizenBudgetModel::Question
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- CitizenBudgetModel::Question
- Defined in:
- app/models/citizen_budget_model/question.rb
Instance Attribute Summary collapse
-
#labels_as_list ⇒ Object
Returns the value of attribute labels_as_list.
-
#maximum ⇒ Object
Returns the value of attribute maximum.
-
#minimum ⇒ Object
Returns the value of attribute minimum.
-
#options_as_list ⇒ Object
Returns the value of attribute options_as_list.
-
#step ⇒ Object
Returns the value of attribute step.
Instance Method Summary collapse
-
#default_equation ⇒ String
Returns a default equation, where the difference between the chosen value and the default value is multiplied by the unit value.
-
#display_name ⇒ String
Returns a question’s name, title or “Untitled”.
-
#solve(value) ⇒ Float
Solves the equation with the variable’s given value.
-
#working_equation ⇒ String
Returns the equation or a default equation if not set.
Instance Attribute Details
#labels_as_list ⇒ Object
Returns the value of attribute labels_as_list.
37 38 39 |
# File 'app/models/citizen_budget_model/question.rb', line 37 def labels_as_list @labels_as_list end |
#maximum ⇒ Object
Returns the value of attribute maximum.
37 38 39 |
# File 'app/models/citizen_budget_model/question.rb', line 37 def maximum @maximum end |
#minimum ⇒ Object
Returns the value of attribute minimum.
37 38 39 |
# File 'app/models/citizen_budget_model/question.rb', line 37 def minimum @minimum end |
#options_as_list ⇒ Object
Returns the value of attribute options_as_list.
37 38 39 |
# File 'app/models/citizen_budget_model/question.rb', line 37 def end |
#step ⇒ Object
Returns the value of attribute step.
37 38 39 |
# File 'app/models/citizen_budget_model/question.rb', line 37 def step @step end |
Instance Method Details
#default_equation ⇒ String
Returns a default equation, where the difference between the chosen value and the default value is multiplied by the unit value.
57 58 59 60 61 |
# File 'app/models/citizen_budget_model/question.rb', line 57 def default_equation if machine_name.present? && default_value.present? && unit_value_down.present? && unit_value_up.present? "(#{machine_name} - #{default_value}) * (#{machine_name} < #{default_value} ? #{unit_value_down} : #{unit_value_up})" end end |
#display_name ⇒ String
Returns a question’s name, title or “Untitled”.
42 43 44 |
# File 'app/models/citizen_budget_model/question.rb', line 42 def display_name name.present? && name || title.present? && title || _('Untitled') end |
#solve(value) ⇒ Float
Solves the equation with the variable’s given value.
67 68 69 70 71 |
# File 'app/models/citizen_budget_model/question.rb', line 67 def solve(value) if working_equation.present? && machine_name.present? eval(working_equation, Struct.new(machine_name.to_sym).new(Float(value)).instance_eval{binding}) end end |
#working_equation ⇒ String
Returns the equation or a default equation if not set.
49 50 51 |
# File 'app/models/citizen_budget_model/question.rb', line 49 def working_equation default_equation || '' end |