data_tools 0.6.4 → 0.6.5
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.
- data/lib/data_tools/hash.rb +10 -0
- data/lib/data_tools/io.rb +2 -1
- data/lib/data_tools/version.rb +1 -1
- data/spec/import_spec.rb +20 -1
- metadata +2 -2
data/lib/data_tools/hash.rb
CHANGED
@@ -183,6 +183,7 @@ module DataTools::Hash
|
|
183
183
|
def cleanse(options = {})
|
184
184
|
each_with_object({}) do |(k,v), out|
|
185
185
|
out[k] = DataTools.scour(v, options)
|
186
|
+
|
186
187
|
if dateformat = options[:datefields][k]
|
187
188
|
begin
|
188
189
|
out[k] = v && DateTime.strptime(v, dateformat).to_date
|
@@ -191,6 +192,15 @@ module DataTools::Hash
|
|
191
192
|
out[k] = nil
|
192
193
|
end
|
193
194
|
end
|
195
|
+
|
196
|
+
if timeformat = options[:timefields][k]
|
197
|
+
begin
|
198
|
+
out[k] = v && DateTime.strptime(v, timeformat).to_time.utc
|
199
|
+
rescue ArgumentError
|
200
|
+
warn "expected '#{timeformat}' in #{k} = '#{v}' at [#{options[:line]}]: #{self}"
|
201
|
+
out[k] = nil
|
202
|
+
end
|
203
|
+
end
|
194
204
|
end
|
195
205
|
end
|
196
206
|
|
data/lib/data_tools/io.rb
CHANGED
data/lib/data_tools/version.rb
CHANGED
data/spec/import_spec.rb
CHANGED
@@ -17,6 +17,25 @@ describe "File Import" do
|
|
17
17
|
f = File.open(File.dirname(__FILE__) + "/../tmp/visits.txt")
|
18
18
|
recs = f.import(:format => :wsv, :datefields => {'admit_arrive_date' => '%Y-%m-%d'}).to_a
|
19
19
|
recs.count.should == 99
|
20
|
-
|
20
|
+
recs.shuffle.take(5).each {|rec| rec.keys.count.should == 3}
|
21
|
+
end
|
22
|
+
|
23
|
+
it "recognizes dates and times" do
|
24
|
+
f = File.open(File.dirname(__FILE__) + "/../tmp/timetest.txt")
|
25
|
+
config = {
|
26
|
+
:format => :tsv,
|
27
|
+
:datefields => {'EDIT_DATE' => '%Y-%m-%d'},
|
28
|
+
:timefields => {'EDIT_TIME' => '%Y-%m-%d %H:%M:%S'}
|
29
|
+
}
|
30
|
+
recs = f.import(config).to_a
|
31
|
+
recs.count.should == 99
|
32
|
+
dt = recs.first['EDIT_DATE']
|
33
|
+
tm = recs.first['EDIT_TIME']
|
34
|
+
dt.year.should == 2012
|
35
|
+
dt.month.should == 11
|
36
|
+
dt.day.should == 28
|
37
|
+
tm.hour.should == 0
|
38
|
+
tm.min.should == 40
|
39
|
+
tm.sec.should == 32
|
21
40
|
end
|
22
41
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: awesome_print
|