smarter_csv 1.6.1 → 1.7.1

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.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +133 -0
  3. data/CHANGELOG.md +22 -1
  4. data/CONTRIBUTORS.md +3 -0
  5. data/Gemfile +7 -4
  6. data/README.md +8 -6
  7. data/Rakefile +15 -13
  8. data/ext/smarter_csv/extconf.rb +14 -0
  9. data/ext/smarter_csv/smarter_csv.c +86 -0
  10. data/lib/extensions/hash.rb +4 -2
  11. data/lib/smarter_csv/version.rb +3 -1
  12. data/lib/smarter_csv.rb +519 -10
  13. data/smarter_csv.gemspec +22 -7
  14. metadata +54 -176
  15. data/.gitignore +0 -10
  16. data/.rspec +0 -2
  17. data/.travis.yml +0 -27
  18. data/lib/smarter_csv/smarter_csv.rb +0 -461
  19. data/spec/fixtures/additional_separator.csv +0 -6
  20. data/spec/fixtures/basic.csv +0 -8
  21. data/spec/fixtures/binary.csv +0 -1
  22. data/spec/fixtures/carriage_returns_n.csv +0 -18
  23. data/spec/fixtures/carriage_returns_quoted.csv +0 -3
  24. data/spec/fixtures/carriage_returns_r.csv +0 -1
  25. data/spec/fixtures/carriage_returns_rn.csv +0 -18
  26. data/spec/fixtures/chunk_cornercase.csv +0 -10
  27. data/spec/fixtures/duplicate_headers.csv +0 -3
  28. data/spec/fixtures/empty.csv +0 -5
  29. data/spec/fixtures/empty_columns_1.csv +0 -2
  30. data/spec/fixtures/empty_columns_2.csv +0 -2
  31. data/spec/fixtures/hard_sample.csv +0 -2
  32. data/spec/fixtures/ignore_comments.csv +0 -11
  33. data/spec/fixtures/ignore_comments2.csv +0 -3
  34. data/spec/fixtures/key_mapping.csv +0 -2
  35. data/spec/fixtures/line_endings_n.csv +0 -4
  36. data/spec/fixtures/line_endings_r.csv +0 -1
  37. data/spec/fixtures/line_endings_rn.csv +0 -4
  38. data/spec/fixtures/lots_of_columns.csv +0 -2
  39. data/spec/fixtures/malformed.csv +0 -3
  40. data/spec/fixtures/malformed_header.csv +0 -3
  41. data/spec/fixtures/money.csv +0 -3
  42. data/spec/fixtures/no_header.csv +0 -7
  43. data/spec/fixtures/numeric.csv +0 -5
  44. data/spec/fixtures/pets.csv +0 -5
  45. data/spec/fixtures/problematic.csv +0 -8
  46. data/spec/fixtures/quote_char.csv +0 -9
  47. data/spec/fixtures/quoted.csv +0 -5
  48. data/spec/fixtures/quoted2.csv +0 -4
  49. data/spec/fixtures/separator_colon.csv +0 -4
  50. data/spec/fixtures/separator_comma.csv +0 -4
  51. data/spec/fixtures/separator_pipe.csv +0 -4
  52. data/spec/fixtures/separator_semi.csv +0 -4
  53. data/spec/fixtures/separator_tab.csv +0 -4
  54. data/spec/fixtures/skip_lines.csv +0 -8
  55. data/spec/fixtures/trading.csv +0 -3
  56. data/spec/fixtures/user_import.csv +0 -3
  57. data/spec/fixtures/valid_unicode.csv +0 -5
  58. data/spec/fixtures/with_dashes.csv +0 -8
  59. data/spec/fixtures/with_dates.csv +0 -4
  60. data/spec/smarter_csv/additional_separator_spec.rb +0 -45
  61. data/spec/smarter_csv/binary_file2_spec.rb +0 -24
  62. data/spec/smarter_csv/binary_file_spec.rb +0 -22
  63. data/spec/smarter_csv/blank_spec.rb +0 -55
  64. data/spec/smarter_csv/carriage_return_spec.rb +0 -190
  65. data/spec/smarter_csv/chunked_reading_spec.rb +0 -14
  66. data/spec/smarter_csv/close_file_spec.rb +0 -15
  67. data/spec/smarter_csv/column_separator_spec.rb +0 -95
  68. data/spec/smarter_csv/convert_values_to_numeric_spec.rb +0 -48
  69. data/spec/smarter_csv/duplicate_headers_spec.rb +0 -76
  70. data/spec/smarter_csv/empty_columns_spec.rb +0 -74
  71. data/spec/smarter_csv/extenstions_spec.rb +0 -17
  72. data/spec/smarter_csv/hard_sample_spec.rb +0 -24
  73. data/spec/smarter_csv/header_transformation_spec.rb +0 -21
  74. data/spec/smarter_csv/ignore_comments_spec.rb +0 -45
  75. data/spec/smarter_csv/invalid_headers_spec.rb +0 -38
  76. data/spec/smarter_csv/keep_headers_spec.rb +0 -24
  77. data/spec/smarter_csv/key_mapping_spec.rb +0 -56
  78. data/spec/smarter_csv/line_ending_spec.rb +0 -43
  79. data/spec/smarter_csv/load_basic_spec.rb +0 -20
  80. data/spec/smarter_csv/malformed_spec.rb +0 -25
  81. data/spec/smarter_csv/no_header_spec.rb +0 -29
  82. data/spec/smarter_csv/not_downcase_header_spec.rb +0 -24
  83. data/spec/smarter_csv/parse/column_separator_spec.rb +0 -61
  84. data/spec/smarter_csv/parse/old_csv_library_spec.rb +0 -74
  85. data/spec/smarter_csv/parse/rfc4180_and_more_spec.rb +0 -170
  86. data/spec/smarter_csv/problematic.rb +0 -34
  87. data/spec/smarter_csv/quoted_spec.rb +0 -52
  88. data/spec/smarter_csv/remove_empty_values_spec.rb +0 -13
  89. data/spec/smarter_csv/remove_keys_from_hashes_spec.rb +0 -25
  90. data/spec/smarter_csv/remove_not_mapped_keys_spec.rb +0 -35
  91. data/spec/smarter_csv/remove_values_matching_spec.rb +0 -26
  92. data/spec/smarter_csv/remove_zero_values_spec.rb +0 -25
  93. data/spec/smarter_csv/skip_lines_spec.rb +0 -29
  94. data/spec/smarter_csv/strings_as_keys_spec.rb +0 -24
  95. data/spec/smarter_csv/strip_chars_from_headers_spec.rb +0 -24
  96. data/spec/smarter_csv/trading_spec.rb +0 -25
  97. data/spec/smarter_csv/valid_unicode_spec.rb +0 -94
  98. data/spec/smarter_csv/value_converters_spec.rb +0 -52
  99. data/spec/spec/spec_helper.rb +0 -17
  100. data/spec/spec.opts +0 -2
  101. data/spec/spec_helper.rb +0 -21
@@ -1,8 +0,0 @@
1
- Compte;Date de comptabilisation;Date op�ration;Libell�;R�f�rence;Date valeur;Montant
2
- 22215449203;02/06/2018;01/06/2018;ECHEANCE PRET DONT CAP 410,33 ASS. 8,00E INT. 21,87 COM. 0,00E;8711552;01/06/2018;-440,20;
3
- 22215449203;04/06/2018;04/06/2018;EVI Gaultier Laperche remboursement compte courant;1038326;04/06/2018;-144,07;
4
- 22215449203;04/06/2018;04/06/2018;EVI Guillemain Nicolas remboursement CC pret d'honneur;1038328;04/06/2018;-144,07;
5
- 22215449203;01/06/2018;01/06/2018;310518 SC****5448 INTERMARCHE 95ERMONT;701JQ1K;01/06/2018;-16,00;
6
- 22215449203;01/06/2018;01/06/2018;EVI Stripe Payments UK L STRIPE E7U0R1;706AO1Q;01/06/2018;45,89;
7
- 22215449203;01/06/2018;01/06/2018;EVI Compte N26 Heroku;1100653;01/06/2018;-700,00;
8
- 22215449203;31/05/2018;31/05/2018;EVI Stripe Payments UK L STRIPE L2J1N7;6YISBWF;31/05/2018;465,89;
@@ -1,9 +0,0 @@
1
- "ID","FIRST_NAME","LAST_NAME"
2
- "1","""John","Cooke"""
3
- "2","Jam
4
- e
5
- son""","McCollum"
6
- "3","""Jean","Conn"
7
- "4","Jenny","Traer"
8
- "5","Bo""bbie","Faga"
9
- "6","Mica","Copeland"
@@ -1,5 +0,0 @@
1
- Year,Make,Model,Description,Price
2
- 1997,Ford,E350,"ac, abs, moon",3000.00
3
- 1999,Chevy,"Venture ""Extended Edition""","",4900.00
4
- 1999,Chevy,"Venture ""Extended Edition, Very Large""",,5000.00
5
- 1996,Jeep,Grand Cherokee,"MUST SELL! air, moon roof, loaded",4799.00
@@ -1,4 +0,0 @@
1
- "REVIEW DATE","AUTHOR","""ISBN""","DISCOUNTED ""PRICE"""
2
- "1985/01/21","Douglas Adams",0345391802,5.95
3
- "1998/07/15","Timothy ""The Parser"" Campbell",0968411304,18.99
4
- "1999/12/03","Richard Friedman",0060630353,5.95
@@ -1,4 +0,0 @@
1
- Year:Make:Model:Length
2
- 1997:Ford:E350:2,34
3
- 2000:Mercury:Cougar:2,38
4
- 2013:Tesla:Model S:4,97
@@ -1,4 +0,0 @@
1
- Year,Make,Model,Length
2
- 1997,Ford,E350,2.34
3
- 2000,Mercury,Cougar,2.38
4
- 2013,Tesla,Model S,4.97
@@ -1,4 +0,0 @@
1
- Year|Make|Model|Length
2
- 1997|Ford|E350|2,34
3
- 2000|Mercury|Cougar|2,38
4
- 2013|Tesla|Model S|4,97
@@ -1,4 +0,0 @@
1
- Year;Make;Model;Length
2
- 1997;Ford;E350;2,34
3
- 2000;Mercury;Cougar;2,38
4
- 2013;Tesla;Model S;4,97
@@ -1,4 +0,0 @@
1
- Year Make Model Length
2
- 1997 Ford E350 2,34
3
- 2000 Mercury Cougar 2,38
4
- 2013 Tesla Model S 4,97
@@ -1,8 +0,0 @@
1
- Lines
2
- To
3
- Skip
4
- first name,last name,dogs,cats,birds,fish
5
- Dan,McAllister,2,,,
6
- Lucy,Laweless,,5,,
7
- Miles,O'Brian,,,,21
8
- Nancy,Homes,2,,1,
@@ -1,3 +0,0 @@
1
- Account_ID,options_trader,Stock_Symbol,Shares Issued,Purchase Date
2
- 0002310234,Mike Smith,TSLA,2300,2011-08-19
3
- 0024923423,John Doe,AAPL,1300,2013-03-21
@@ -1,3 +0,0 @@
1
- email,firstname,lastname,manager_email,department
2
- tom@bla.com,Tom,Sawyer,mike@bla.com,IT
3
- eri@bla.com,Eri Chan,tom@bla.com,IT
@@ -1,5 +0,0 @@
1
- "Artist","Track","Album","Label","Year"
2
- Кино,"Мама, мы все сошли с ума",Группа Крови,Moroz Records,1998
3
- "Кино","Мама, мы все сошли с ума","Группа Крови","Moroz Records",1998
4
- Rammstein,Frühling in Paris,Liebe ist für alle da,Vagrant,2009
5
- "Rammstein","Frühling in Paris","Liebe ist für alle da","Vagrant",2009
@@ -1,8 +0,0 @@
1
- First-Name,Last-Name,Dogs,Cats,Birds,Fish
2
- Dan,McAllister,2,0,,
3
- Lucy,Laweless,,5,0,
4
- ,,,,,
5
- Miles,O'Brian,0,0,0,21
6
- Nancy,Homes,2,0,1,
7
- Hernán,Curaçon,3,0,0,
8
- ,,,,,
@@ -1,4 +0,0 @@
1
- first,last,date,price
2
- Ben,Miller,10/30/1998,$44.50
3
- Tom,Turner,2/1/2011,$15
4
- Ken,Smith,01/09/2013,$0.11
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- fixture_path = 'spec/fixtures'
4
-
5
- describe 'handling of additional trailing column separators' do
6
- let(:file) { "#{fixture_path}/additional_separator.csv" }
7
-
8
- describe '' do
9
- let(:data) { SmarterCSV.process(file) }
10
-
11
- it 'reads all lines' do
12
- data.size.should eq 5
13
- end
14
-
15
- it 'reads regular lines' do
16
- item = data[0]
17
- item[:col1].should == 'eins'
18
- item[:col2].should == 'zwei'
19
- end
20
-
21
- it 'strips single trailing col_sep character' do
22
- item = data[1]
23
- item[:col1].should == 'uno'
24
- item[:col2].should == 'dos'
25
- end
26
-
27
- it 'strips multiple trailing col_sep characters' do
28
- item = data[2]
29
- item[:col1].should == 'one'
30
- item[:col2].should == 'two'
31
- end
32
-
33
- it 'strips multiple trailing col_sep chars' do
34
- item = data[3]
35
- item[:col1].should == 'ichi'
36
- item[:col2].should == nil
37
- end
38
-
39
- it 'strips multiple trailing col_sep chars' do
40
- item = data[4]
41
- item[:col1].should == 'un'
42
- item[:col2].should == nil
43
- end
44
- end
45
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
-
3
- fixture_path = 'spec/fixtures'
4
-
5
- # this reads a binary database dump file, which is in structure like a CSV file
6
- # but contains control characters delimiting the rows and columns, and also
7
- # contains a comment section which is commented our by a leading # character
8
-
9
- # same as binary_file_spec , but reading the file with strings as keys
10
-
11
- describe 'be_able_to' do
12
- it 'loads_binary_file_with_strings_as_keys' do
13
- options = {:col_sep => "\cA", :row_sep => "\cB", :comment_regexp => /^#/, :strings_as_keys => true}
14
- data = SmarterCSV.process("#{fixture_path}/binary.csv", options)
15
- data.size.should == 8
16
- data.each do |item|
17
- # all keys should be strings
18
- item.keys.each{|x| x.class.should be == String}
19
- item['timestamp'].should == 1381388409
20
- item['item_id'].class.should be == Fixnum
21
- item['name'].size.should be > 0
22
- end
23
- end
24
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- fixture_path = 'spec/fixtures'
4
-
5
- # this reads a binary database dump file, which is in structure like a CSV file
6
- # but contains control characters delimiting the rows and columns, and also
7
- # contains a comment section which is commented our by a leading # character
8
-
9
- describe 'be_able_to' do
10
- it 'loads_binary_file_with_comments' do
11
- options = {:col_sep => "\cA", :row_sep => "\cB", :comment_regexp => /^#/}
12
- data = SmarterCSV.process("#{fixture_path}/binary.csv", options)
13
- data.flatten.size.should == 8
14
- data.each do |item|
15
- # all keys should be symbols
16
- item.keys.each{|x| x.class.should be == Symbol}
17
- item[:timestamp].should == 1381388409
18
- item[:item_id].class.should be == Fixnum
19
- item[:name].size.should be > 0
20
- end
21
- end
22
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'blank?' do
4
- it 'is true for nil' do
5
- SmarterCSV.send(:blank?, nil).should eq true
6
- end
7
-
8
- it 'is true for empty string' do
9
- SmarterCSV.send(:blank?, '').should eq true
10
- end
11
-
12
- it 'is true for blank string' do
13
- SmarterCSV.send(:blank?, ' ').should eq true
14
- end
15
-
16
- it 'is true for tab string' do
17
- SmarterCSV.send(:blank?, " \t ").should eq true
18
- end
19
-
20
- it 'is false for string with content' do
21
- SmarterCSV.send(:blank?, " 1 ").should eq false
22
- end
23
-
24
- it 'is false for numeic values' do
25
- SmarterCSV.send(:blank?, 1).should eq false
26
- end
27
-
28
- describe 'arrays' do
29
- it 'is true for empty arrays' do
30
- SmarterCSV.send(:blank?, []).should eq true
31
- end
32
-
33
- it 'is true for blank arrays' do
34
- SmarterCSV.send(:blank?, [nil, '', ' ', " \t "]).should eq true
35
- end
36
-
37
- it 'is false for non-blank arrays' do
38
- SmarterCSV.send(:blank?, [nil, '', ' ', " 1 "]).should eq false
39
- end
40
- end
41
-
42
- describe 'hashes' do
43
- it 'is true for empty arrays' do
44
- SmarterCSV.send(:blank?, {}).should eq true
45
- end
46
-
47
- it 'is true for blank arrays' do
48
- SmarterCSV.send(:blank?, {a: nil, b: '', c: ' ', d: " \t "}).should eq true
49
- end
50
-
51
- it 'is false for non-blank arrays' do
52
- SmarterCSV.send(:blank?, {a: nil, b: '', c: ' ', d: " 1 "}).should eq false
53
- end
54
- end
55
- end
@@ -1,190 +0,0 @@
1
- require 'spec_helper'
2
-
3
- fixture_path = 'spec/fixtures'
4
-
5
- describe 'process files with line endings explicitly pre-specified' do
6
- it 'should process a file with \n for line endings and within data fields' do
7
- sep = "\n"
8
- options = {:row_sep => sep}
9
- data = SmarterCSV.process("#{fixture_path}/carriage_returns_n.csv", {:row_sep => sep})
10
- data.flatten.size.should == 8
11
- data[0][:name].should == "Anfield"
12
- data[0][:street].should == "Anfield Road"
13
- data[0][:city].should == "Liverpool"
14
- data[1][:name].should == ["Highbury", "Highbury House"].join(sep)
15
- data[2][:street].should == ["Sir Matt ", "Busby Way"].join(sep)
16
- data[3][:city].should == ["Newcastle-upon-tyne ", "Tyne and Wear"].join(sep)
17
- data[4][:name].should == ["White Hart Lane", "(The Lane)"].join(sep)
18
- data[4][:street].should == ["Bill Nicholson Way ", "748 High Rd"].join(sep)
19
- data[4][:city].should == ["Tottenham", "London"].join(sep)
20
- data[5][:name].should == "Stamford Bridge"
21
- data[5][:street].should == ["Fulham Road", "London"].join(sep)
22
- data[5][:city].should be_nil
23
- data[6][:name].should == ["Etihad Stadium", "Rowsley St", "Manchester"].join(sep)
24
- data[7][:name].should == "Goodison"
25
- data[7][:street].should == "Goodison Road"
26
- data[7][:city].should == "Liverpool"
27
- end
28
-
29
- it 'should process a file with \r for line endings and within data fields' do
30
- sep = "\r"
31
- data = SmarterCSV.process("#{fixture_path}/carriage_returns_r.csv", {:row_sep => sep})
32
- data.flatten.size.should == 8
33
- data[0][:name].should == "Anfield"
34
- data[0][:street].should == "Anfield Road"
35
- data[0][:city].should == "Liverpool"
36
- data[1][:name].should == ["Highbury", "Highbury House"].join(sep)
37
- data[2][:street].should == ["Sir Matt ", "Busby Way"].join(sep)
38
- data[3][:city].should == ["Newcastle-upon-tyne ", "Tyne and Wear"].join(sep)
39
- data[4][:name].should == ["White Hart Lane", "(The Lane)"].join(sep)
40
- data[4][:street].should == ["Bill Nicholson Way ", "748 High Rd"].join(sep)
41
- data[4][:city].should == ["Tottenham", "London"].join(sep)
42
- data[5][:name].should == "Stamford Bridge"
43
- data[5][:street].should == ["Fulham Road", "London"].join(sep)
44
- data[5][:city].should be_nil
45
- data[6][:name].should == ["Etihad Stadium", "Rowsley St", "Manchester"].join(sep)
46
- data[7][:name].should == "Goodison"
47
- data[7][:street].should == "Goodison Road"
48
- data[7][:city].should == "Liverpool"
49
- end
50
-
51
- it 'should process a file with \r\n for line endings and within data fields' do
52
- sep = "\r\n"
53
- data = SmarterCSV.process("#{fixture_path}/carriage_returns_rn.csv", {:row_sep => sep})
54
- data.flatten.size.should == 8
55
- data[0][:name].should == "Anfield"
56
- data[0][:street].should == "Anfield Road"
57
- data[0][:city].should == "Liverpool"
58
- data[1][:name].should == ["Highbury", "Highbury House"].join(sep)
59
- data[2][:street].should == ["Sir Matt ", "Busby Way"].join(sep)
60
- data[3][:city].should == ["Newcastle-upon-tyne ", "Tyne and Wear"].join(sep)
61
- data[4][:name].should == ["White Hart Lane", "(The Lane)"].join(sep)
62
- data[4][:street].should == ["Bill Nicholson Way ", "748 High Rd"].join(sep)
63
- data[4][:city].should == ["Tottenham", "London"].join(sep)
64
- data[5][:name].should == "Stamford Bridge"
65
- data[5][:street].should == ["Fulham Road", "London"].join(sep)
66
- data[5][:city].should be_nil
67
- data[6][:name].should == ["Etihad Stadium", "Rowsley St", "Manchester"].join(sep)
68
- data[7][:name].should == "Goodison"
69
- data[7][:street].should == "Goodison Road"
70
- data[7][:city].should == "Liverpool"
71
- end
72
-
73
- it 'should process a file with more quoted text carriage return characters (\r) than line ending characters (\n)' do
74
- row_sep = "\n"
75
- text_sep = "\r"
76
- data = SmarterCSV.process("#{fixture_path}/carriage_returns_quoted.csv", {:row_sep => row_sep})
77
- data.flatten.size.should == 2
78
- data[0][:band].should == "New Order"
79
- data[0][:members].should == ["Bernard Sumner", "Peter Hook", "Stephen Morris", "Gillian Gilbert"].join(text_sep)
80
- data[0][:albums].should == ["Movement", "Power, Corruption and Lies", "Low-Life", "Brotherhood", "Substance"].join(text_sep)
81
- data[1][:band].should == "Led Zeppelin"
82
- data[1][:members].should == ["Jimmy Page", "Robert Plant", "John Bonham", "John Paul Jones"].join(text_sep)
83
- data[1][:albums].should == ["Led Zeppelin", "Led Zeppelin II", "Led Zeppelin III", "Led Zeppelin IV"].join(text_sep)
84
- end
85
- end
86
-
87
- describe 'process files with line endings in automatic mode' do
88
- let(:options) { { row_sep: :auto } }
89
-
90
- it 'should process a file with \n for line endings and within data fields' do
91
- sep = "\n"
92
- data = SmarterCSV.process("#{fixture_path}/carriage_returns_n.csv", options)
93
- data.flatten.size.should == 8
94
- data[0][:name].should == "Anfield"
95
- data[0][:street].should == "Anfield Road"
96
- data[0][:city].should == "Liverpool"
97
- data[1][:name].should == ["Highbury", "Highbury House"].join(sep)
98
- data[2][:street].should == ["Sir Matt ", "Busby Way"].join(sep)
99
- data[3][:city].should == ["Newcastle-upon-tyne ", "Tyne and Wear"].join(sep)
100
- data[4][:name].should == ["White Hart Lane", "(The Lane)"].join(sep)
101
- data[4][:street].should == ["Bill Nicholson Way ", "748 High Rd"].join(sep)
102
- data[4][:city].should == ["Tottenham", "London"].join(sep)
103
- data[5][:name].should == "Stamford Bridge"
104
- data[5][:street].should == ["Fulham Road", "London"].join(sep)
105
- data[5][:city].should be_nil
106
- data[6][:name].should == ["Etihad Stadium", "Rowsley St", "Manchester"].join(sep)
107
- data[7][:name].should == "Goodison"
108
- data[7][:street].should == "Goodison Road"
109
- data[7][:city].should == "Liverpool"
110
- end
111
-
112
- it 'should process a file with \r for line endings and within data fields' do
113
- sep = "\r"
114
- data = SmarterCSV.process("#{fixture_path}/carriage_returns_r.csv", options)
115
- data.flatten.size.should == 8
116
- data[0][:name].should == "Anfield"
117
- data[0][:street].should == "Anfield Road"
118
- data[0][:city].should == "Liverpool"
119
- data[1][:name].should == ["Highbury", "Highbury House"].join(sep)
120
- data[2][:street].should == ["Sir Matt ", "Busby Way"].join(sep)
121
- data[3][:city].should == ["Newcastle-upon-tyne ", "Tyne and Wear"].join(sep)
122
- data[4][:name].should == ["White Hart Lane", "(The Lane)"].join(sep)
123
- data[4][:street].should == ["Bill Nicholson Way ", "748 High Rd"].join(sep)
124
- data[4][:city].should == ["Tottenham", "London"].join(sep)
125
- data[5][:name].should == "Stamford Bridge"
126
- data[5][:street].should == ["Fulham Road", "London"].join(sep)
127
- data[5][:city].should be_nil
128
- data[6][:name].should == ["Etihad Stadium", "Rowsley St", "Manchester"].join(sep)
129
- data[7][:name].should == "Goodison"
130
- data[7][:street].should == "Goodison Road"
131
- data[7][:city].should == "Liverpool"
132
- end
133
-
134
- it 'also works when auto is given a string' do
135
- sep = "\r"
136
- data = SmarterCSV.process("#{fixture_path}/carriage_returns_r.csv", {row_sep: 'auto'})
137
- data.flatten.size.should == 8
138
- data[0][:name].should == "Anfield"
139
- data[0][:street].should == "Anfield Road"
140
- data[0][:city].should == "Liverpool"
141
- data[1][:name].should == ["Highbury", "Highbury House"].join(sep)
142
- data[2][:street].should == ["Sir Matt ", "Busby Way"].join(sep)
143
- data[3][:city].should == ["Newcastle-upon-tyne ", "Tyne and Wear"].join(sep)
144
- data[4][:name].should == ["White Hart Lane", "(The Lane)"].join(sep)
145
- data[4][:street].should == ["Bill Nicholson Way ", "748 High Rd"].join(sep)
146
- data[4][:city].should == ["Tottenham", "London"].join(sep)
147
- data[5][:name].should == "Stamford Bridge"
148
- data[5][:street].should == ["Fulham Road", "London"].join(sep)
149
- data[5][:city].should be_nil
150
- data[6][:name].should == ["Etihad Stadium", "Rowsley St", "Manchester"].join(sep)
151
- data[7][:name].should == "Goodison"
152
- data[7][:street].should == "Goodison Road"
153
- data[7][:city].should == "Liverpool"
154
- end
155
-
156
- it 'should process a file with \r\n for line endings and within data fields' do
157
- sep = "\r\n"
158
- data = SmarterCSV.process("#{fixture_path}/carriage_returns_rn.csv", options)
159
- data.flatten.size.should == 8
160
- data[0][:name].should == "Anfield"
161
- data[0][:street].should == "Anfield Road"
162
- data[0][:city].should == "Liverpool"
163
- data[1][:name].should == ["Highbury", "Highbury House"].join(sep)
164
- data[2][:street].should == ["Sir Matt ", "Busby Way"].join(sep)
165
- data[3][:city].should == ["Newcastle-upon-tyne ", "Tyne and Wear"].join(sep)
166
- data[4][:name].should == ["White Hart Lane", "(The Lane)"].join(sep)
167
- data[4][:street].should == ["Bill Nicholson Way ", "748 High Rd"].join(sep)
168
- data[4][:city].should == ["Tottenham", "London"].join(sep)
169
- data[5][:name].should == "Stamford Bridge"
170
- data[5][:street].should == ["Fulham Road", "London"].join(sep)
171
- data[5][:city].should be_nil
172
- data[6][:name].should == ["Etihad Stadium", "Rowsley St", "Manchester"].join(sep)
173
- data[7][:name].should == "Goodison"
174
- data[7][:street].should == "Goodison Road"
175
- data[7][:city].should == "Liverpool"
176
- end
177
-
178
- it 'should process a file with more quoted text carriage return characters (\r) than line ending characters (\n)' do
179
- row_sep = "\n"
180
- text_sep = "\r"
181
- data = SmarterCSV.process("#{fixture_path}/carriage_returns_quoted.csv", options)
182
- data.flatten.size.should == 2
183
- data[0][:band].should == "New Order"
184
- data[0][:members].should == ["Bernard Sumner", "Peter Hook", "Stephen Morris", "Gillian Gilbert"].join(text_sep)
185
- data[0][:albums].should == ["Movement", "Power, Corruption and Lies", "Low-Life", "Brotherhood", "Substance"].join(text_sep)
186
- data[1][:band].should == "Led Zeppelin"
187
- data[1][:members].should == ["Jimmy Page", "Robert Plant", "John Bonham", "John Paul Jones"].join(text_sep)
188
- data[1][:albums].should == ["Led Zeppelin", "Led Zeppelin II", "Led Zeppelin III", "Led Zeppelin IV"].join(text_sep)
189
- end
190
- end
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- fixture_path = 'spec/fixtures'
4
-
5
- describe 'be_able_to' do
6
- it 'loads_chunk_cornercase_csv_files' do
7
- (0..5).each do |chunk_size| # test for all chunk-sizes
8
- options = {:chunk_size => chunk_size, :remove_empty_hashes => true}
9
- data = SmarterCSV.process("#{fixture_path}/chunk_cornercase.csv", options)
10
- data.flatten.size.should == 5 # end-result must always be 5 rows
11
- end
12
- end
13
-
14
- end
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
-
3
- fixture_path = 'spec/fixtures'
4
-
5
- describe 'be_able_to' do
6
- it 'close file after using it' do
7
- options = {:col_sep => "\cA", :row_sep => "\cB", :comment_regexp => /^#/, :strings_as_keys => true}
8
-
9
- file = File.new("#{fixture_path}/binary.csv")
10
-
11
- SmarterCSV.process(file, options)
12
-
13
- file.closed?.should == true
14
- end
15
- end
@@ -1,95 +0,0 @@
1
- require 'spec_helper'
2
-
3
- fixture_path = 'spec/fixtures'
4
-
5
- describe 'can handle col_sep' do
6
-
7
- it 'has default of comma as col_sep' do
8
- data = SmarterCSV.process("#{fixture_path}/separator_comma.csv") # no options
9
- data.first.keys.size.should == 4
10
- data.size.should eq 3
11
- end
12
-
13
- describe 'with explicitly given col_sep' do
14
- it 'loads file with comma separator' do
15
- options = {:col_sep => ','}
16
- data = SmarterCSV.process("#{fixture_path}/separator_comma.csv", options)
17
- data.first.keys.size.should == 4
18
- data.size.should eq 3
19
- end
20
-
21
- it 'loads file with tab separator' do
22
- options = {:col_sep => "\t"}
23
- data = SmarterCSV.process("#{fixture_path}/separator_tab.csv", options)
24
- data.first.keys.size.should == 4
25
- data.size.should eq 3
26
- end
27
-
28
- it 'loads file with semi-colon separator' do
29
- options = {:col_sep => ';'}
30
- data = SmarterCSV.process("#{fixture_path}/separator_semi.csv", options)
31
- data.first.keys.size.should == 4
32
- data.size.should eq 3
33
- end
34
-
35
- it 'loads file with colon separator' do
36
- options = {:col_sep => ':'}
37
- data = SmarterCSV.process("#{fixture_path}/separator_colon.csv", options)
38
- data.first.keys.size.should == 4
39
- data.size.should eq 3
40
- end
41
-
42
- it 'loads file with pipe separator' do
43
- options = {:col_sep => '|'}
44
- data = SmarterCSV.process("#{fixture_path}/separator_pipe.csv", options)
45
- data.first.keys.size.should == 4
46
- data.size.should eq 3
47
- end
48
- end
49
-
50
- describe 'auto-detection of separator' do
51
- options = {col_sep: :auto}
52
-
53
- it 'auto-detects comma separator and loads data' do
54
- data = SmarterCSV.process("#{fixture_path}/separator_comma.csv", options)
55
- data.first.keys.size.should == 4
56
- data.size.should eq 3
57
- end
58
-
59
- it 'auto-detects tab separator and loads data' do
60
- data = SmarterCSV.process("#{fixture_path}/separator_tab.csv", options)
61
- data.first.keys.size.should == 4
62
- data.size.should eq 3
63
- end
64
-
65
- it 'auto-detects semi-colon separator and loads data' do
66
- data = SmarterCSV.process("#{fixture_path}/separator_semi.csv", options)
67
- data.first.keys.size.should == 4
68
- data.size.should eq 3
69
- end
70
-
71
- it 'auto-detects colon separator and loads data' do
72
- data = SmarterCSV.process("#{fixture_path}/separator_colon.csv", options)
73
- data.first.keys.size.should == 4
74
- data.size.should eq 3
75
- end
76
-
77
- it 'auto-detects pipe separator and loads data' do
78
- data = SmarterCSV.process("#{fixture_path}/separator_pipe.csv", options)
79
- data.first.keys.size.should == 4
80
- data.size.should eq 3
81
- end
82
-
83
- it 'does not auto-detect other separators' do
84
- expect {
85
- SmarterCSV.process("#{fixture_path}/binary.csv", options)
86
- }.to raise_exception SmarterCSV::NoColSepDetected
87
- end
88
-
89
- it 'also works when auto is given a string' do
90
- data = SmarterCSV.process("#{fixture_path}/separator_pipe.csv", col_sep: 'auto')
91
- data.first.keys.size.should == 4
92
- data.size.should eq 3
93
- end
94
- end
95
- end
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
-
3
- fixture_path = 'spec/fixtures'
4
-
5
- describe 'numeric conversion of values' do
6
- it 'occurs by default' do
7
- options = {}
8
- data = SmarterCSV.process("#{fixture_path}/numeric.csv", options)
9
- data.size.should == 3
10
-
11
- # all the keys should be symbols
12
- data.each do |hash|
13
- hash[:wealth].should be_a_kind_of(Numeric) unless hash[:wealth].nil?
14
- hash[:reference].should be_a_kind_of(Numeric) unless hash[:reference].nil?
15
- end
16
- end
17
-
18
- it 'can be prevented for all values' do
19
- options = { :convert_values_to_numeric => false }
20
- data = SmarterCSV.process("#{fixture_path}/numeric.csv", options)
21
-
22
- data.each do |hash|
23
- hash[:wealth].should be_a_kind_of(String) unless hash[:wealth].nil?
24
- hash[:reference].should be_a_kind_of(String) unless hash[:reference].nil?
25
- end
26
- end
27
-
28
- it 'can be prevented for some keys' do
29
- options = { :convert_values_to_numeric => { :except => :reference }}
30
- data = SmarterCSV.process("#{fixture_path}/numeric.csv", options)
31
-
32
- data.each do |hash|
33
- hash[:wealth].should be_a_kind_of(Numeric) unless hash[:wealth].nil?
34
- hash[:reference].should be_a_kind_of(String) unless hash[:reference].nil?
35
- end
36
- end
37
-
38
- it 'can occur only for some keys' do
39
- options = { :convert_values_to_numeric => { :only => :wealth }}
40
- data = SmarterCSV.process("#{fixture_path}/numeric.csv", options)
41
-
42
- data.each do |hash|
43
- hash[:wealth].should be_a_kind_of(Numeric) unless hash[:wealth].nil?
44
- hash[:reference].should be_a_kind_of(String) unless hash[:reference].nil?
45
- end
46
- end
47
- end
48
-