Module: Virgola::ExtractionMethods
- Extended by:
- ActiveSupport::Concern
- Included in:
- CSVParser
- Defined in:
- lib/virgola/extraction_methods.rb
Instance Method Summary collapse
Instance Method Details
#all ⇒ Object
9 10 11 |
# File 'lib/virgola/extraction_methods.rb', line 9 def all self.in_groups_of(@contents.size) end |
#count ⇒ Object
5 6 7 |
# File 'lib/virgola/extraction_methods.rb', line 5 def count @contents.size-1 end |
#each ⇒ Object
13 14 15 16 17 |
# File 'lib/virgola/extraction_methods.rb', line 13 def each self.in_groups_of(1) { |group| yield group.first } end |
#in_groups_of(batch_size = 1000) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/virgola/extraction_methods.rb', line 19 def in_groups_of(batch_size=1000) all_groups = [] (0..self.count).step(batch_size) { |batch_start| batch_offset = batch_start + batch_size batch_offset = @contents.size if batch_offset >= @contents.size group = self.extract(@contents[batch_start+1, batch_offset]) (block_given? && group.present?) ? (yield group) : (all_groups += group) } all_groups end |