windows_csv 0.0.3 → 0.0.4
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 +6 -11
- data/spec/windows_csv_spec.rb +1 -1
- data/windows_csv.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/windows_csv.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
class WindowsCsv
|
2
|
-
ENCODING = Encoding::
|
3
|
-
|
2
|
+
ENCODING = Encoding::UTF_8
|
3
|
+
|
4
|
+
BOM = "\377\376".force_encoding(Encoding::UTF_16LE) # Byte Order Mark
|
4
5
|
COL_SEP = "\t"
|
5
6
|
QUOTE_CHAR = "\""
|
6
7
|
|
@@ -8,9 +9,7 @@ class WindowsCsv
|
|
8
9
|
require "rubygems"
|
9
10
|
require "csv_lazy"
|
10
11
|
|
11
|
-
File.open(path, "
|
12
|
-
fp.sysread(2)
|
13
|
-
|
12
|
+
File.open(path, "rb:bom|utf-16le") do |fp|
|
14
13
|
csv_args = {:debug => false, :io => fp, :col_sep => COL_SEP, :quote_char => QUOTE_CHAR}
|
15
14
|
csv_args.merge!(args[:csv_args]) if args[:csv_args]
|
16
15
|
|
@@ -39,11 +38,7 @@ class WindowsCsv
|
|
39
38
|
|
40
39
|
begin
|
41
40
|
@args[:io].write(BOM)
|
42
|
-
|
43
|
-
::CSV.open(@args[:io], "w", :col_sep => COL_SEP, :quote_char => QUOTE_CHAR, :force_quotes => true) do |csv|
|
44
|
-
@csv = csv
|
45
|
-
yield self
|
46
|
-
end
|
41
|
+
yield self
|
47
42
|
ensure
|
48
43
|
fp.close if fp
|
49
44
|
end
|
@@ -62,7 +57,7 @@ class WindowsCsv
|
|
62
57
|
end
|
63
58
|
end
|
64
59
|
|
65
|
-
@
|
60
|
+
@args[:io].puts CSV.generate_line(encoded, :col_sep => COL_SEP, :quote_char => QUOTE_CHAR, :force_quotes => true).encode(Encoding::UTF_16LE)
|
66
61
|
|
67
62
|
return nil
|
68
63
|
end
|
data/spec/windows_csv_spec.rb
CHANGED
@@ -18,7 +18,7 @@ describe "WindowsCsv" do
|
|
18
18
|
#puts "Path: #{tmpfile}"
|
19
19
|
|
20
20
|
WindowsCsv.foreach(tmpfile, :csv_args => {:headers => true}) do |row|
|
21
|
-
|
21
|
+
puts "Row: #{row}"
|
22
22
|
row[:Name2].should eql("Christina")
|
23
23
|
row[:Encoding].should eql("æøå")
|
24
24
|
row[:MultiLine].should eql("Multi\r\nLine")
|
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.4
|
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: 1699321643464917244
|
129
129
|
version: '0'
|
130
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
131
|
none: false
|