pcsv 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pcsv.rb +9 -1
- data/lib/pcsv/version.rb +1 -1
- metadata +26 -4
data/lib/pcsv.rb
CHANGED
@@ -25,6 +25,9 @@ class PCSV
|
|
25
25
|
options[:headers] = true
|
26
26
|
thread_count = options.delete(:thread_count) || 10
|
27
27
|
if_proc = options.delete(:if)
|
28
|
+
on_count_proc = options.delete(:on_count)
|
29
|
+
progress_bar_visible = options.has_key?(:progress_bar) ? options.delete(:progress_bar) : true
|
30
|
+
progress_bar = nil
|
28
31
|
|
29
32
|
# Open CSV & build a worker queue.
|
30
33
|
csv = CSV.read(path, options)
|
@@ -41,9 +44,12 @@ class PCSV
|
|
41
44
|
value:field.to_s,
|
42
45
|
header:headers[col_index]
|
43
46
|
}
|
47
|
+
next if if_proc.nil? || !if_proc.call(item)
|
44
48
|
queue << item
|
45
49
|
end
|
46
50
|
end
|
51
|
+
progress_bar = ::ProgressBar.create(:total => queue.length, :format => '%a |%B| %E %P%%') if progress_bar_visible
|
52
|
+
on_count_proc.call(queue.length) unless on_count_proc.nil?
|
47
53
|
|
48
54
|
# Launch threads and iterate over queue until it's done.
|
49
55
|
mutex = Mutex.new()
|
@@ -60,7 +66,6 @@ class PCSV
|
|
60
66
|
|
61
67
|
# Invoke the block with the row info.
|
62
68
|
begin
|
63
|
-
next if if_proc.nil? || !if_proc.call(item)
|
64
69
|
result = yield item, mutex
|
65
70
|
|
66
71
|
if action == :map
|
@@ -69,7 +74,10 @@ class PCSV
|
|
69
74
|
}
|
70
75
|
end
|
71
76
|
|
77
|
+
mutex.synchronize { progress_bar.increment } unless progress_bar.nil?
|
78
|
+
|
72
79
|
rescue StandardError => e
|
80
|
+
mutex.synchronize { progress_bar.clear } unless progress_bar.nil?
|
73
81
|
warn("[ERROR] #{e.message} [R#{item[:row_index]},C#{item[:col_index]}]")
|
74
82
|
end
|
75
83
|
end
|
data/lib/pcsv/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ruby-progressbar
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.0.2
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: rake
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,7 +83,7 @@ dependencies:
|
|
67
83
|
- - ~>
|
68
84
|
- !ruby/object:Gem::Version
|
69
85
|
version: 0.1.0
|
70
|
-
type: :
|
86
|
+
type: :development
|
71
87
|
prerelease: false
|
72
88
|
version_requirements: !ruby/object:Gem::Requirement
|
73
89
|
none: false
|
@@ -99,15 +115,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
115
|
- - ! '>='
|
100
116
|
- !ruby/object:Gem::Version
|
101
117
|
version: '0'
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
hash: -1237481695324050432
|
102
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
122
|
none: false
|
104
123
|
requirements:
|
105
124
|
- - ! '>='
|
106
125
|
- !ruby/object:Gem::Version
|
107
126
|
version: '0'
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
hash: -1237481695324050432
|
108
130
|
requirements: []
|
109
131
|
rubyforge_project:
|
110
|
-
rubygems_version: 1.8.
|
132
|
+
rubygems_version: 1.8.25
|
111
133
|
signing_key:
|
112
134
|
specification_version: 3
|
113
135
|
summary: A simple, parallel processing framework for CSV files.
|