Class: ArrayProgressOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/array_with_progress/array_progress_operation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items_, description_, options_) ⇒ ArrayProgressOperation

Returns a new instance of ArrayProgressOperation.



8
9
10
11
12
# File 'lib/array_with_progress/array_progress_operation.rb', line 8

def initialize(items_, description_, options_)
  self.items = items_
  self.description = description_
  self.transaction = options_[:transaction] || :none
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/array_with_progress/array_progress_operation.rb', line 5

def description
  @description
end

#itemsObject

Returns the value of attribute items.



4
5
6
# File 'lib/array_with_progress/array_progress_operation.rb', line 4

def items
  @items
end

#transactionObject

Returns the value of attribute transaction.



6
7
8
# File 'lib/array_with_progress/array_progress_operation.rb', line 6

def transaction
  @transaction
end

Instance Method Details

#run!(&block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/array_with_progress/array_progress_operation.rb', line 14

def run!(&block)
  count = self.items.count.to_f
  run_with_transaction(:collection) do
    self.items.each_with_index do |item, index|
      run_with_transaction(:member) do
        progress = index.to_f / count * 100.0
        ArrayProgressItem.run!(self, item, progress, &block)
      end
    end
  end
end