import: data frames are here!
Implemented a whole new class to represent the data that comes in from CSV and XLSX. See docs for more info. Closes #153
This commit is contained in:
+18
-18
@@ -3,7 +3,7 @@ require 'spec_helper'
|
||||
describe Squib::Deck do
|
||||
context '#csv' do
|
||||
it 'loads basic csv data' do
|
||||
expect(Squib.csv(file: csv_file('basic.csv'))).to eq({
|
||||
expect(Squib.csv(file: csv_file('basic.csv')).to_h.to_h).to eq({
|
||||
'h1' => [1, 3],
|
||||
'h2' => [2, 4]
|
||||
})
|
||||
@@ -12,7 +12,7 @@ describe Squib::Deck do
|
||||
it 'collapses duplicate columns and warns' do
|
||||
expect(Squib.logger).to receive(:warn)
|
||||
.with('CSV duplicated the following column keys: h1,h1')
|
||||
expect(Squib.csv(file: csv_file('dup_cols.csv'))).to eq({
|
||||
expect(Squib.csv(file: csv_file('dup_cols.csv')).to_h.to_h).to eq({
|
||||
'h1' => [1, 3],
|
||||
'h2' => [5, 7],
|
||||
'H2' => [6, 8],
|
||||
@@ -21,7 +21,7 @@ describe Squib::Deck do
|
||||
end
|
||||
|
||||
it 'strips spaces by default' do
|
||||
expect(Squib.csv(file: csv_file('with_spaces.csv'))).to eq({
|
||||
expect(Squib.csv(file: csv_file('with_spaces.csv')).to_h).to eq({
|
||||
'With Spaces' => ['a b c', 3],
|
||||
'h2' => [2, 4],
|
||||
'h3' => [3, nil]
|
||||
@@ -29,7 +29,7 @@ describe Squib::Deck do
|
||||
end
|
||||
|
||||
it 'skips space stripping if told to' do
|
||||
expect(Squib.csv(strip: false, file: csv_file('with_spaces.csv'))).to eq({
|
||||
expect(Squib.csv(strip: false, file: csv_file('with_spaces.csv')).to_h).to eq({
|
||||
' With Spaces ' => ['a b c ', 3],
|
||||
'h2' => [2, 4],
|
||||
'h3' => [3, nil]
|
||||
@@ -37,14 +37,14 @@ describe Squib::Deck do
|
||||
end
|
||||
|
||||
it 'explodes quantities' do
|
||||
expect(Squib.csv(file: csv_file('qty.csv'))).to eq({
|
||||
expect(Squib.csv(file: csv_file('qty.csv')).to_h).to eq({
|
||||
'Name' => %w(Ha Ha Ha Ho),
|
||||
'Qty' => [3, 3, 3, 1],
|
||||
})
|
||||
end
|
||||
|
||||
it 'explodes quantities on specified header' do
|
||||
expect(Squib.csv(explode: 'Quantity', file: csv_file('qty_named.csv'))).to eq({
|
||||
expect(Squib.csv(explode: 'Quantity', file: csv_file('qty_named.csv')).to_h).to eq({
|
||||
'Name' => %w(Ha Ha Ha Ho),
|
||||
'Quantity' => [3, 3, 3, 1],
|
||||
})
|
||||
@@ -52,7 +52,7 @@ describe Squib::Deck do
|
||||
|
||||
it 'loads inline data' do
|
||||
hash = Squib.csv(data: "h1,h2\n1,2\n3,4")
|
||||
expect(hash).to eq({
|
||||
expect(hash.to_h).to eq({
|
||||
'h1' => [1, 3],
|
||||
'h2' => [2, 4]
|
||||
})
|
||||
@@ -60,7 +60,7 @@ describe Squib::Deck do
|
||||
|
||||
it 'loads csv with newlines' do
|
||||
hash = Squib.csv(file: csv_file('newline.csv'))
|
||||
expect(hash).to eq({
|
||||
expect(hash.to_h).to eq({
|
||||
'title' => ['Foo'],
|
||||
'level' => [1],
|
||||
'notes' => ["a\nb"]
|
||||
@@ -70,7 +70,7 @@ describe Squib::Deck do
|
||||
it 'loads custom CSV options' do
|
||||
hash = Squib.csv(file: csv_file('custom_opts.csv'),
|
||||
col_sep: '-', quote_char: '|')
|
||||
expect(hash).to eq({
|
||||
expect(hash.to_h).to eq({
|
||||
'x' => ['p'],
|
||||
'y' => ['q-r']
|
||||
})
|
||||
@@ -85,7 +85,7 @@ describe Squib::Deck do
|
||||
'ha'
|
||||
end
|
||||
end
|
||||
expect(data).to eq({
|
||||
expect(data.to_h).to eq({
|
||||
'h1' => [2, 6],
|
||||
'h2' => %w(ha ha),
|
||||
})
|
||||
@@ -99,7 +99,7 @@ describe Squib::Deck do
|
||||
value
|
||||
end
|
||||
end
|
||||
expect(data).to eq({
|
||||
expect(data.to_h).to eq({
|
||||
'a' => ["foo\nbar", 1],
|
||||
'b' => [1, "blah\n"],
|
||||
})
|
||||
@@ -109,7 +109,7 @@ describe Squib::Deck do
|
||||
|
||||
context '#xlsx' do
|
||||
it 'loads basic xlsx data' do
|
||||
expect(Squib.xlsx(file: xlsx_file('basic.xlsx'))).to eq({
|
||||
expect(Squib.xlsx(file: xlsx_file('basic.xlsx')).to_h).to eq({
|
||||
'Name' => %w(Larry Curly Mo),
|
||||
'General Number' => %w(1 2 3), # general types always get loaded as strings with no conversion
|
||||
'Actual Number' => [4.0, 5.0, 6.0], # numbers get auto-converted to integers
|
||||
@@ -117,7 +117,7 @@ describe Squib::Deck do
|
||||
end
|
||||
|
||||
it 'loads xlsx with formulas' do
|
||||
expect(Squib.xlsx(file: xlsx_file('formulas.xlsx'))).to eq({
|
||||
expect(Squib.xlsx(file: xlsx_file('formulas.xlsx')).to_h).to eq({
|
||||
'A' => %w(1 2),
|
||||
'B' => %w(3 4),
|
||||
'Sum' => %w(4 6),
|
||||
@@ -125,20 +125,20 @@ describe Squib::Deck do
|
||||
end
|
||||
|
||||
it 'loads xlsm files with macros' do
|
||||
expect(Squib.xlsx(file: xlsx_file('with_macros.xlsm'))).to eq({
|
||||
expect(Squib.xlsx(file: xlsx_file('with_macros.xlsm')).to_h).to eq({
|
||||
'foo' => %w(8 10),
|
||||
'bar' => %w(9 11),
|
||||
})
|
||||
end
|
||||
|
||||
it 'strips whitespace by default' do
|
||||
expect(Squib.xlsx(file: xlsx_file('whitespace.xlsx'))).to eq({
|
||||
expect(Squib.xlsx(file: xlsx_file('whitespace.xlsx')).to_h).to eq({
|
||||
'With Whitespace' => ['foo', 'bar', 'baz'],
|
||||
})
|
||||
end
|
||||
|
||||
it 'does not strip whitespace when specified' do
|
||||
expect(Squib.xlsx(file: xlsx_file('whitespace.xlsx'), strip: false)).to eq({
|
||||
expect(Squib.xlsx(file: xlsx_file('whitespace.xlsx'), strip: false).to_h).to eq({
|
||||
' With Whitespace ' => ['foo ', ' bar', ' baz '],
|
||||
})
|
||||
end
|
||||
@@ -154,7 +154,7 @@ describe Squib::Deck do
|
||||
'ha'
|
||||
end
|
||||
end
|
||||
expect(data).to eq({
|
||||
expect(data.to_h).to eq({
|
||||
'Name' => %w(he he he),
|
||||
'General Number' => %w(ha ha ha),
|
||||
'Actual Number' => [8.0, 10.0, 12.0],
|
||||
@@ -162,7 +162,7 @@ describe Squib::Deck do
|
||||
end
|
||||
|
||||
it 'explodes quantities' do
|
||||
expect(Squib.xlsx(explode: 'Qty', file: xlsx_file('explode_quantities.xlsx'))).to eq({
|
||||
expect(Squib.xlsx(explode: 'Qty', file: xlsx_file('explode_quantities.xlsx')).to_h).to eq({
|
||||
'Name' => ['Zergling', 'Zergling', 'Zergling', 'High Templar'],
|
||||
'Qty' => %w(3 3 3 1),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user