roo 2.0.1 → 2.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +17 -0
- data/.github/ISSUE_TEMPLATE +10 -0
- data/.gitignore +4 -0
- data/.travis.yml +10 -6
- data/CHANGELOG.md +116 -1
- data/Gemfile +3 -4
- data/Gemfile_ruby2 +30 -0
- data/Guardfile +1 -2
- data/README.md +56 -22
- data/Rakefile +1 -1
- data/lib/roo/base.rb +108 -245
- data/lib/roo/constants.rb +5 -0
- data/lib/roo/csv.rb +94 -87
- data/lib/roo/errors.rb +11 -0
- data/lib/roo/excelx/cell/base.rb +94 -0
- data/lib/roo/excelx/cell/boolean.rb +27 -0
- data/lib/roo/excelx/cell/date.rb +28 -0
- data/lib/roo/excelx/cell/datetime.rb +111 -0
- data/lib/roo/excelx/cell/empty.rb +19 -0
- data/lib/roo/excelx/cell/number.rb +87 -0
- data/lib/roo/excelx/cell/string.rb +19 -0
- data/lib/roo/excelx/cell/time.rb +43 -0
- data/lib/roo/excelx/cell.rb +33 -4
- data/lib/roo/excelx/comments.rb +33 -0
- data/lib/roo/excelx/coordinate.rb +12 -0
- data/lib/roo/excelx/extractor.rb +3 -4
- data/lib/roo/excelx/format.rb +64 -0
- data/lib/roo/excelx/shared.rb +32 -0
- data/lib/roo/excelx/shared_strings.rb +124 -4
- data/lib/roo/excelx/sheet.rb +12 -7
- data/lib/roo/excelx/sheet_doc.rb +108 -97
- data/lib/roo/excelx/styles.rb +1 -1
- data/lib/roo/excelx.rb +61 -103
- data/lib/roo/formatters/base.rb +15 -0
- data/lib/roo/formatters/csv.rb +84 -0
- data/lib/roo/formatters/matrix.rb +23 -0
- data/lib/roo/formatters/xml.rb +31 -0
- data/lib/roo/formatters/yaml.rb +40 -0
- data/lib/roo/libre_office.rb +1 -2
- data/lib/roo/link.rb +21 -2
- data/lib/roo/open_office.rb +468 -523
- data/lib/roo/spreadsheet.rb +3 -1
- data/lib/roo/tempdir.rb +21 -0
- data/lib/roo/utils.rb +7 -7
- data/lib/roo/version.rb +1 -1
- data/lib/roo.rb +8 -3
- data/roo.gemspec +2 -1
- data/spec/helpers.rb +5 -0
- data/spec/lib/roo/base_spec.rb +229 -0
- data/spec/lib/roo/csv_spec.rb +19 -0
- data/spec/lib/roo/excelx_spec.rb +97 -11
- data/spec/lib/roo/openoffice_spec.rb +18 -1
- data/spec/lib/roo/spreadsheet_spec.rb +20 -0
- data/spec/lib/roo/utils_spec.rb +1 -1
- data/spec/spec_helper.rb +5 -5
- data/test/all_ss.rb +12 -11
- data/test/excelx/cell/test_base.rb +63 -0
- data/test/excelx/cell/test_boolean.rb +36 -0
- data/test/excelx/cell/test_date.rb +38 -0
- data/test/excelx/cell/test_datetime.rb +45 -0
- data/test/excelx/cell/test_empty.rb +7 -0
- data/test/excelx/cell/test_number.rb +74 -0
- data/test/excelx/cell/test_string.rb +28 -0
- data/test/excelx/cell/test_time.rb +30 -0
- data/test/formatters/test_csv.rb +119 -0
- data/test/formatters/test_matrix.rb +76 -0
- data/test/formatters/test_xml.rb +78 -0
- data/test/formatters/test_yaml.rb +20 -0
- data/test/helpers/test_accessing_files.rb +60 -0
- data/test/helpers/test_comments.rb +43 -0
- data/test/helpers/test_formulas.rb +9 -0
- data/test/helpers/test_labels.rb +103 -0
- data/test/helpers/test_sheets.rb +55 -0
- data/test/helpers/test_styles.rb +62 -0
- data/test/roo/test_base.rb +182 -0
- data/test/roo/test_csv.rb +60 -0
- data/test/roo/test_excelx.rb +325 -0
- data/test/roo/test_libre_office.rb +9 -0
- data/test/roo/test_open_office.rb +289 -0
- data/test/test_helper.rb +116 -18
- data/test/test_roo.rb +362 -2088
- metadata +70 -4
- data/test/test_generic_spreadsheet.rb +0 -237
@@ -0,0 +1,43 @@
|
|
1
|
+
module TestComments
|
2
|
+
def test_comment
|
3
|
+
options = { name: "comments", format: [:openoffice, :libreoffice, :excelx] }
|
4
|
+
with_each_spreadsheet(options) do |oo|
|
5
|
+
assert_equal "Kommentar fuer B4", oo.comment("b", 4)
|
6
|
+
assert_equal "Kommentar fuer B5", oo.comment("b", 5)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_no_comment
|
11
|
+
options = { name: "comments", format: [:openoffice, :excelx] }
|
12
|
+
with_each_spreadsheet(options) do |oo|
|
13
|
+
# There are no comments at the second sheet.
|
14
|
+
assert_nil oo.comment("b", 4, oo.sheets[1])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_comments
|
19
|
+
options = { name: "comments", format: [:openoffice, :libreoffice, :excelx] }
|
20
|
+
expexted_comments = [
|
21
|
+
[4, 2, "Kommentar fuer B4"],
|
22
|
+
[5, 2, "Kommentar fuer B5"],
|
23
|
+
]
|
24
|
+
|
25
|
+
with_each_spreadsheet(options) do |oo|
|
26
|
+
assert_equal expexted_comments, oo.comments(oo.sheets.first), "comments error in class #{oo.class}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_empty_sheet_comments
|
31
|
+
options = { name: "emptysheets", format: [:openoffice, :excelx] }
|
32
|
+
with_each_spreadsheet(options) do |oo|
|
33
|
+
assert_equal [], oo.comments, "An empty sheet's formulas should be an empty array"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_comments_from_google_sheet_exported_as_xlsx
|
38
|
+
expected_comments = [[1, 1, "this is a comment\n\t-Steven Daniels"]]
|
39
|
+
with_each_spreadsheet(name: "comments-google", format: [:excelx]) do |oo|
|
40
|
+
assert_equal expected_comments, oo.comments(oo.sheets.first), "comments error in class #{oo.class}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module TestFormulas
|
2
|
+
def test_empty_sheet_formulas
|
3
|
+
options = { name: "emptysheets", format: [:openoffice, :excelx] }
|
4
|
+
with_each_spreadsheet(options) do |oo|
|
5
|
+
oo.default_sheet = oo.sheets.first
|
6
|
+
assert_equal [], oo.formulas, "An empty sheet's formulas should be an empty array"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module TestLabels
|
2
|
+
def test_labels
|
3
|
+
options = { name: "named_cells", format: [:openoffice, :excelx, :libreoffice] }
|
4
|
+
expected_labels = [
|
5
|
+
["anton", [5, 3, "Sheet1"]],
|
6
|
+
["berta", [4, 2, "Sheet1"]],
|
7
|
+
["caesar", [7, 2, "Sheet1"]],
|
8
|
+
]
|
9
|
+
with_each_spreadsheet(options) do |oo|
|
10
|
+
assert_equal expected_labels, oo.labels, "error with labels array in class #{oo.class}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_labeled_cells
|
15
|
+
options = { name: "named_cells", format: [:openoffice, :excelx, :libreoffice] }
|
16
|
+
with_each_spreadsheet(options) do |oo|
|
17
|
+
oo.default_sheet = oo.sheets.first
|
18
|
+
begin
|
19
|
+
row, col = oo.label("anton")
|
20
|
+
rescue ArgumentError
|
21
|
+
puts "labels error at #{oo.class}"
|
22
|
+
raise
|
23
|
+
end
|
24
|
+
assert_equal 5, row
|
25
|
+
assert_equal 3, col
|
26
|
+
|
27
|
+
row, col = oo.label("anton")
|
28
|
+
assert_equal "Anton", oo.cell(row, col)
|
29
|
+
|
30
|
+
row, col = oo.label("berta")
|
31
|
+
assert_equal "Bertha", oo.cell(row, col)
|
32
|
+
|
33
|
+
row, col = oo.label("caesar")
|
34
|
+
assert_equal "Cäsar", oo.cell(row, col)
|
35
|
+
|
36
|
+
row, col = oo.label("never")
|
37
|
+
assert_nil row
|
38
|
+
assert_nil col
|
39
|
+
|
40
|
+
row, col, sheet = oo.label("anton")
|
41
|
+
assert_equal 5, row
|
42
|
+
assert_equal 3, col
|
43
|
+
assert_equal "Sheet1", sheet
|
44
|
+
|
45
|
+
assert_equal "Anton", oo.anton
|
46
|
+
assert_raises(NoMethodError) do
|
47
|
+
row, col = oo.never
|
48
|
+
end
|
49
|
+
|
50
|
+
# Reihenfolge row, col,sheet analog zu #label
|
51
|
+
expected_labels = [
|
52
|
+
["anton", [5, 3, "Sheet1"]],
|
53
|
+
["berta", [4, 2, "Sheet1"]],
|
54
|
+
["caesar", [7, 2, "Sheet1"]],
|
55
|
+
]
|
56
|
+
assert_equal expected_labels, oo.labels, "error with labels array in class #{oo.class}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_label
|
61
|
+
options = { name: "named_cells", format: [:openoffice, :excelx, :libreoffice] }
|
62
|
+
with_each_spreadsheet(options) do |oo|
|
63
|
+
begin
|
64
|
+
row, col = oo.label("anton")
|
65
|
+
rescue ArgumentError
|
66
|
+
puts "labels error at #{oo.class}"
|
67
|
+
raise
|
68
|
+
end
|
69
|
+
|
70
|
+
assert_equal 5, row, "error with label in class #{oo.class}"
|
71
|
+
assert_equal 3, col, "error with label in class #{oo.class}"
|
72
|
+
|
73
|
+
row, col = oo.label("anton")
|
74
|
+
assert_equal "Anton", oo.cell(row, col), "error with label in class #{oo.class}"
|
75
|
+
|
76
|
+
row, col = oo.label("berta")
|
77
|
+
assert_equal "Bertha", oo.cell(row, col), "error with label in class #{oo.class}"
|
78
|
+
|
79
|
+
row, col = oo.label("caesar")
|
80
|
+
assert_equal "Cäsar", oo.cell(row, col), "error with label in class #{oo.class}"
|
81
|
+
|
82
|
+
row, col = oo.label("never")
|
83
|
+
assert_nil row
|
84
|
+
assert_nil col
|
85
|
+
|
86
|
+
row, col, sheet = oo.label("anton")
|
87
|
+
assert_equal 5, row
|
88
|
+
assert_equal 3, col
|
89
|
+
assert_equal "Sheet1", sheet
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_method_missing_anton
|
94
|
+
options = { name: "named_cells", format: [:openoffice, :excelx, :libreoffice] }
|
95
|
+
with_each_spreadsheet(options) do |oo|
|
96
|
+
# oo.default_sheet = oo.sheets.first
|
97
|
+
assert_equal "Anton", oo.anton
|
98
|
+
assert_raises(NoMethodError) do
|
99
|
+
oo.never
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# NOTE: Putting these tests into modules in order to share them across different
|
2
|
+
# test classes, i.e. both TestRooExcelx and TestRooOpenOffice should run
|
3
|
+
# sheet related tests.
|
4
|
+
#
|
5
|
+
# This will allow me to reuse these test cases when I add new classes for
|
6
|
+
# Roo's future API.
|
7
|
+
# Sheet related tests
|
8
|
+
module TestSheets
|
9
|
+
def test_sheets
|
10
|
+
sheet_names = ["Tabelle1", "Name of Sheet 2", "Sheet3", "Sheet4", "Sheet5"]
|
11
|
+
with_each_spreadsheet(name: "numbers1") do |oo|
|
12
|
+
assert_equal sheet_names, oo.sheets
|
13
|
+
assert_raises(RangeError) { oo.default_sheet = "no_sheet" }
|
14
|
+
assert_raises(TypeError) { oo.default_sheet = [1, 2, 3] }
|
15
|
+
oo.sheets.each do |sheet_name|
|
16
|
+
oo.default_sheet = sheet_name
|
17
|
+
assert_equal sheet_name, oo.default_sheet
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_sheetname
|
23
|
+
bad_sheet_name = "non existing sheet name"
|
24
|
+
with_each_spreadsheet(name: "numbers1") do |oo|
|
25
|
+
oo.default_sheet = "Name of Sheet 2"
|
26
|
+
assert_equal "I am sheet 2", oo.cell("C", 5)
|
27
|
+
assert_raises(RangeError) { oo.default_sheet = bad_sheet_name }
|
28
|
+
assert_raises(RangeError) { oo.default_sheet = bad_sheet_name }
|
29
|
+
assert_raises(RangeError) { oo.cell("C", 5, bad_sheet_name) }
|
30
|
+
assert_raises(RangeError) { oo.celltype("C", 5, bad_sheet_name) }
|
31
|
+
assert_raises(RangeError) { oo.empty?("C", 5, bad_sheet_name) }
|
32
|
+
assert_raises(RangeError) { oo.formula?("C", 5, bad_sheet_name) }
|
33
|
+
assert_raises(RangeError) { oo.formula("C", 5, bad_sheet_name) }
|
34
|
+
assert_raises(RangeError) { oo.set("C", 5, 42, bad_sheet_name) }
|
35
|
+
assert_raises(RangeError) { oo.formulas(bad_sheet_name) }
|
36
|
+
assert_raises(RangeError) { oo.to_yaml({}, 1, 1, 1, 1, bad_sheet_name) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_info_doesnt_set_default_sheet
|
41
|
+
sheet_name = "Sheet3"
|
42
|
+
with_each_spreadsheet(name: "numbers1") do |oo|
|
43
|
+
oo.default_sheet = sheet_name
|
44
|
+
oo.info
|
45
|
+
assert_equal sheet_name, oo.default_sheet
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_bug_numbered_sheet_names
|
50
|
+
options = { name: "bug-numbered-sheet-names", format: :excelx }
|
51
|
+
with_each_spreadsheet(options) do |oo|
|
52
|
+
oo.each_with_pagename {}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module TestStyles
|
2
|
+
def test_cell_styles
|
3
|
+
# styles only valid in excel spreadsheets?
|
4
|
+
# TODO: what todo with other spreadsheet types
|
5
|
+
with_each_spreadsheet(name: "style", format: [:excelx]) do |oo|
|
6
|
+
# bold
|
7
|
+
assert_equal true, oo.font(1, 1).bold?
|
8
|
+
assert_equal false, oo.font(1, 1).italic?
|
9
|
+
assert_equal false, oo.font(1, 1).underline?
|
10
|
+
|
11
|
+
# italic
|
12
|
+
assert_equal false, oo.font(2, 1).bold?
|
13
|
+
assert_equal true, oo.font(2, 1).italic?
|
14
|
+
assert_equal false, oo.font(2, 1).underline?
|
15
|
+
|
16
|
+
# normal
|
17
|
+
assert_equal false, oo.font(3, 1).bold?
|
18
|
+
assert_equal false, oo.font(3, 1).italic?
|
19
|
+
assert_equal false, oo.font(3, 1).underline?
|
20
|
+
|
21
|
+
# underline
|
22
|
+
assert_equal false, oo.font(4, 1).bold?
|
23
|
+
assert_equal false, oo.font(4, 1).italic?
|
24
|
+
assert_equal true, oo.font(4, 1).underline?
|
25
|
+
|
26
|
+
# bold italic
|
27
|
+
assert_equal true, oo.font(5, 1).bold?
|
28
|
+
assert_equal true, oo.font(5, 1).italic?
|
29
|
+
assert_equal false, oo.font(5, 1).underline?
|
30
|
+
|
31
|
+
# bold underline
|
32
|
+
assert_equal true, oo.font(6, 1).bold?
|
33
|
+
assert_equal false, oo.font(6, 1).italic?
|
34
|
+
assert_equal true, oo.font(6, 1).underline?
|
35
|
+
|
36
|
+
# italic underline
|
37
|
+
assert_equal false, oo.font(7, 1).bold?
|
38
|
+
assert_equal true, oo.font(7, 1).italic?
|
39
|
+
assert_equal true, oo.font(7, 1).underline?
|
40
|
+
|
41
|
+
# bolded row
|
42
|
+
assert_equal true, oo.font(8, 1).bold?
|
43
|
+
assert_equal false, oo.font(8, 1).italic?
|
44
|
+
assert_equal false, oo.font(8, 1).underline?
|
45
|
+
|
46
|
+
# bolded col
|
47
|
+
assert_equal true, oo.font(9, 2).bold?
|
48
|
+
assert_equal false, oo.font(9, 2).italic?
|
49
|
+
assert_equal false, oo.font(9, 2).underline?
|
50
|
+
|
51
|
+
# bolded row, italic col
|
52
|
+
assert_equal true, oo.font(10, 3).bold?
|
53
|
+
assert_equal true, oo.font(10, 3).italic?
|
54
|
+
assert_equal false, oo.font(10, 3).underline?
|
55
|
+
|
56
|
+
# normal
|
57
|
+
assert_equal false, oo.font(11, 4).bold?
|
58
|
+
assert_equal false, oo.font(11, 4).italic?
|
59
|
+
assert_equal false, oo.font(11, 4).underline?
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestRooBase < Minitest::Test
|
4
|
+
def test_info
|
5
|
+
# NOTE: unfortunately, the ods and xlsx versions of numbers1 are not
|
6
|
+
# identical, so this test fails for Open Office.
|
7
|
+
expected_templ = File.read("#{TESTDIR}/expected_results/numbers_info.yml")
|
8
|
+
with_each_spreadsheet(name: "numbers1", format: [:excelx]) do |workbook|
|
9
|
+
ext = get_extension(workbook)
|
10
|
+
expected = Kernel.format(expected_templ, ext)
|
11
|
+
assert_equal expected.strip, workbook.info.strip
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_column
|
16
|
+
with_each_spreadsheet(name: "numbers1") do |workbook|
|
17
|
+
expected = [1.0, 5.0, nil, 10.0, Date.new(1961, 11, 21), "tata", nil, nil, nil, nil, "thisisa11", 41.0, nil, nil, 41.0, "einundvierzig", nil, Date.new(2007, 5, 31)]
|
18
|
+
assert_equal expected, workbook.column(1)
|
19
|
+
assert_equal expected, workbook.column("a")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_column_huge_document
|
24
|
+
skip_long_test
|
25
|
+
with_each_spreadsheet(name: "Bibelbund", format: [:openoffice, :excelx]) do |workbook|
|
26
|
+
workbook.default_sheet = workbook.sheets.first
|
27
|
+
assert_equal 3735, workbook.column("a").size
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_simple_spreadsheet_find_by_condition
|
32
|
+
with_each_spreadsheet(name: "simple_spreadsheet") do |workbook|
|
33
|
+
workbook.header_line = 3
|
34
|
+
results = workbook.find(:all, conditions: { "Comment" => "Task 1" })
|
35
|
+
assert_equal Date.new(2007, 05, 07), results[1]["Date"]
|
36
|
+
assert_equal 10.75, results[1]["Start time"]
|
37
|
+
assert_equal 12.50, results[1]["End time"]
|
38
|
+
assert_equal 0, results[1]["Pause"]
|
39
|
+
assert_equal 1.75, results[1]["Sum"]
|
40
|
+
assert_equal "Task 1", results[1]["Comment"]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_bug_bbu
|
45
|
+
expected_templ = File.read("#{TESTDIR}/expected_results/bbu_info.txt")
|
46
|
+
with_each_spreadsheet(name: "bbu", format: [:openoffice, :excelx]) do |workbook|
|
47
|
+
ext = get_extension(workbook)
|
48
|
+
expected_result = Kernel.format(expected_templ, ext)
|
49
|
+
assert_equal expected_result.strip, workbook.info.strip
|
50
|
+
|
51
|
+
workbook.default_sheet = workbook.sheets[1] # empty sheet
|
52
|
+
assert_nil workbook.first_row
|
53
|
+
assert_nil workbook.last_row
|
54
|
+
assert_nil workbook.first_column
|
55
|
+
assert_nil workbook.last_column
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_find_by_row_huge_document
|
60
|
+
skip_long_test
|
61
|
+
options = { name: "Bibelbund", format: [:openoffice, :excelx] }
|
62
|
+
with_each_spreadsheet(options) do |workbook|
|
63
|
+
workbook.default_sheet = workbook.sheets.first
|
64
|
+
result = workbook.find 20
|
65
|
+
assert result
|
66
|
+
assert_equal "Brief aus dem Sekretariat", result[0]["TITEL"]
|
67
|
+
|
68
|
+
result = workbook.find 22
|
69
|
+
assert result
|
70
|
+
assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.", result[0]["TITEL"]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_find_by_row
|
75
|
+
with_each_spreadsheet(name: "numbers1") do |workbook|
|
76
|
+
workbook.header_line = nil
|
77
|
+
result = workbook.find 16
|
78
|
+
assert result
|
79
|
+
assert_nil workbook.header_line
|
80
|
+
# keine Headerlines in diesem Beispiel definiert
|
81
|
+
assert_equal "einundvierzig", result[0]
|
82
|
+
# assert_equal false, results
|
83
|
+
result = workbook.find 15
|
84
|
+
assert result
|
85
|
+
assert_equal 41, result[0]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_find_by_row_if_header_line_is_not_nil
|
90
|
+
with_each_spreadsheet(name: "numbers1") do |workbook|
|
91
|
+
workbook.header_line = 2
|
92
|
+
refute_nil workbook.header_line
|
93
|
+
results = workbook.find 1
|
94
|
+
assert results
|
95
|
+
assert_equal 5, results[0]
|
96
|
+
assert_equal 6, results[1]
|
97
|
+
results = workbook.find 15
|
98
|
+
assert results
|
99
|
+
assert_equal "einundvierzig", results[0]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_find_by_conditions
|
104
|
+
skip_long_test
|
105
|
+
expected_results = [
|
106
|
+
{
|
107
|
+
"VERFASSER" => "Almassy, Annelene von",
|
108
|
+
"INTERNET" => nil,
|
109
|
+
"SEITE" => 316.0,
|
110
|
+
"KENNUNG" => "Aus dem Bibelbund",
|
111
|
+
"OBJEKT" => "Bibel+Gem",
|
112
|
+
"PC" => "#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
|
113
|
+
"NUMMER" => "1982-3",
|
114
|
+
"TITEL" => "Brief aus dem Sekretariat"
|
115
|
+
},
|
116
|
+
{
|
117
|
+
"VERFASSER" => "Almassy, Annelene von",
|
118
|
+
"INTERNET" => nil,
|
119
|
+
"SEITE" => 222.0,
|
120
|
+
"KENNUNG" => "Aus dem Bibelbund",
|
121
|
+
"OBJEKT" => "Bibel+Gem",
|
122
|
+
"PC" => "#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
|
123
|
+
"NUMMER" => "1983-2",
|
124
|
+
"TITEL" => "Brief aus dem Sekretariat"
|
125
|
+
}
|
126
|
+
]
|
127
|
+
|
128
|
+
expected_results_size = 2
|
129
|
+
options = { name: "Bibelbund", format: [:openoffice, :excelx] }
|
130
|
+
with_each_spreadsheet(options) do |workbook|
|
131
|
+
results = workbook.find(:all, conditions: { "TITEL" => "Brief aus dem Sekretariat" })
|
132
|
+
assert_equal expected_results_size, results.size
|
133
|
+
assert_equal expected_results, results
|
134
|
+
|
135
|
+
conditions = {
|
136
|
+
"TITEL" => "Brief aus dem Sekretariat",
|
137
|
+
"VERFASSER" => "Almassy, Annelene von"
|
138
|
+
}
|
139
|
+
results = workbook.find(:all, conditions: conditions)
|
140
|
+
assert_equal expected_results, results
|
141
|
+
assert_equal expected_results_size, results.size
|
142
|
+
|
143
|
+
results = workbook.find(:all, conditions: { "VERFASSER" => "Almassy, Annelene von" })
|
144
|
+
assert_equal 13, results.size
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_find_by_conditions_with_array_option
|
149
|
+
expected_results = [
|
150
|
+
[
|
151
|
+
"Brief aus dem Sekretariat",
|
152
|
+
"Almassy, Annelene von",
|
153
|
+
"Bibel+Gem",
|
154
|
+
"1982-3",
|
155
|
+
316.0,
|
156
|
+
nil,
|
157
|
+
"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
|
158
|
+
"Aus dem Bibelbund",
|
159
|
+
],
|
160
|
+
[
|
161
|
+
"Brief aus dem Sekretariat",
|
162
|
+
"Almassy, Annelene von",
|
163
|
+
"Bibel+Gem",
|
164
|
+
"1983-2",
|
165
|
+
222.0,
|
166
|
+
nil,
|
167
|
+
"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
|
168
|
+
"Aus dem Bibelbund",
|
169
|
+
]
|
170
|
+
]
|
171
|
+
options = { name: "Bibelbund", format: [:openoffice, :excelx] }
|
172
|
+
with_each_spreadsheet(options) do |workbook|
|
173
|
+
conditions = {
|
174
|
+
"TITEL" => "Brief aus dem Sekretariat",
|
175
|
+
"VERFASSER" => "Almassy, Annelene von"
|
176
|
+
}
|
177
|
+
results = workbook.find(:all, conditions: conditions, array: true)
|
178
|
+
assert_equal 2, results.size
|
179
|
+
assert_equal expected_results, results
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestRooCSV < Minitest::Test
|
4
|
+
def test_sheets
|
5
|
+
file = filename("numbers1")
|
6
|
+
workbook = roo_class.new(File.join(TESTDIR, file))
|
7
|
+
assert_equal ["default"], workbook.sheets
|
8
|
+
assert_raises(RangeError) { workbook.default_sheet = "no_sheet" }
|
9
|
+
assert_raises(TypeError) { workbook.default_sheet = [1, 2, 3] }
|
10
|
+
workbook.sheets.each do |sh|
|
11
|
+
workbook.default_sheet = sh
|
12
|
+
assert_equal sh, workbook.default_sheet
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_nil_rows_and_lines_csv
|
17
|
+
# x_123
|
18
|
+
oo = Roo::CSV.new(File.join(TESTDIR,'Bibelbund.csv'))
|
19
|
+
oo.default_sheet = oo.sheets.first
|
20
|
+
assert_equal 1, oo.first_row
|
21
|
+
assert_equal 3735, oo.last_row
|
22
|
+
assert_equal 1, oo.first_column
|
23
|
+
assert_equal 8, oo.last_column
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_empty_csv
|
27
|
+
# x_123
|
28
|
+
oo = Roo::CSV.new(File.join(TESTDIR,'emptysheets.csv'))
|
29
|
+
oo.default_sheet = oo.sheets.first
|
30
|
+
assert_equal 1, oo.first_row
|
31
|
+
assert_equal 1, oo.last_row
|
32
|
+
assert_equal 1, oo.first_column
|
33
|
+
assert_equal 1, oo.last_column
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_csv_parsing_with_headers
|
37
|
+
return unless CSV
|
38
|
+
headers = ["TITEL", "VERFASSER", "OBJEKT", "NUMMER", "SEITE", "INTERNET", "PC", "KENNUNG"]
|
39
|
+
|
40
|
+
oo = Roo::Spreadsheet.open(File.join(TESTDIR, "Bibelbund.csv"))
|
41
|
+
parsed = oo.parse(headers: true)
|
42
|
+
assert_equal headers, parsed[1].keys
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_iso_8859_1
|
46
|
+
file = File.open(File.join(TESTDIR, "iso_8859_1.csv"))
|
47
|
+
options = { csv_options: { col_sep: ";", encoding: Encoding::ISO_8859_1 } }
|
48
|
+
workbook = Roo::CSV.new(file.path, options)
|
49
|
+
result = workbook.last_column
|
50
|
+
assert_equal(19, result)
|
51
|
+
end
|
52
|
+
|
53
|
+
def roo_class
|
54
|
+
Roo::CSV
|
55
|
+
end
|
56
|
+
|
57
|
+
def filename(name)
|
58
|
+
"#{name}.csv"
|
59
|
+
end
|
60
|
+
end
|