simplecsv 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ 2007-04-01
2
+
3
+ * 0.1.4
4
+ * add SimpleCSV.parse_file and SimpleCSV#parse_file
5
+
1
6
  2007-03-18
2
7
 
3
8
  * 0.1.3
@@ -11,6 +11,10 @@ ext/simplecsv/extconf.rb
11
11
  ext/simplecsv/rb_simplecsv.c
12
12
  ext/simplecsv/rb_simplecsv.h
13
13
  lib/simplecsv.rb
14
+ lib/simplecsv/extension.rb
14
15
  lib/simplecsv/version.rb
15
16
  setup.rb
17
+ test/data/01.csv
18
+ test/data/02.csv
19
+ test/data/03.csv
16
20
  test/simplecsv/simplecsv_test.rb
data/README.txt CHANGED
@@ -1,4 +1,4 @@
1
- SimpleCSV 0.1.3 README
1
+ SimpleCSV 0.1.4 README
2
2
 
3
3
  What is:
4
4
  SimpleCSV provides simple api to read/write csv.
data/Rakefile CHANGED
@@ -52,7 +52,7 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
52
52
  #p.extra_deps - An array of rubygem dependencies.
53
53
  #p.spec_extras - A hash of extra values to set in the gemspec.
54
54
 
55
- p.rdoc_pattern = /^(bin|ext)|txt$/
55
+ p.rdoc_pattern = /^(lib|bin|ext)|txt$/
56
56
  p.spec_extras = {
57
57
  :extensions => ['ext/simplecsv/extconf.rb']
58
58
  }
@@ -0,0 +1,23 @@
1
+ class SimpleCSV
2
+ # All methods of module SimpleCSV::Extension are
3
+ # extended & included by SimpleCSV.
4
+ # For example, you can use SimpleCSV.parse_file SimpleCSV#parse_file.
5
+ module Extension
6
+ # Parse csv file.
7
+ # See SimpleCSV.parse for details.
8
+ #
9
+ # ==== Parameters
10
+ # [file_name] <code>String</code> : csv file name.
11
+ # [options] <code>Integer</code> : parser options.
12
+ # [row] <code>Array</code> of <code>String</code>s : parsed data.
13
+ def parse_file(file_name, options = nil, &block)
14
+ File.foreach(file_name, options) do |line|
15
+ parse(line, &block)
16
+ end
17
+ end
18
+ end
19
+
20
+ extend(Extension)
21
+ include(Extension)
22
+ end
23
+
@@ -1,8 +1,8 @@
1
- class SimpleCSV #:nodoc:
1
+ class SimpleCSV
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 3
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1 @@
1
+ 0, 1, 2, 3
@@ -0,0 +1,2 @@
1
+ ab, cde, fg
2
+ hijk, lmn
@@ -0,0 +1,5 @@
1
+ 1
2
+
3
+
4
+
5
+ 5
@@ -1,4 +1,5 @@
1
1
  $:.unshift(File.join(File.dirname(__FILE__), '..', '..', 'ext', 'simplecsv'))
2
+ $:.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
2
3
 
3
4
  require 'simplecsv'
4
5
  require 'test/unit'
@@ -368,4 +369,66 @@ _CSV_
368
369
  assert_equal ["L", "c"], row
369
370
  end
370
371
  end
372
+
373
+ class DefaultParser < SimpleCSV
374
+ def initialize
375
+ @row = []
376
+ end
377
+
378
+ def on_field(str, pr)
379
+ @row << str
380
+ end
381
+
382
+ def on_row(str, pr)
383
+ pr.call(@row)
384
+ @row = []
385
+ end
386
+ end
387
+
388
+ def test_parse_file
389
+ csv_file = File.join(data_path, '01.csv')
390
+ SimpleCSV.parse_file(csv_file) do |row|
391
+ assert_equal ["0", "1", "2", "3"], row
392
+ end
393
+
394
+ simplecsv = SimpleCSV.new
395
+ simplecsv.parse_file(csv_file) do |row|
396
+ assert_equal ["0", "1", "2", "3"], row
397
+ end
398
+
399
+ DefaultParser.parse_file(csv_file) do |row|
400
+ assert_equal ["0", "1", "2", "3"], row
401
+ end
402
+
403
+ csv_file = File.join(data_path, '02.csv')
404
+ rows = []
405
+ SimpleCSV.parse_file(csv_file) do |row|
406
+ rows << row
407
+ end
408
+ assert_equal [ ["ab", "cde", "fg"], ["hijk", "lmn"] ], rows
409
+
410
+ rows = []
411
+ DefaultParser.parse_file(csv_file) do |row|
412
+ rows << row
413
+ end
414
+ assert_equal [ ["ab", "cde", "fg"], ["hijk", "lmn"] ], rows
415
+
416
+ csv_file = File.join(data_path, '03.csv')
417
+ rows = []
418
+ SimpleCSV.parse_file(csv_file) do |row|
419
+ rows << row
420
+ end
421
+ assert_equal [ ["1"], ["5"] ], rows
422
+
423
+ rows = []
424
+ DefaultParser.parse_file(csv_file) do |row|
425
+ rows << row
426
+ end
427
+ assert_equal [ ["1"], ["5"] ], rows
428
+ end
429
+
430
+ private
431
+ def data_path
432
+ File.join(File.dirname(__FILE__), '..', 'data')
433
+ end
371
434
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: simplecsv
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.3
7
- date: 2007-03-18 00:00:00 +09:00
6
+ version: 0.1.4
7
+ date: 2007-04-01 00:00:00 +09:00
8
8
  summary: SimpleCSV privides simple csv reading/writing api.
9
9
  require_paths:
10
10
  - lib
@@ -42,8 +42,12 @@ files:
42
42
  - ext/simplecsv/rb_simplecsv.c
43
43
  - ext/simplecsv/rb_simplecsv.h
44
44
  - lib/simplecsv.rb
45
+ - lib/simplecsv/extension.rb
45
46
  - lib/simplecsv/version.rb
46
47
  - setup.rb
48
+ - test/data/01.csv
49
+ - test/data/02.csv
50
+ - test/data/03.csv
47
51
  - test/simplecsv/simplecsv_test.rb
48
52
  test_files:
49
53
  - test/simplecsv/simplecsv_test.rb