tabular 0.2.4 → 0.2.5

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c908df1467372314b8f4df918f660907f6783762
4
+ data.tar.gz: 9c63253c7add9585952dc55cd2fe4e79701f1901
5
+ SHA512:
6
+ metadata.gz: 9d4c2d9a66f85c6bbe76a045fad990565ebfab721df204a9a818e181794d55b86a272748766e61e82cdae2ed6ca93f3571cb8757639cc9ba3b05300ae5cd81d1
7
+ data.tar.gz: 542cb560461e295a94adfe5f6864d185ae023874dd3d8c4905c65ad992c042a0c0296f5ea0c9e3c78a143aa106c20d128e8027010bb7ed2a03f791c248c0adda
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ gem "rake"
3
4
  gem "ruby-ole", :git => "git://github.com/scottwillson/ruby-ole.git"
4
5
  gem "spreadsheet", :git => "git://github.com/scottwillson/spreadsheet.git"
5
- gem "jeweler"
@@ -14,21 +14,12 @@ GIT
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
- git (1.2.5)
18
- jeweler (1.8.4)
19
- bundler (~> 1.0)
20
- git (>= 1.2.5)
21
- rake
22
- rdoc
23
- json (1.7.7)
24
- rake (10.0.4)
25
- rdoc (4.0.1)
26
- json (~> 1.4)
17
+ rake (10.1.0)
27
18
 
28
19
  PLATFORMS
29
20
  ruby
30
21
 
31
22
  DEPENDENCIES
32
- jeweler
23
+ rake
33
24
  ruby-ole!
34
25
  spreadsheet!
data/README CHANGED
@@ -8,6 +8,8 @@ Much of the API is a copy of FasterCSV without the focus on CSV.
8
8
 
9
9
  Import and display can be configured with Mappers and Renderers. It's a OOP-heavy design that is fast and test-able.
10
10
 
11
+ Tabular can read Excel files if you add the spreadsheet gem to your project.
12
+
11
13
  Install
12
14
  -------
13
15
  sudo gem install tabular
@@ -62,6 +64,7 @@ There's basic test coverage. More comprehensive test coverage needs to be extrac
62
64
 
63
65
  Changes
64
66
  -------
67
+ 0.2.5 Use modern gemspec with no runtime dependencies. Make spreadsheet gem optional.
65
68
  0.2.3 Add :except option for delete_homogenous_columns!
66
69
  0.2.1 Documentation!
67
70
  0.2.0 Add several new features that break previous API
@@ -73,14 +76,14 @@ Changes
73
76
  A | B | C
74
77
  =========
75
78
  1 | 2 | 3
76
- 1 | 6 |
79
+ 1 | 6 |
77
80
  1 | * | 5
78
-
81
+
79
82
  Column A would be deleted
80
83
  * Table#strip! to remove whitespace around cell values. By default, Tabular::Table preserves cell whitespace.
81
84
  * Column#max
82
85
  * Column#precision
83
- * Ruby 1.8 support is deprcated
86
+ * Ruby 1.8 support is deprecated
84
87
 
85
88
  0.0.5 Parse 'invalid' m/d/yy dates
86
89
 
@@ -88,4 +91,4 @@ Changes
88
91
  Copyright
89
92
  ---------
90
93
 
91
- Copyright (c) 2010 Scott Willson. See LICENSE for details.
94
+ Copyright (c) 2014 Scott Willson. See LICENSE for details.
@@ -0,0 +1,3 @@
1
+ module Tabular
2
+ VERSION = "0.2.5"
3
+ end
@@ -1,17 +1,14 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ require "tabular/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
6
  s.name = "tabular"
8
- s.version = "0.2.4"
7
+ s.version = Tabular::VERSION
9
8
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
9
  s.authors = ["Scott Willson"]
12
- s.date = "2013-06-13"
13
10
  s.description = "Tabular is a Ruby library for reading, writing, and manipulating CSV, tab-delimited and Excel data."
14
- s.email = "scott.willson@gmail.cpm"
11
+ s.email = "scott.willson@gmail.c0m"
15
12
  s.extra_rdoc_files = [
16
13
  "LICENSE",
17
14
  "README"
@@ -22,7 +19,6 @@ Gem::Specification.new do |s|
22
19
  "LICENSE",
23
20
  "README",
24
21
  "Rakefile",
25
- "VERSION",
26
22
  "lib/tabular.rb",
27
23
  "lib/tabular/blank.rb",
28
24
  "lib/tabular/column.rb",
@@ -32,40 +28,14 @@ Gem::Specification.new do |s|
32
28
  "lib/tabular/row.rb",
33
29
  "lib/tabular/table.rb",
34
30
  "lib/tabular/zero.rb",
35
- "tabular.gemspec",
36
- "test/column_test.rb",
37
- "test/columns_test.rb",
38
- "test/fixtures/blank.txt",
39
- "test/fixtures/excel.xls",
40
- "test/fixtures/quoted.txt",
41
- "test/fixtures/sample.csv",
42
- "test/fixtures/sample.lif",
43
- "test/helper.rb",
44
- "test/row_test.rb",
45
- "test/table_test.rb",
46
- "test/zero_test.rb"
31
+ "lib/tabular/version.rb",
32
+ "tabular.gemspec"
47
33
  ]
48
34
  s.homepage = "http://github.com/scottwillson/tabular"
49
35
  s.require_paths = ["lib"]
50
- s.rubygems_version = "1.8.25"
51
36
  s.summary = "Read, write, and manipulate CSV, tab-delimited and Excel data"
52
37
 
53
- if s.respond_to? :specification_version then
54
- s.specification_version = 3
55
-
56
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
- s.add_runtime_dependency(%q<ruby-ole>, [">= 0"])
58
- s.add_runtime_dependency(%q<spreadsheet>, [">= 0"])
59
- s.add_runtime_dependency(%q<jeweler>, [">= 0"])
60
- else
61
- s.add_dependency(%q<ruby-ole>, [">= 0"])
62
- s.add_dependency(%q<spreadsheet>, [">= 0"])
63
- s.add_dependency(%q<jeweler>, [">= 0"])
64
- end
65
- else
66
- s.add_dependency(%q<ruby-ole>, [">= 0"])
67
- s.add_dependency(%q<spreadsheet>, [">= 0"])
68
- s.add_dependency(%q<jeweler>, [">= 0"])
69
- end
38
+ s.add_development_dependency "ruby-ole", "~> 1.2.11.3"
39
+ s.add_development_dependency "spreadsheet", "~> 0.6.6"
70
40
  end
71
41
 
metadata CHANGED
@@ -1,67 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabular
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.2.4
4
+ version: 0.2.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Scott Willson
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-13 00:00:00.000000000 Z
11
+ date: 2014-05-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: ruby-ole
16
- prerelease: false
17
15
  requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
22
- none: false
23
- type: :runtime
19
+ version: 1.2.11.3
20
+ type: :development
21
+ prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
23
  requirements:
26
- - - ! '>='
24
+ - - "~>"
27
25
  - !ruby/object:Gem::Version
28
- version: '0'
29
- none: false
26
+ version: 1.2.11.3
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: spreadsheet
32
- prerelease: false
33
29
  requirement: !ruby/object:Gem::Requirement
34
30
  requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- none: false
39
- type: :runtime
40
- version_requirements: !ruby/object:Gem::Requirement
41
- requirements:
42
- - - ! '>='
31
+ - - "~>"
43
32
  - !ruby/object:Gem::Version
44
- version: '0'
45
- none: false
46
- - !ruby/object:Gem::Dependency
47
- name: jeweler
33
+ version: 0.6.6
34
+ type: :development
48
35
  prerelease: false
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- none: false
55
- type: :runtime
56
36
  version_requirements: !ruby/object:Gem::Requirement
57
37
  requirements:
58
- - - ! '>='
38
+ - - "~>"
59
39
  - !ruby/object:Gem::Version
60
- version: '0'
61
- none: false
40
+ version: 0.6.6
62
41
  description: Tabular is a Ruby library for reading, writing, and manipulating CSV,
63
42
  tab-delimited and Excel data.
64
- email: scott.willson@gmail.cpm
43
+ email: scott.willson@gmail.c0m
65
44
  executables: []
66
45
  extensions: []
67
46
  extra_rdoc_files:
@@ -73,7 +52,6 @@ files:
73
52
  - LICENSE
74
53
  - README
75
54
  - Rakefile
76
- - VERSION
77
55
  - lib/tabular.rb
78
56
  - lib/tabular/blank.rb
79
57
  - lib/tabular/column.rb
@@ -82,44 +60,30 @@ files:
82
60
  - lib/tabular/renderer.rb
83
61
  - lib/tabular/row.rb
84
62
  - lib/tabular/table.rb
63
+ - lib/tabular/version.rb
85
64
  - lib/tabular/zero.rb
86
65
  - tabular.gemspec
87
- - test/column_test.rb
88
- - test/columns_test.rb
89
- - test/fixtures/blank.txt
90
- - test/fixtures/excel.xls
91
- - test/fixtures/quoted.txt
92
- - test/fixtures/sample.csv
93
- - test/fixtures/sample.lif
94
- - test/helper.rb
95
- - test/row_test.rb
96
- - test/table_test.rb
97
- - test/zero_test.rb
98
66
  homepage: http://github.com/scottwillson/tabular
99
67
  licenses: []
68
+ metadata: {}
100
69
  post_install_message:
101
70
  rdoc_options: []
102
71
  require_paths:
103
72
  - lib
104
73
  required_ruby_version: !ruby/object:Gem::Requirement
105
74
  requirements:
106
- - - ! '>='
75
+ - - ">="
107
76
  - !ruby/object:Gem::Version
108
- hash: 3719895612721090780
109
- segments:
110
- - 0
111
77
  version: '0'
112
- none: false
113
78
  required_rubygems_version: !ruby/object:Gem::Requirement
114
79
  requirements:
115
- - - ! '>='
80
+ - - ">="
116
81
  - !ruby/object:Gem::Version
117
82
  version: '0'
118
- none: false
119
83
  requirements: []
120
84
  rubyforge_project:
121
- rubygems_version: 1.8.25
85
+ rubygems_version: 2.2.2
122
86
  signing_key:
123
- specification_version: 3
87
+ specification_version: 4
124
88
  summary: Read, write, and manipulate CSV, tab-delimited and Excel data
125
89
  test_files: []
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.4
@@ -1,80 +0,0 @@
1
- require "helper"
2
-
3
- module Tabular
4
- class ColumnTest < Test::Unit::TestCase
5
- def test_new_nil
6
- column = Column.new(nil, nil)
7
- assert_equal "", column.to_s, "blank column to_s"
8
- assert_equal nil, column.key, "blank column key"
9
- end
10
-
11
- def test_new
12
- assert_equal :date, Column.new(nil, nil, "date").key, "column key"
13
- assert_equal :date, Column.new(nil, nil, :date).key, "column key"
14
- assert_equal :date, Column.new(nil, nil, "Date").key, "column key"
15
- assert_equal :date, Column.new(nil, nil, " Date ").key, "column key"
16
- assert_equal :date, Column.new(nil, nil, "DATE").key, "column key"
17
- assert_equal :start_date, Column.new(nil, nil, "StartDate").key, "column key"
18
- assert_equal :start_date, Column.new(nil, nil, "Start Date").key, "column key"
19
- end
20
-
21
- def test_mapping
22
- assert_equal :city, Column.new(nil, nil, :location, :location => :city).key, "column key"
23
- end
24
-
25
- def test_type
26
- column = Column.new(nil, nil, "name")
27
- assert_equal :name, column.key, "key"
28
- assert_equal :string, column.column_type, "column_type"
29
-
30
- column = Column.new(nil, nil, "date")
31
- assert_equal :date, column.key, "key"
32
- assert_equal :date, column.column_type, "column_type"
33
-
34
- column = Column.new(nil, nil, "phone", :phone => { :column_type => :integer })
35
- assert_equal :phone, column.key, "key"
36
- assert_equal :integer, column.column_type, "column_type"
37
- end
38
-
39
- def test_cells
40
- data = [
41
- { :place => "1", :name => "Bernard Hinault" },
42
- { :place => "2", :name => "Greg Lemond" }
43
- ]
44
- table = Table.new(data)
45
- column = table.columns[:place]
46
- assert_equal [ "1", "2" ], column.cells
47
- end
48
-
49
- def test_max
50
- data = [
51
- { :place => "1", :name => "Bernard Hinault" },
52
- { :place => "2", :name => "Greg Lemond" }
53
- ]
54
- table = Table.new(data)
55
-
56
- assert_equal "2", table.columns[:place].max
57
- assert_equal "Greg Lemond", table.columns[:name].max
58
- end
59
-
60
- def test_precision
61
- data = [
62
- { :place => "1", :age => 22, :points => 10.75 },
63
- { :place => "2", :age => 30, :points => 12.000 }
64
- ]
65
- table = Table.new(data)
66
-
67
- assert_equal 0, table.columns[:place].precision
68
- assert_equal 0, table.columns[:age].precision
69
- assert_equal 2, table.columns[:points].precision
70
- end
71
-
72
- def test_precision_with_mixed_zeros
73
- data = [
74
- { :place => "1", :age => 22, :points => 12.001 }
75
- ]
76
- table = Table.new(data)
77
- assert_equal 3, table.columns[:points].precision
78
- end
79
- end
80
- end
@@ -1,89 +0,0 @@
1
- require "helper"
2
-
3
- module Tabular
4
- class ColumnsTest < Test::Unit::TestCase
5
- def test_new_blank
6
- columns = Columns.new(nil, [])
7
- assert_equal false, columns.has_key?(:name), "has_key? :name"
8
- assert_equal nil, columns[:name], "[:name]"
9
- assert_equal nil, columns.index(nil), "index"
10
- assert_equal nil, columns.index(""), "index"
11
- assert_equal nil, columns.index(:name), "index"
12
- columns.each { |c| c.nil? }
13
- end
14
-
15
- def test_new
16
- columns = Columns.new(nil, ["date", "first name", "LastName"])
17
- assert_equal false, columns.has_key?(:location), "has_key? :location"
18
- assert_equal true, columns.has_key?(:date), "has_key? :date"
19
- assert_equal true, columns.has_key?(:first_name), "has_key? :first_name"
20
- assert_equal true, columns.has_key?(:last_name), "has_key? :last_name"
21
- assert_equal false, columns.has_key?("first name"), "has_key? 'first name'"
22
-
23
- column = columns[:first_name]
24
- assert_equal :first_name, column.key, "column[:first_name] Column key"
25
-
26
- assert_equal 1, columns.index(:first_name), "index of :first_name"
27
- end
28
-
29
- def test_columns_map
30
- columns = Columns.new(nil, ["date"], :start_date => :date)
31
- assert_equal true, columns.has_key?(:date), "has_key? :date"
32
- assert_equal false, columns.has_key?(:start_date), "has_key? :start_date"
33
- end
34
-
35
- def test_render
36
- columns = Columns.new(Table.new, ["date", "first name", "LastName"])
37
- assert_equal "date", columns.first.render
38
- end
39
-
40
- def test_renderer
41
- columns = Columns.new(nil, ["date", "first name", "LastName"])
42
- columns.renderer = TestRenderer
43
- assert_equal "Date", columns.first.render
44
- end
45
-
46
- def test_delete
47
- columns = Columns.new(nil, ["date", "first name", "LastName"])
48
- columns.delete :date
49
-
50
- columns_from_each = []
51
- columns.each { |c| columns_from_each << c.key }
52
- assert_equal [ :first_name, :last_name ], columns_from_each, "column keys from #each"
53
-
54
- assert_equal false, columns.has_key?(:date), "has_key? :date"
55
- assert_equal true, columns.has_key?(:first_name), "has_key? :first_name"
56
- assert_equal 0, columns.index(:first_name), "index of :first_name"
57
- assert_equal 1, columns.index(:last_name), "index of :last_name"
58
- end
59
-
60
- def test_push_onto_blank
61
- columns = Columns.new(nil, [])
62
- columns << "city state"
63
- assert_equal true, columns.has_key?(:city_state), "has_key? :city_state"
64
- assert_equal 0, columns.index(:city_state), "index of new column"
65
-
66
- column = columns[:city_state]
67
- assert_equal :city_state, column.key, "column[:city_state] Column key"
68
- end
69
-
70
- def test_push
71
- columns = Columns.new(nil, ["first", "second"])
72
- columns << "third"
73
- assert_equal true, columns.has_key?(:third), "has_key? :third"
74
- assert_equal 0, columns.index(:first), "index of existing column"
75
- assert_equal 1, columns.index(:second), "index of existing column"
76
- assert_equal 2, columns.index(:third), "index of new column"
77
-
78
- column = columns[:third]
79
- assert_equal :third, column.key, "column[:third] Column key"
80
- end
81
-
82
- class TestRenderer
83
- def self.render_header(column)
84
- key = column.key.to_s
85
- (key.slice(0) || key.chars('')).upcase + (key.slice(1..-1) || key.chars('')).downcase
86
- end
87
- end
88
- end
89
- end
File without changes
Binary file
@@ -1,3 +0,0 @@
1
- Date Race CityState Discipline Promoter PromoterPhone PromoterEmail SponsoringTeam SanctionedBy Website FlyerApproved
2
- 1/1/99 Butte Hillclimb Butte
3
- 2/12/99 Valentine Criterium "Missoula, MT" Criterium Al Pendergrass (414) 333-1100 al@gmail.com 1200000 USA Cycling http://geocities.com/bikes 1
@@ -1,5 +0,0 @@
1
- "Place ","Number","Last Name","First Name","Team","Category Raced"
2
- "1","189","Willson","Scott","Gentle Lover","Senior Men 1/2/3","11",,"11"
3
- "2","190","Phinney","Harry","CCCP","Senior Men 1/2/3","9",,
4
- "3","10a","Holland","Steve","Huntair","Senior Men 1/2/3",,"3",
5
- "dnf","100","Bourcier","Paul","Hutch's","Senior Men 1/2/3",,,"1"
@@ -1,5 +0,0 @@
1
- "Place ","Number","Last Name","First Name","Team","Category Raced"
2
- "1","189","Willson","Scott","Gentle Lover","Senior Men 1/2/3","11",,"11"
3
- "2","190","Phinney","Harry","CCCP","Senior Men 1/2/3","9",,
4
- "3","10a","Holland","Steve","Huntair","Senior Men 1/2/3",,"3",
5
- "dnf","100","Bourcier","Paul","Hutch's","Senior Men 1/2/3",,,"1"
@@ -1,9 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
-
4
- $LOAD_PATH.unshift(File.dirname(__FILE__))
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- require 'tabular'
7
-
8
- class Test::Unit::TestCase
9
- end
@@ -1,140 +0,0 @@
1
- require "helper"
2
-
3
- module Tabular
4
- class RowTest < Test::Unit::TestCase
5
- def test_new
6
- row = Row.new(Table.new)
7
- assert_equal nil, row[:city], "[]"
8
-
9
- assert_equal "", row.join, "join"
10
- assert_equal({}, row.to_hash, "to_hash")
11
- assert_equal "{}", row.inspect, "inspect"
12
- assert_equal "", row.to_s, "to_s"
13
-
14
- # Test each
15
- row.each { |c| c.nil? }
16
- end
17
-
18
- def test_new_from_hash
19
- row = Row.new(Table.new, { :place => "1" })
20
- assert_equal nil, row[:city], "[]"
21
-
22
- assert_equal "1", row.join, "join"
23
- assert_equal({ :place => "1" }, row.to_hash, "to_hash")
24
- assert_equal "{:place=>\"1\"}", row.inspect, "inspect"
25
- assert_equal "1", row.to_s, "to_s"
26
-
27
- # Test each
28
- row.each { |c| c.nil? }
29
- end
30
-
31
- def test_new_from_hash_with_string_keys
32
- row = Row.new(Table.new, { "place" => "1" })
33
- assert_equal nil, row[:city], "[]"
34
-
35
- assert_equal "1", row.join, "join"
36
- assert_equal({ :place => "1" }, row.to_hash, "to_hash")
37
- assert_equal "{:place=>\"1\"}", row.inspect, "inspect"
38
- assert_equal "1", row.to_s, "to_s"
39
-
40
- # Test each
41
- row.each { |c| c.nil? }
42
-
43
- assert_equal({ "place" => "1" }, row.source, "source")
44
- end
45
-
46
- def test_set
47
- table = Table.new([[ "planet", "star" ]])
48
- row = Row.new(table, [ "Mars", "Sun" ])
49
-
50
- assert_equal "Sun", row[:star], "row[:star]"
51
-
52
- row[:star] = "Solaris"
53
- assert_equal "Solaris", row[:star], "row[:star]"
54
-
55
- row[:astronaut] = "Buzz"
56
- assert_equal "Buzz", row[:astronaut], "row[:astronaut]"
57
- end
58
-
59
- def test_join
60
- table = Table.new([[ "planet", "star" ]])
61
- row = Row.new(table, [ "Mars", "Sun" ])
62
- assert_equal "MarsSun", row.join, "join"
63
- assert_equal "Mars-Sun", row.join("-"), "join '-'"
64
- end
65
-
66
- def test_to_hash
67
- table = Table.new([[ "planet", "star" ]])
68
- row = Row.new(table, [ "Mars", "Sun" ])
69
- assert_equal({ :planet => "Mars", :star => "Sun"}, row.to_hash, "to_hash")
70
- end
71
-
72
- def test_inspect
73
- table = Table.new([[ "planet", "star" ]])
74
- row = Row.new(table, [ "Mars", "Sun" ])
75
- assert_match %r{:planet=>"Mars"}, row.inspect, "inspect"
76
- assert_match %r{:star=>"Sun"}, row.inspect, "inspect"
77
- end
78
-
79
- def test_to_s
80
- table = Table.new([[ "planet", "star" ]])
81
- row = Row.new(table, [ "Mars", "Sun" ])
82
- assert_equal "Mars, Sun", row.to_s, "to_s"
83
- end
84
-
85
- def test_render
86
- table = Table.new([[ "planet", "star" ]])
87
- table.renderers[:planet] = StarRenderer
88
- row = Row.new(table, [ "Mars", "Sun" ])
89
- assert_equal "****", row.render("planet"), "render"
90
- assert_equal "****", row.render(:planet), "render"
91
- assert_equal "****", row.render(row.columns.first), "render"
92
- end
93
-
94
- def test_render_with_no_renderer
95
- table = Table.new([[ "planet", "star" ]])
96
- row = Row.new(table, [ "Mars", "Sun" ])
97
- assert_equal "Mars", row.render("planet"), "render"
98
- end
99
-
100
- def test_previous
101
- table = Table.new([[ "planet", "star" ]])
102
- table << [ "Mars", "Sun" ]
103
- table << [ "Jupiter", "Sun" ]
104
- assert_equal nil, table.rows.first.previous, "previous of first Row"
105
- assert_equal "Mars", table.rows.last.previous[:planet], "previous"
106
- end
107
-
108
- def test_each_with_key
109
- table = Table.new([[ "planet", "star" ]])
110
- table << [ "Mars", "Sun" ]
111
- results = []
112
- table.rows.first.each_with_key do |key, value|
113
- results << [ key, value ]
114
- end
115
- assert_equal [ [ :planet, "Mars" ], [ :star, "Sun" ] ], results
116
- end
117
-
118
- def test_invalid_date_raises_exception
119
- table = Table.new([[ "launched" ]], :columns => { :launched => { :column_type => :date } })
120
- row = Row.new(table, [ "99/z/99" ])
121
- assert_raise ArgumentError do
122
- row[:launched]
123
- end
124
- end
125
-
126
- def test_parse_compact_american_dates
127
- table = Table.new([[ "launched" ]], :columns => { :launched => { :column_type => :date } })
128
- assert_equal Date.new(1999, 1, 1), Row.new(table, [ "1/1/99" ])[:launched], "1/1/99"
129
- assert_equal Date.new(2000, 8, 28), Row.new(table, [ "8/28/00" ])[:launched], "8/28/00"
130
- assert_equal Date.new(2008, 12, 31), Row.new(table, [ "12/31/08" ])[:launched], "12/31/08"
131
- end
132
-
133
- class StarRenderer
134
- def self.render(column, row)
135
- row[column.key].gsub(/\w/, "*")
136
- end
137
- end
138
- end
139
- end
140
-
@@ -1,214 +0,0 @@
1
- require "helper"
2
-
3
- module Tabular
4
- class TableTest < Test::Unit::TestCase
5
- def test_read_from_blank_txt_file
6
- Table.read(File.expand_path(File.dirname(__FILE__) + "/fixtures/blank.txt"))
7
- end
8
-
9
- def test_read_quoted_txt_file
10
- Table.read(File.expand_path(File.dirname(__FILE__) + "/fixtures/quoted.txt"))
11
- end
12
-
13
- # "Place ","Number","Last Name","First Name","Team","Category Raced"
14
- # "1","189","Willson","Scott","Gentle Lover","Senior Men 1/2/3","11",,"11"
15
- # "2","190","Phinney","Harry","CCCP","Senior Men 1/2/3","9",,
16
- # "3","10a","Holland","Steve","Huntair","Senior Men 1/2/3",,"3",
17
- # "dnf","100","Bourcier","Paul","Hutch's","Senior Men 1/2/3",,,"1"
18
- def test_read_from_csv
19
- table = Table.read(File.expand_path(File.dirname(__FILE__) + "/fixtures/sample.csv"))
20
- assert_equal 4, table.rows.size, "rows"
21
-
22
- assert_equal "1", table[0][:place], "0.0"
23
- assert_equal "189", table[0][:number], "0.1"
24
- assert_equal "Willson", table[0][:last_name], "0.2"
25
- assert_equal "Scott", table[0][:first_name], "0.3"
26
- assert_equal "Gentle Lover", table[0][:team], "0.4"
27
-
28
- assert_equal "dnf", table[3][:place], "3.0"
29
- assert_equal "100", table[3][:number], "3.1"
30
- assert_equal "Bourcier", table[3][:last_name], "3.2"
31
- assert_equal "Paul", table[3][:first_name], "3.3"
32
- assert_equal "Hutch's", table[3][:team], "3.4"
33
- end
34
-
35
- def test_read_from_excel
36
- table = Table.read(File.expand_path(File.dirname(__FILE__) + "/fixtures/excel.xls"))
37
- assert_equal Date.new(2006, 1, 20), table[0][:date], "0.0"
38
- end
39
-
40
- def test_read_from_excel_file
41
- table = Table.read(File.new(File.expand_path(File.dirname(__FILE__) + "/fixtures/excel.xls")))
42
- assert_equal Date.new(2006, 1, 20), table[0][:date], "0.0"
43
- end
44
-
45
- def test_read_as
46
- table = Table.read(File.expand_path(File.dirname(__FILE__) + "/fixtures/sample.lif"), :as => :csv)
47
- assert_equal 4, table.rows.size, "rows"
48
- end
49
-
50
- def test_column_map
51
- data = [
52
- [ "nom", "equipe", "homme" ],
53
- [ "Hinault", "Team Z", "true" ]
54
- ]
55
- table = Table.new(data, :columns => { :nom => :name, :equipe => :team, :homme => { :column_type => :boolean } })
56
- assert_equal "Hinault", table.rows.first[:name], ":name"
57
- assert_equal "Team Z", table.rows.first[:team], ":team"
58
- assert_equal true, table.rows.first[:homme], "boolean"
59
- end
60
-
61
- def test_new_with_hashes
62
- data = [
63
- { :place => "1", :name => "Bernard Hinault" },
64
- { :place => "2", :name => "Greg Lemond" }
65
- ]
66
- table = Table.new(data)
67
- assert_equal 2, table.rows.size, "size"
68
- assert_equal data[0], table.rows[0].to_hash
69
- assert_equal data[1], table.rows[1].to_hash
70
- end
71
-
72
- def test_row_mapper_class_method
73
- data = [
74
- [ :place, "1", :name, "Bernard Hinault" ],
75
- ]
76
-
77
- table = Table.new
78
- table.row_mapper = StatelessTestMapper
79
- table.rows = data
80
-
81
- assert_equal 1, table.rows.size, "size"
82
- assert_equal({ :place => "1", :name => "Bernard Hinault" }, table.rows[0].to_hash)
83
- end
84
-
85
- def test_row_mapper
86
- data = [
87
- [ :place, "1", :name, "Bernard Hinault" ],
88
- ]
89
-
90
- table = Table.new
91
- table.row_mapper = TestMapper.new
92
- table.rows = data
93
-
94
- assert_equal 1, table.rows.size, "size"
95
- assert_equal({ :place => "1", :name => "Bernard Hinault" }, table.rows[0].to_hash)
96
- end
97
-
98
- def test_delete_blank_columns
99
- data = [
100
- [ "nom", "equipe", "homme", "age" ],
101
- [ "Hinault", "", "true", "0" ]
102
- ]
103
-
104
- table = Table.new
105
- table.rows = data
106
-
107
- table.delete_blank_columns!
108
-
109
- assert_equal 1, table.rows.size, "size"
110
- assert_equal({ :nom => "Hinault", :homme => "true" }, table.rows[0].to_hash)
111
- end
112
-
113
- def test_delete_blank_columns_empty_table
114
- Table.new.delete_blank_columns!
115
- end
116
-
117
- def test_delete_homogenous_columns
118
- Table.new.delete_homogenous_columns!
119
-
120
- data = [
121
- [ "nom", "equipe", "homme", "age" ],
122
- [ "Hinault", "", "true", "30" ],
123
- [ "Lemond", "", "true", "20" ],
124
- [ "Hinault", "", "true", "30" ]
125
- ]
126
-
127
- table = Table.new
128
- table.rows = data
129
-
130
- table.delete_homogenous_columns!
131
-
132
- assert_equal 3, table.rows.size, "size"
133
- assert_equal({ :nom => "Hinault", :age => "30" }, table.rows[0].to_hash)
134
- assert_equal({ :nom => "Lemond", :age => "20" }, table.rows[1].to_hash)
135
- assert_equal({ :nom => "Hinault", :age => "30" }, table.rows[2].to_hash)
136
- end
137
-
138
- def test_delete_homogenous_columns_with_exceptions
139
- data = [
140
- [ "nom", "equipe", "homme", "age" ],
141
- [ "Hinault", "", "true", "30" ],
142
- [ "Lemond", "", "true", "20" ],
143
- [ "Hinault", "", "true", "30" ]
144
- ]
145
-
146
- table = Table.new
147
- table.rows = data
148
-
149
- table.delete_homogenous_columns!(:except => [ :homme ])
150
-
151
- assert_equal 3, table.rows.size, "size"
152
- assert_equal({ :nom => "Hinault", :homme => "true", :age => "30" }, table.rows[0].to_hash)
153
- assert_equal({ :nom => "Lemond", :homme => "true", :age => "20" }, table.rows[1].to_hash)
154
- assert_equal({ :nom => "Hinault", :homme => "true", :age => "30" }, table.rows[2].to_hash)
155
- end
156
-
157
- def test_delete_homogenous_columns_single_row
158
- Table.new.delete_homogenous_columns!
159
-
160
- data = [
161
- [ "nom", "equipe", "homme", "age" ],
162
- [ "Hinault", "", "true", "30" ],
163
- ]
164
-
165
- table = Table.new
166
- table.rows = data
167
-
168
- table.delete_homogenous_columns!
169
-
170
- assert_equal 1, table.rows.size, "size"
171
- assert_equal({ :nom => "Hinault", :equipe => "", :homme => "true", :age => "30" }, table.rows[0].to_hash)
172
- end
173
-
174
- def test_delete_column
175
- data = [
176
- { :place => "1", :name => "Bernard Hinault" },
177
- { :place => "2", :name => "Greg Lemond" }
178
- ]
179
- table = Table.new(data)
180
-
181
- table.delete_column :place
182
-
183
- assert_equal 2, table.rows.size, "size"
184
- assert_equal({ :name => "Bernard Hinault" }, table.rows[0].to_hash)
185
- assert_equal({ :name => "Greg Lemond" }, table.rows[1].to_hash)
186
- end
187
-
188
- def test_strip
189
- data = [
190
- { :name => " Bernard Hinault " }
191
- ]
192
- table = Table.new(data)
193
-
194
- assert_equal 1, table.rows.size, "size"
195
- assert_equal({ :name => " Bernard Hinault " }, table.rows[0].to_hash)
196
-
197
- table.strip!
198
-
199
- assert_equal({ :name => "Bernard Hinault" }, table.rows[0].to_hash)
200
- end
201
-
202
- class StatelessTestMapper
203
- def self.map(array)
204
- Hash[*array]
205
- end
206
- end
207
-
208
- class TestMapper
209
- def map(array)
210
- Hash[*array]
211
- end
212
- end
213
- end
214
- end
@@ -1,23 +0,0 @@
1
- require "helper"
2
-
3
- class ZeroTest < Test::Unit::TestCase
4
- include Tabular::Zero
5
-
6
- def test_zero
7
- assert is_zero?(0)
8
- assert is_zero?(0.0)
9
- assert is_zero?("0")
10
- assert is_zero?("0.0")
11
- assert is_zero?("00000.00000")
12
-
13
- assert !is_zero?(1)
14
- assert !is_zero?(-1)
15
- assert !is_zero?(0.1)
16
- assert !is_zero?("1")
17
- assert !is_zero?("ABC")
18
- assert !is_zero?(nil)
19
- assert !is_zero?("")
20
- assert !is_zero?(false)
21
- assert !is_zero?(true)
22
- end
23
- end