windows_csv 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/windows_csv.rb +5 -2
- data/spec/windows_csv_spec.rb +5 -3
- data/windows_csv.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
data/lib/windows_csv.rb
CHANGED
@@ -4,14 +4,17 @@ class WindowsCsv
|
|
4
4
|
COL_SEP = "\t"
|
5
5
|
QUOTE_CHAR = "\""
|
6
6
|
|
7
|
-
def self.foreach(path)
|
7
|
+
def self.foreach(path, args = {})
|
8
8
|
require "rubygems"
|
9
9
|
require "csv_lazy"
|
10
10
|
|
11
11
|
File.open(path, "rb", :encoding => "UTF-8") do |fp|
|
12
12
|
fp.sysread(2)
|
13
13
|
|
14
|
-
|
14
|
+
csv_args = {:debug => false, :io => fp, :col_sep => COL_SEP, :quote_char => QUOTE_CHAR}
|
15
|
+
csv_args.merge!(args[:csv_args]) if args[:csv_args]
|
16
|
+
|
17
|
+
Csv_lazy.new(csv_args) do |row|
|
15
18
|
yield row
|
16
19
|
end
|
17
20
|
end
|
data/spec/windows_csv_spec.rb
CHANGED
@@ -11,15 +11,17 @@ describe "WindowsCsv" do
|
|
11
11
|
tmpfile = "#{Dir.tmpdir}/windows_csv_test_#{Digest::MD5.hexdigest(Time.now.to_f.to_s)}.csv"
|
12
12
|
|
13
13
|
WindowsCsv.new(:path => tmpfile) do |csv|
|
14
|
+
csv << ["Name1", "Name2", "Encoding", "Date", "Time", "DateTime"]
|
14
15
|
csv << ["Kasper", "Christina", "æøå", Date.new, Time.new, DateTime.new]
|
15
16
|
end
|
16
17
|
|
17
|
-
puts "Path: #{tmpfile}"
|
18
|
+
#puts "Path: #{tmpfile}"
|
18
19
|
|
19
20
|
begin
|
20
|
-
WindowsCsv.foreach(tmpfile) do |row|
|
21
|
+
WindowsCsv.foreach(tmpfile, :csv_args => {:headers => true}) do |row|
|
21
22
|
#puts "Row: #{row}"
|
22
|
-
row[
|
23
|
+
row[:Name2].should eql("Christina")
|
24
|
+
row[:Encoding].should eql("æøå")
|
23
25
|
end
|
24
26
|
rescue => e
|
25
27
|
puts e.inspect
|
data/windows_csv.gemspec
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: windows_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- kaspernj
|
@@ -125,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
segments:
|
127
127
|
- 0
|
128
|
-
hash: -
|
128
|
+
hash: -4189247397405598293
|
129
129
|
version: '0'
|
130
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
131
|
none: false
|