roo 1.13.2 → 2.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +17 -0
- data/.github/issue_template.md +16 -0
- data/.github/pull_request_template.md +14 -0
- data/.github/workflows/pull-request.yml +15 -0
- data/.github/workflows/ruby.yml +34 -0
- data/.gitignore +11 -0
- data/.rubocop.yml +186 -0
- data/.simplecov +4 -0
- data/CHANGELOG.md +702 -0
- data/Gemfile +18 -12
- data/Guardfile +23 -0
- data/LICENSE +5 -1
- data/README.md +328 -0
- data/Rakefile +23 -23
- data/examples/roo_soap_client.rb +28 -31
- data/examples/roo_soap_server.rb +4 -6
- data/examples/write_me.rb +9 -10
- data/lib/roo/base.rb +317 -504
- data/lib/roo/constants.rb +7 -0
- data/lib/roo/csv.rb +141 -113
- data/lib/roo/errors.rb +11 -0
- data/lib/roo/excelx/cell/base.rb +108 -0
- data/lib/roo/excelx/cell/boolean.rb +30 -0
- data/lib/roo/excelx/cell/date.rb +28 -0
- data/lib/roo/excelx/cell/datetime.rb +107 -0
- data/lib/roo/excelx/cell/empty.rb +20 -0
- data/lib/roo/excelx/cell/number.rb +99 -0
- data/lib/roo/excelx/cell/string.rb +19 -0
- data/lib/roo/excelx/cell/time.rb +44 -0
- data/lib/roo/excelx/cell.rb +110 -0
- data/lib/roo/excelx/comments.rb +55 -0
- data/lib/roo/excelx/coordinate.rb +19 -0
- data/lib/roo/excelx/extractor.rb +39 -0
- data/lib/roo/excelx/format.rb +71 -0
- data/lib/roo/excelx/images.rb +26 -0
- data/lib/roo/excelx/relationships.rb +33 -0
- data/lib/roo/excelx/shared.rb +39 -0
- data/lib/roo/excelx/shared_strings.rb +151 -0
- data/lib/roo/excelx/sheet.rb +151 -0
- data/lib/roo/excelx/sheet_doc.rb +257 -0
- data/lib/roo/excelx/styles.rb +64 -0
- data/lib/roo/excelx/workbook.rb +64 -0
- data/lib/roo/excelx.rb +407 -601
- data/lib/roo/font.rb +17 -0
- 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/helpers/default_attr_reader.rb +20 -0
- data/lib/roo/helpers/weak_instance_cache.rb +41 -0
- data/lib/roo/libre_office.rb +4 -0
- data/lib/roo/link.rb +34 -0
- data/lib/roo/open_office.rb +631 -0
- data/lib/roo/spreadsheet.rb +28 -23
- data/lib/roo/tempdir.rb +24 -0
- data/lib/roo/utils.rb +128 -0
- data/lib/roo/version.rb +3 -0
- data/lib/roo.rb +26 -24
- data/roo.gemspec +29 -203
- data/spec/helpers.rb +5 -0
- data/spec/lib/roo/base_spec.rb +291 -3
- data/spec/lib/roo/csv_spec.rb +38 -11
- data/spec/lib/roo/excelx/cell/time_spec.rb +15 -0
- data/spec/lib/roo/excelx/format_spec.rb +7 -6
- data/spec/lib/roo/excelx/relationships_spec.rb +43 -0
- data/spec/lib/roo/excelx/sheet_doc_spec.rb +11 -0
- data/spec/lib/roo/excelx_spec.rb +672 -11
- data/spec/lib/roo/libreoffice_spec.rb +16 -6
- data/spec/lib/roo/openoffice_spec.rb +30 -8
- data/spec/lib/roo/spreadsheet_spec.rb +60 -12
- data/spec/lib/roo/strict_spec.rb +43 -0
- data/spec/lib/roo/utils_spec.rb +119 -0
- data/spec/lib/roo/weak_instance_cache_spec.rb +92 -0
- data/spec/lib/roo_spec.rb +0 -0
- data/spec/spec_helper.rb +7 -6
- data/test/all_ss.rb +12 -11
- data/test/excelx/cell/test_attr_reader_default.rb +72 -0
- data/test/excelx/cell/test_base.rb +68 -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 +18 -0
- data/test/excelx/cell/test_number.rb +90 -0
- data/test/excelx/cell/test_string.rb +48 -0
- data/test/excelx/cell/test_time.rb +30 -0
- data/test/excelx/test_coordinate.rb +51 -0
- data/test/formatters/test_csv.rb +136 -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 +81 -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 +88 -0
- data/test/roo/test_excelx.rb +360 -0
- data/test/roo/test_libre_office.rb +9 -0
- data/test/roo/test_open_office.rb +289 -0
- data/test/test_helper.rb +123 -59
- data/test/test_roo.rb +392 -2292
- metadata +153 -298
- data/CHANGELOG +0 -417
- data/Gemfile.lock +0 -78
- data/README.markdown +0 -126
- data/VERSION +0 -1
- data/lib/roo/excel.rb +0 -355
- data/lib/roo/excel2003xml.rb +0 -300
- data/lib/roo/google.rb +0 -292
- data/lib/roo/openoffice.rb +0 -496
- data/lib/roo/roo_rails_helper.rb +0 -83
- data/lib/roo/worksheet.rb +0 -18
- data/scripts/txt2html +0 -67
- data/spec/lib/roo/excel2003xml_spec.rb +0 -15
- data/spec/lib/roo/excel_spec.rb +0 -17
- data/spec/lib/roo/google_spec.rb +0 -64
- data/test/files/1900_base.xls +0 -0
- data/test/files/1900_base.xlsx +0 -0
- data/test/files/1904_base.xls +0 -0
- data/test/files/1904_base.xlsx +0 -0
- data/test/files/Bibelbund.csv +0 -3741
- data/test/files/Bibelbund.ods +0 -0
- data/test/files/Bibelbund.xls +0 -0
- data/test/files/Bibelbund.xlsx +0 -0
- data/test/files/Bibelbund.xml +0 -62518
- data/test/files/Bibelbund1.ods +0 -0
- data/test/files/Pfand_from_windows_phone.xlsx +0 -0
- data/test/files/bad_excel_date.xls +0 -0
- data/test/files/bbu.ods +0 -0
- data/test/files/bbu.xls +0 -0
- data/test/files/bbu.xlsx +0 -0
- data/test/files/bbu.xml +0 -152
- data/test/files/bode-v1.ods.zip +0 -0
- data/test/files/bode-v1.xls.zip +0 -0
- data/test/files/boolean.csv +0 -2
- data/test/files/boolean.ods +0 -0
- data/test/files/boolean.xls +0 -0
- data/test/files/boolean.xlsx +0 -0
- data/test/files/boolean.xml +0 -112
- data/test/files/borders.ods +0 -0
- data/test/files/borders.xls +0 -0
- data/test/files/borders.xlsx +0 -0
- data/test/files/borders.xml +0 -144
- data/test/files/bug-numbered-sheet-names.xlsx +0 -0
- data/test/files/bug-row-column-fixnum-float.xls +0 -0
- data/test/files/bug-row-column-fixnum-float.xml +0 -127
- data/test/files/comments.ods +0 -0
- data/test/files/comments.xls +0 -0
- data/test/files/comments.xlsx +0 -0
- data/test/files/csvtypes.csv +0 -1
- data/test/files/datetime.ods +0 -0
- data/test/files/datetime.xls +0 -0
- data/test/files/datetime.xlsx +0 -0
- data/test/files/datetime.xml +0 -142
- data/test/files/datetime_floatconv.xls +0 -0
- data/test/files/datetime_floatconv.xml +0 -148
- data/test/files/dreimalvier.ods +0 -0
- data/test/files/emptysheets.ods +0 -0
- data/test/files/emptysheets.xls +0 -0
- data/test/files/emptysheets.xlsx +0 -0
- data/test/files/emptysheets.xml +0 -105
- data/test/files/excel2003.xml +0 -21140
- data/test/files/false_encoding.xls +0 -0
- data/test/files/false_encoding.xml +0 -132
- data/test/files/file_item_error.xlsx +0 -0
- data/test/files/formula.ods +0 -0
- data/test/files/formula.xls +0 -0
- data/test/files/formula.xlsx +0 -0
- data/test/files/formula.xml +0 -134
- data/test/files/formula_parse_error.xls +0 -0
- data/test/files/formula_parse_error.xml +0 -1833
- data/test/files/formula_string_error.xlsx +0 -0
- data/test/files/html-escape.ods +0 -0
- data/test/files/link.xls +0 -0
- data/test/files/link.xlsx +0 -0
- data/test/files/matrix.ods +0 -0
- data/test/files/matrix.xls +0 -0
- data/test/files/named_cells.ods +0 -0
- data/test/files/named_cells.xls +0 -0
- data/test/files/named_cells.xlsx +0 -0
- data/test/files/no_spreadsheet_file.txt +0 -1
- data/test/files/numbers1.csv +0 -18
- data/test/files/numbers1.ods +0 -0
- data/test/files/numbers1.xls +0 -0
- data/test/files/numbers1.xlsx +0 -0
- data/test/files/numbers1.xml +0 -312
- data/test/files/numeric-link.xlsx +0 -0
- data/test/files/only_one_sheet.ods +0 -0
- data/test/files/only_one_sheet.xls +0 -0
- data/test/files/only_one_sheet.xlsx +0 -0
- data/test/files/only_one_sheet.xml +0 -67
- data/test/files/paragraph.ods +0 -0
- data/test/files/paragraph.xls +0 -0
- data/test/files/paragraph.xlsx +0 -0
- data/test/files/paragraph.xml +0 -127
- data/test/files/prova.xls +0 -0
- data/test/files/ric.ods +0 -0
- data/test/files/simple_spreadsheet.ods +0 -0
- data/test/files/simple_spreadsheet.xls +0 -0
- data/test/files/simple_spreadsheet.xlsx +0 -0
- data/test/files/simple_spreadsheet.xml +0 -225
- data/test/files/simple_spreadsheet_from_italo.ods +0 -0
- data/test/files/simple_spreadsheet_from_italo.xls +0 -0
- data/test/files/simple_spreadsheet_from_italo.xml +0 -242
- data/test/files/so_datetime.csv +0 -7
- data/test/files/style.ods +0 -0
- data/test/files/style.xls +0 -0
- data/test/files/style.xlsx +0 -0
- data/test/files/style.xml +0 -154
- data/test/files/time-test.csv +0 -2
- data/test/files/time-test.ods +0 -0
- data/test/files/time-test.xls +0 -0
- data/test/files/time-test.xlsx +0 -0
- data/test/files/time-test.xml +0 -131
- data/test/files/type_excel.ods +0 -0
- data/test/files/type_excel.xlsx +0 -0
- data/test/files/type_excelx.ods +0 -0
- data/test/files/type_excelx.xls +0 -0
- data/test/files/type_openoffice.xls +0 -0
- data/test/files/type_openoffice.xlsx +0 -0
- data/test/files/whitespace.ods +0 -0
- data/test/files/whitespace.xls +0 -0
- data/test/files/whitespace.xlsx +0 -0
- data/test/files/whitespace.xml +0 -184
- data/test/rm_sub_test.rb +0 -12
- data/test/rm_test.rb +0 -7
- data/test/test_generic_spreadsheet.rb +0 -259
- data/website/index.html +0 -385
- data/website/index.txt +0 -423
- data/website/javascripts/rounded_corners_lite.inc.js +0 -285
- data/website/stylesheets/screen.css +0 -130
- data/website/template.rhtml +0 -48
data/spec/lib/roo/base_spec.rb
CHANGED
@@ -1,7 +1,295 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Roo::
|
4
|
-
|
5
|
-
|
3
|
+
describe Roo::Base do
|
4
|
+
let(:klass) do
|
5
|
+
Class.new(Roo::Base) do
|
6
|
+
def initialize(filename, data = {})
|
7
|
+
super(filename)
|
8
|
+
@data ||= data
|
9
|
+
end
|
10
|
+
|
11
|
+
def read_cells(sheet = default_sheet)
|
12
|
+
return if @cells_read[sheet]
|
13
|
+
type_map = { String => :string, Date => :date, Numeric => :float }
|
14
|
+
|
15
|
+
@cell[sheet] = @data
|
16
|
+
@cell_type[sheet] = Hash[@data.map { |k, v| [k, type_map.find {|type,_| v.is_a?(type) }.last ] }]
|
17
|
+
@first_row[sheet] = @data.map { |k, _| k[0] }.min
|
18
|
+
@last_row[sheet] = @data.map { |k, _| k[0] }.max
|
19
|
+
@first_column[sheet] = @data.map { |k, _| k[1] }.min
|
20
|
+
@last_column[sheet] = @data.map { |k, _| k[1] }.max
|
21
|
+
@cells_read[sheet] = true
|
22
|
+
end
|
23
|
+
|
24
|
+
def cell(row, col, sheet = nil)
|
25
|
+
sheet ||= default_sheet
|
26
|
+
read_cells(sheet)
|
27
|
+
@cell[sheet][[row, col]]
|
28
|
+
end
|
29
|
+
|
30
|
+
def celltype(row, col, sheet = nil)
|
31
|
+
sheet ||= default_sheet
|
32
|
+
read_cells(sheet)
|
33
|
+
@cell_type[sheet][[row, col]]
|
34
|
+
end
|
35
|
+
|
36
|
+
def sheets
|
37
|
+
['my_sheet', 'blank sheet']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:spreadsheet_data) do
|
43
|
+
{
|
44
|
+
[3, 1] => 'Header',
|
45
|
+
|
46
|
+
[5, 1] => Date.civil(1961, 11, 21),
|
47
|
+
|
48
|
+
[8, 3] => 'thisisc8',
|
49
|
+
[8, 7] => 'thisisg8',
|
50
|
+
|
51
|
+
[12, 1] => 41.0,
|
52
|
+
[12, 2] => 42.0,
|
53
|
+
[12, 3] => 43.0,
|
54
|
+
[12, 4] => 44.0,
|
55
|
+
[12, 5] => 45.0,
|
56
|
+
|
57
|
+
[15, 3] => 43.0,
|
58
|
+
[15, 4] => 44.0,
|
59
|
+
[15, 5] => 45.0,
|
60
|
+
|
61
|
+
[16, 2] => '"Hello world!"',
|
62
|
+
[16, 3] => 'forty-three',
|
63
|
+
[16, 4] => 'forty-four',
|
64
|
+
[16, 5] => 'forty-five'
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
let(:spreadsheet) { klass.new('some_file', spreadsheet_data) }
|
69
|
+
|
70
|
+
describe '#uri?' do
|
71
|
+
it 'should return true when passed a filename starting with http(s)://' do
|
72
|
+
expect(spreadsheet.send(:uri?, 'http://example.com/')).to be_truthy
|
73
|
+
expect(spreadsheet.send(:uri?, 'https://example.com/')).to be_truthy
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should return false when passed a filename which does not start with http(s)://' do
|
77
|
+
expect(spreadsheet.send(:uri?, 'example.com')).to be_falsy
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should return false when passed non-String object such as Tempfile' do
|
81
|
+
expect(spreadsheet.send(:uri?, Tempfile.new('test'))).to be_falsy
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#set' do
|
86
|
+
it 'should not update cell when setting an invalid type' do
|
87
|
+
spreadsheet.set(1, 1, 1)
|
88
|
+
expect { spreadsheet.set(1, 1, :invalid_type) }.to raise_error(ArgumentError)
|
89
|
+
expect(spreadsheet.cell(1, 1)).to eq(1)
|
90
|
+
expect(spreadsheet.celltype(1, 1)).to eq(:float)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#first_row' do
|
95
|
+
it 'should return the first row' do
|
96
|
+
expect(spreadsheet.first_row).to eq(3)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#last_row' do
|
101
|
+
it 'should return the last row' do
|
102
|
+
expect(spreadsheet.last_row).to eq(16)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '#first_column' do
|
107
|
+
it 'should return the first column' do
|
108
|
+
expect(spreadsheet.first_column).to eq(1)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#first_column_as_letter' do
|
113
|
+
it 'should return the first column as a letter' do
|
114
|
+
expect(spreadsheet.first_column_as_letter).to eq('A')
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe '#last_column' do
|
119
|
+
it 'should return the last column' do
|
120
|
+
expect(spreadsheet.last_column).to eq(7)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#last_column_as_letter' do
|
125
|
+
it 'should return the last column as a letter' do
|
126
|
+
expect(spreadsheet.last_column_as_letter).to eq('G')
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "#row" do
|
131
|
+
it "should return the specified row" do
|
132
|
+
expect(spreadsheet.row(12)).to eq([41.0, 42.0, 43.0, 44.0, 45.0, nil, nil])
|
133
|
+
expect(spreadsheet.row(16)).to eq([nil, '"Hello world!"', "forty-three", "forty-four", "forty-five", nil, nil])
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should return the specified row if default_sheet is set by a string" do
|
137
|
+
spreadsheet.default_sheet = "my_sheet"
|
138
|
+
expect(spreadsheet.row(12)).to eq([41.0, 42.0, 43.0, 44.0, 45.0, nil, nil])
|
139
|
+
expect(spreadsheet.row(16)).to eq([nil, '"Hello world!"', "forty-three", "forty-four", "forty-five", nil, nil])
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should return the specified row if default_sheet is set by an integer" do
|
143
|
+
spreadsheet.default_sheet = 0
|
144
|
+
expect(spreadsheet.row(12)).to eq([41.0, 42.0, 43.0, 44.0, 45.0, nil, nil])
|
145
|
+
expect(spreadsheet.row(16)).to eq([nil, '"Hello world!"', "forty-three", "forty-four", "forty-five", nil, nil])
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe '#row_with' do
|
150
|
+
context 'with a matching header row' do
|
151
|
+
it 'returns the row number' do
|
152
|
+
expect(spreadsheet.row_with([/Header/])). to eq 3
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context 'without a matching header row' do
|
157
|
+
it 'raises an error' do
|
158
|
+
expect { spreadsheet.row_with([/Missing Header/]) }.to \
|
159
|
+
raise_error(Roo::HeaderRowNotFoundError)
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'returns missing headers' do
|
163
|
+
expect { spreadsheet.row_with([/Header/, /Missing Header 1/, /Missing Header 2/]) }.to \
|
164
|
+
raise_error(Roo::HeaderRowNotFoundError, '[/Missing Header 1/, /Missing Header 2/]')
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe '#empty?' do
|
170
|
+
it 'should return true when empty' do
|
171
|
+
expect(spreadsheet.empty?(1, 1)).to be_truthy
|
172
|
+
expect(spreadsheet.empty?(8, 3)).to be_falsy
|
173
|
+
expect(spreadsheet.empty?('A', 11)).to be_truthy
|
174
|
+
expect(spreadsheet.empty?('A', 12)).to be_falsy
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe '#reload' do
|
179
|
+
it 'should return reinitialize the spreadsheet' do
|
180
|
+
spreadsheet.reload
|
181
|
+
expect(spreadsheet.instance_variable_get(:@cell).empty?).to be_truthy
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe '#each_with_pagename' do
|
186
|
+
context 'when block given' do
|
187
|
+
it 'iterate with sheet and sheet_name' do
|
188
|
+
sheet_names = []
|
189
|
+
spreadsheet.each_with_pagename do |sheet_name, sheet|
|
190
|
+
sheet_names << sheet_name
|
191
|
+
end
|
192
|
+
expect(sheet_names).to eq ['my_sheet', 'blank sheet']
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context 'when called without block' do
|
197
|
+
it 'should return an enumerator with all the rows' do
|
198
|
+
each_with_pagename = spreadsheet.each_with_pagename
|
199
|
+
expect(each_with_pagename).to be_a(Enumerator)
|
200
|
+
expect(each_with_pagename.to_a.last).to eq([spreadsheet.default_sheet, spreadsheet])
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
describe '#each' do
|
206
|
+
it 'should return an enumerator with all the rows' do
|
207
|
+
each = spreadsheet.each
|
208
|
+
expect(each).to be_a(Enumerator)
|
209
|
+
expect(each.to_a.last).to eq([nil, '"Hello world!"', 'forty-three', 'forty-four', 'forty-five', nil, nil])
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "#default_sheet=" do
|
214
|
+
it "should correctly set the default sheet if passed a string" do
|
215
|
+
spreadsheet.default_sheet = "my_sheet"
|
216
|
+
expect(spreadsheet.default_sheet).to eq("my_sheet")
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should correctly set the default sheet if passed an integer" do
|
220
|
+
spreadsheet.default_sheet = 0
|
221
|
+
expect(spreadsheet.default_sheet).to eq("my_sheet")
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should correctly set the default sheet if passed an integer for the second sheet" do
|
225
|
+
spreadsheet.default_sheet = 1
|
226
|
+
expect(spreadsheet.default_sheet).to eq("blank sheet")
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should raise an error if passed a sheet that does not exist as an integer" do
|
230
|
+
expect { spreadsheet.default_sheet = 10 }.to raise_error RangeError
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should raise an error if passed a sheet that does not exist as a string" do
|
234
|
+
expect { spreadsheet.default_sheet = "does_not_exist" }.to raise_error RangeError
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
describe '#to_yaml' do
|
239
|
+
it 'should convert the spreadsheet to yaml' do
|
240
|
+
expect(spreadsheet.to_yaml({}, 5, 1, 5, 1)).to eq("--- \n" + yaml_entry(5, 1, 'date', '1961-11-21'))
|
241
|
+
expect(spreadsheet.to_yaml({}, 8, 3, 8, 3)).to eq("--- \n" + yaml_entry(8, 3, 'string', 'thisisc8'))
|
242
|
+
|
243
|
+
expect(spreadsheet.to_yaml({}, 12, 3, 12, 3)).to eq("--- \n" + yaml_entry(12, 3, 'float', 43.0))
|
244
|
+
|
245
|
+
expect(spreadsheet.to_yaml({}, 12, 3, 12)).to eq(
|
246
|
+
"--- \n" + yaml_entry(12, 3, 'float', 43.0) +
|
247
|
+
yaml_entry(12, 4, 'float', 44.0) +
|
248
|
+
yaml_entry(12, 5, 'float', 45.0))
|
249
|
+
|
250
|
+
expect(spreadsheet.to_yaml({}, 12, 3)).to eq(
|
251
|
+
"--- \n" + yaml_entry(12, 3, 'float', 43.0) +
|
252
|
+
yaml_entry(12, 4, 'float', 44.0) +
|
253
|
+
yaml_entry(12, 5, 'float', 45.0) +
|
254
|
+
yaml_entry(15, 3, 'float', 43.0) +
|
255
|
+
yaml_entry(15, 4, 'float', 44.0) +
|
256
|
+
yaml_entry(15, 5, 'float', 45.0) +
|
257
|
+
yaml_entry(16, 3, 'string', 'forty-three') +
|
258
|
+
yaml_entry(16, 4, 'string', 'forty-four') +
|
259
|
+
yaml_entry(16, 5, 'string', 'forty-five'))
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
let(:expected_csv) do
|
264
|
+
<<EOS
|
265
|
+
,,,,,,
|
266
|
+
,,,,,,
|
267
|
+
"Header",,,,,,
|
268
|
+
,,,,,,
|
269
|
+
1961-11-21,,,,,,
|
270
|
+
,,,,,,
|
271
|
+
,,,,,,
|
272
|
+
,,"thisisc8",,,,"thisisg8"
|
273
|
+
,,,,,,
|
274
|
+
,,,,,,
|
275
|
+
,,,,,,
|
276
|
+
41,42,43,44,45,,
|
277
|
+
,,,,,,
|
278
|
+
,,,,,,
|
279
|
+
,,43,44,45,,
|
280
|
+
,"""Hello world!""","forty-three","forty-four","forty-five",,
|
281
|
+
EOS
|
282
|
+
end
|
283
|
+
|
284
|
+
let(:expected_csv_with_semicolons) { expected_csv.gsub(/\,/, ';') }
|
285
|
+
|
286
|
+
describe '#to_csv' do
|
287
|
+
it 'should convert the spreadsheet to csv' do
|
288
|
+
expect(spreadsheet.to_csv).to eq(expected_csv)
|
289
|
+
end
|
290
|
+
|
291
|
+
it 'should convert the spreadsheet to csv using the separator when is passed on the parameter' do
|
292
|
+
expect(spreadsheet.to_csv(nil, ';')).to eq(expected_csv_with_semicolons)
|
293
|
+
end
|
6
294
|
end
|
7
295
|
end
|
data/spec/lib/roo/csv_spec.rb
CHANGED
@@ -10,12 +10,33 @@ describe Roo::CSV do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
describe '.new with stream' do
|
14
|
+
let(:csv) { Roo::CSV.new(File.read(path)) }
|
15
|
+
it 'creates an instance' do
|
16
|
+
expect(csv).to be_a(Roo::CSV)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
13
20
|
describe '#parse' do
|
14
|
-
subject
|
21
|
+
subject do
|
15
22
|
csv.parse(options)
|
16
|
-
|
23
|
+
end
|
17
24
|
context 'with headers: true' do
|
18
|
-
let(:options) { {headers: true} }
|
25
|
+
let(:options) { { headers: true } }
|
26
|
+
|
27
|
+
it "doesn't blow up" do
|
28
|
+
expect { subject }.to_not raise_error
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#parse_with_clean_option' do
|
34
|
+
subject do
|
35
|
+
csv.parse(options)
|
36
|
+
end
|
37
|
+
context 'with clean: true' do
|
38
|
+
let(:options) { {clean: true} }
|
39
|
+
let(:path) { 'test/files/parse_with_clean_option.csv' }
|
19
40
|
|
20
41
|
it "doesn't blow up" do
|
21
42
|
expect { subject }.to_not raise_error
|
@@ -25,30 +46,36 @@ describe Roo::CSV do
|
|
25
46
|
|
26
47
|
describe '#csv_options' do
|
27
48
|
context 'when created with the csv_options option' do
|
28
|
-
let(:options)
|
49
|
+
let(:options) do
|
29
50
|
{
|
30
51
|
col_sep: '\t',
|
31
52
|
quote_char: "'"
|
32
53
|
}
|
33
|
-
|
54
|
+
end
|
34
55
|
|
35
56
|
it 'returns the csv options' do
|
36
57
|
csv = Roo::CSV.new(path, csv_options: options)
|
37
|
-
csv.csv_options.
|
58
|
+
expect(csv.csv_options).to eq(options)
|
38
59
|
end
|
39
60
|
end
|
40
61
|
|
41
62
|
context 'when created without the csv_options option' do
|
42
63
|
it 'returns a hash' do
|
43
64
|
csv = Roo::CSV.new(path)
|
44
|
-
csv.csv_options.
|
65
|
+
expect(csv.csv_options).to eq({})
|
45
66
|
end
|
46
67
|
end
|
47
68
|
end
|
48
|
-
end
|
49
69
|
|
50
|
-
describe
|
51
|
-
|
52
|
-
|
70
|
+
describe '#set_value' do
|
71
|
+
it 'returns the cell value' do
|
72
|
+
expect(csv.set_value('A', 1, 'some-value', nil)).to eq('some-value')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#set_type' do
|
77
|
+
it 'returns the cell type' do
|
78
|
+
expect(csv.set_type('A', 1, 'some-type', nil)).to eq('some-type')
|
79
|
+
end
|
53
80
|
end
|
54
81
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Roo::Excelx::Cell::Time do
|
4
|
+
it "should set the cell value to the correct number of seconds" do
|
5
|
+
value = 0.05513888888888888 # '1:19:24'
|
6
|
+
excelx_type = [:numeric_or_formula, "h:mm:ss"]
|
7
|
+
base_timestamp = Date.new(1899, 12, 30).to_time.to_i
|
8
|
+
time_cell = Roo::Excelx::Cell::Time.new(value, nil, excelx_type, 1, nil, base_timestamp, nil)
|
9
|
+
expect(time_cell.value).to eq(1*60*60 + 19*60 + 24) # '1:19:24' in seconds
|
10
|
+
# use case from https://github.com/roo-rb/roo/issues/310
|
11
|
+
value = 0.523761574074074 # '12:34:13' in seconds
|
12
|
+
time_cell = Roo::Excelx::Cell::Time.new(value, nil, excelx_type, 1, nil, base_timestamp, nil)
|
13
|
+
expect(time_cell.value).to eq(12*60*60 + 34*60 + 13) # 12:34:13 in seconds
|
14
|
+
end
|
15
|
+
end
|
@@ -11,8 +11,8 @@ describe Roo::Excelx::Format do
|
|
11
11
|
'0%' => :percentage,
|
12
12
|
'0.00%' => :percentage,
|
13
13
|
'0.00E+00' => :float,
|
14
|
-
'# ?/?' => :float,
|
15
|
-
'# ??/??' => :float,
|
14
|
+
'# ?/?' => :float, # ??? TODO:
|
15
|
+
'# ??/??' => :float, # ??? TODO:
|
16
16
|
'mm-dd-yy' => :date,
|
17
17
|
'd-mmm-yy' => :date,
|
18
18
|
'd-mmm' => :date,
|
@@ -33,17 +33,18 @@ describe Roo::Excelx::Format do
|
|
33
33
|
'##0.0E+0' => :float,
|
34
34
|
'@' => :float,
|
35
35
|
#-- zusaetzliche Formate, die nicht standardmaessig definiert sind:
|
36
|
-
|
36
|
+
'yyyy\\-mm\\-dd' => :date,
|
37
37
|
'dd/mm/yy' => :date,
|
38
38
|
'hh:mm:ss' => :time,
|
39
|
-
|
39
|
+
'dd/mm/yy\\ hh:mm' => :datetime,
|
40
40
|
'dd/mmm/yy\\ hh:mm' => :datetime,
|
41
41
|
'dd/mmm/yy' => :date, # 2011-05-21
|
42
42
|
'yyyy-mm-dd' => :date, # 2011-09-16
|
43
|
-
'yyyy-mm-dd;@' => :date
|
43
|
+
'yyyy-mm-dd;@' => :date,
|
44
|
+
'#0_);[Red]\(0\)' => :float
|
44
45
|
}.each do |format, type|
|
45
46
|
it "translates #{format} to #{type}" do
|
46
|
-
Roo::Excelx::Format.to_type(format).
|
47
|
+
expect(Roo::Excelx::Format.to_type(format)).to eq(type)
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Roo::Excelx::Relationships do
|
6
|
+
subject(:relationships) { Roo::Excelx::Relationships.new Roo::Excelx.new(path).rels_files[0] }
|
7
|
+
|
8
|
+
describe "#include_type?" do
|
9
|
+
[
|
10
|
+
["with hyperlink type", "test/files/link.xlsx", true, false],
|
11
|
+
["with nil path", "test/files/Bibelbund.xlsx", false, false],
|
12
|
+
["with comments type", "test/files/comments-google.xlsx", false, true],
|
13
|
+
].each do |context_desc, file_path, hyperlink_value, comments_value|
|
14
|
+
context context_desc do
|
15
|
+
let(:path) { file_path }
|
16
|
+
|
17
|
+
it "should return #{hyperlink_value} for hyperlink" do
|
18
|
+
expect(subject.include_type?("hyperlink")).to be hyperlink_value
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return #{hyperlink_value} for link" do
|
22
|
+
expect(subject.include_type?("link")).to be hyperlink_value
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return false for hypelink" do
|
26
|
+
expect(subject.include_type?("hypelink")).to be false
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return false for coment" do
|
30
|
+
expect(subject.include_type?("coment")).to be false
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return #{comments_value} for comments" do
|
34
|
+
expect(subject.include_type?("comments")).to be comments_value
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return #{comments_value} for comment" do
|
38
|
+
expect(subject.include_type?("comment")).to be comments_value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|