Class: Tally::CalculatorRunner
- Inherits:
-
Object
- Object
- Tally::CalculatorRunner
- Defined in:
- lib/tally/calculator_runner.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
Instance Method Summary collapse
-
#initialize(class_name, date) ⇒ CalculatorRunner
constructor
A new instance of CalculatorRunner.
- #klass ⇒ Object
-
#save ⇒ Object
loop through each value and save in db.
- #valid? ⇒ Boolean
- #values ⇒ Object
Constructor Details
#initialize(class_name, date) ⇒ CalculatorRunner
Returns a new instance of CalculatorRunner.
6 7 8 9 |
# File 'lib/tally/calculator_runner.rb', line 6 def initialize(class_name, date) @date = date @class_name = class_name end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
4 5 6 |
# File 'lib/tally/calculator_runner.rb', line 4 def date @date end |
Instance Method Details
#klass ⇒ Object
11 12 13 |
# File 'lib/tally/calculator_runner.rb', line 11 def klass @klass ||= @class_name.to_s.safe_constantize end |
#save ⇒ Object
loop through each value and save in db
16 17 18 19 20 21 22 23 24 |
# File 'lib/tally/calculator_runner.rb', line 16 def save return false unless valid? values.each do |attributes| create_record(attributes) end true end |
#valid? ⇒ Boolean
32 33 34 |
# File 'lib/tally/calculator_runner.rb', line 32 def valid? klass.present? && date.present? end |
#values ⇒ Object
26 27 28 29 30 |
# File 'lib/tally/calculator_runner.rb', line 26 def values return [] unless valid? @values ||= [ klass.new(date).call ].flatten end |