Class: InvoiceCount::CountCommand
- Inherits:
-
Object
- Object
- InvoiceCount::CountCommand
- Defined in:
- lib/invoice_count/count_command.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(id, starting_date, ending_date) ⇒ CountCommand
constructor
A new instance of CountCommand.
Constructor Details
#initialize(id, starting_date, ending_date) ⇒ CountCommand
Returns a new instance of CountCommand.
3 4 5 6 7 8 9 |
# File 'lib/invoice_count/count_command.rb', line 3 def initialize(id, starting_date, ending_date) @id = id @starting_date = starting_date @ending_date = ending_date @current_step = (ending_date - starting_date).to_i @count = 0 end |
Instance Method Details
#execute ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/invoice_count/count_command.rb', line 11 def execute date_range.step(current_step).each_cons(2) do |slice| self.current_slice = slice @count += current_slice_invoice_count end if current_slice_term_date < @ending_date params = [@id, current_slice_term_date + 1, @ending_date] @count += InvoiceCount::Invoice.count(*params).to_i end @count rescue InvoiceCount::Error::TooManyResults @current_step /= 2 and retry end |