tabular 0.0.3 → 0.0.4
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.
- data/VERSION +1 -1
- data/lib/tabular/table.rb +9 -1
- data/tabular.gemspec +2 -2
- data/test/table_test.rb +5 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/tabular/table.rb
CHANGED
@@ -3,9 +3,17 @@ module Tabular
|
|
3
3
|
class Table
|
4
4
|
attr_reader :rows
|
5
5
|
|
6
|
+
# +file+ : file path as String or File
|
6
7
|
# Assumes .txt = tab-delimited, .csv = CSV, .xls = Excel. Assumes first row is the header.
|
7
8
|
# Normalizes column names to lower-case with underscores.
|
8
|
-
def self.read(
|
9
|
+
def self.read(file, *options)
|
10
|
+
file_path = case file
|
11
|
+
when File
|
12
|
+
file.path
|
13
|
+
else
|
14
|
+
file
|
15
|
+
end
|
16
|
+
|
9
17
|
raise "Could not find '#{file_path}'" unless File.exists?(file_path)
|
10
18
|
options = extract_options(options)
|
11
19
|
|
data/tabular.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{tabular}
|
8
|
-
s.version = "0.0.
|
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 = ["Scott Willson"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-09}
|
13
13
|
s.description = %q{Tabular is a Ruby library for reading, writing, and manipulating CSV, tab-delimited and Excel data.}
|
14
14
|
s.email = %q{scott.willson@gmail.cpm}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/table_test.rb
CHANGED
@@ -33,6 +33,11 @@ module Tabular
|
|
33
33
|
assert_equal Date.new(2006, 1, 20), table[0][:date], "0.0"
|
34
34
|
end
|
35
35
|
|
36
|
+
def test_read_from_excel_file
|
37
|
+
table = Table.read(File.new(File.expand_path(File.dirname(__FILE__) + "/fixtures/excel.xls")))
|
38
|
+
assert_equal Date.new(2006, 1, 20), table[0][:date], "0.0"
|
39
|
+
end
|
40
|
+
|
36
41
|
def test_read_as
|
37
42
|
table = Table.read(File.expand_path(File.dirname(__FILE__) + "/fixtures/sample.lif"), :as => :csv)
|
38
43
|
assert_equal 4, table.rows.size, "rows"
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Scott Willson
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-09 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|