pcsv 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/pcsv.rb +16 -4
  2. data/lib/pcsv/version.rb +1 -1
  3. metadata +1 -1
data/lib/pcsv.rb CHANGED
@@ -22,19 +22,26 @@ class PCSV
22
22
 
23
23
  # Performs a given action on each cell of a CSV file.
24
24
  def self.process(action, path, options={})
25
+ options[:headers] = true
25
26
  thread_count = options.delete(:thread_count) || 10
27
+ if_proc = options.delete(:if)
26
28
 
27
29
  # Open CSV & build a worker queue.
28
30
  csv = CSV.read(path, options)
29
31
  queue = []
32
+ headers = nil
30
33
  csv.each_with_index do |row, row_index|
34
+ headers ||= csv.headers
35
+
31
36
  row.fields.each_with_index do |field, col_index|
32
- queue << {
37
+ item = {
38
+ row:row,
33
39
  row_index:row_index,
34
40
  col_index:col_index,
35
- row:row,
36
- value:field
41
+ value:field.to_s,
42
+ header:headers[col_index]
37
43
  }
44
+ queue << item
38
45
  end
39
46
  end
40
47
 
@@ -53,6 +60,7 @@ class PCSV
53
60
 
54
61
  # Invoke the block with the row info.
55
62
  begin
63
+ next if if_proc.nil? || !if_proc.call(item)
56
64
  result = yield item, mutex
57
65
 
58
66
  if action == :map
@@ -68,7 +76,11 @@ class PCSV
68
76
  end
69
77
  end
70
78
 
71
- threads.each { |t| t.join }
79
+ begin
80
+ threads.each { |t| t.join }
81
+ rescue SystemExit, Interrupt
82
+ threads.each { |thread| thread.kill }
83
+ end
72
84
 
73
85
  return csv
74
86
  end
data/lib/pcsv/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class PCSV
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pcsv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: