Class: ArrayProgressOperation
- Inherits:
-
Object
- Object
- ArrayProgressOperation
- Defined in:
- lib/array_with_progress/array_progress_operation.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#items ⇒ Object
Returns the value of attribute items.
-
#transaction ⇒ Object
Returns the value of attribute transaction.
Instance Method Summary collapse
-
#initialize(items_, description_, options_) ⇒ ArrayProgressOperation
constructor
A new instance of ArrayProgressOperation.
- #run!(&block) ⇒ Object
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_, ) self.items = items_ self.description = description_ self.transaction = [:transaction] || :none end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/array_with_progress/array_progress_operation.rb', line 5 def description @description end |
#items ⇒ Object
Returns the value of attribute items.
4 5 6 |
# File 'lib/array_with_progress/array_progress_operation.rb', line 4 def items @items end |
#transaction ⇒ Object
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 |