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 CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/lib/windows_csv.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  class WindowsCsv
2
- ENCODING = Encoding::UTF_16LE
3
- BOM = "\377\376".force_encoding(ENCODING) # Byte Order Mark
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, "r", :encoding => "UTF-8") do |fp|
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
- @csv << encoded
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
@@ -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
- #puts "Row: #{row}"
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "windows_csv"
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["kaspernj"]
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.3
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: 2642998020291054997
128
+ hash: 1699321643464917244
129
129
  version: '0'
130
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  none: false