fat_core 1.6.0 → 1.7.1
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.
- checksums.yaml +4 -4
- data/lib/fat_core/column.rb +71 -9
- data/lib/fat_core/date.rb +6 -6
- data/lib/fat_core/enumerable.rb +12 -1
- data/lib/fat_core/formatters/aoa_formatter.rb +84 -0
- data/lib/fat_core/formatters/aoh_formatter.rb +82 -0
- data/lib/fat_core/formatters/formatter.rb +973 -0
- data/lib/fat_core/formatters/org_formatter.rb +72 -0
- data/lib/fat_core/formatters/text_formatter.rb +91 -0
- data/lib/fat_core/formatters.rb +5 -0
- data/lib/fat_core/hash.rb +13 -0
- data/lib/fat_core/numeric.rb +3 -3
- data/lib/fat_core/period.rb +5 -1
- data/lib/fat_core/string.rb +20 -0
- data/lib/fat_core/symbol.rb +1 -1
- data/lib/fat_core/table.rb +251 -266
- data/lib/fat_core/version.rb +2 -2
- data/lib/fat_core.rb +2 -0
- data/spec/lib/column_spec.rb +24 -8
- data/spec/lib/formatters/aoa_formatter_spec.rb +62 -0
- data/spec/lib/formatters/aoh_formatter_spec.rb +61 -0
- data/spec/lib/formatters/formatter_spec.rb +371 -0
- data/spec/lib/formatters/org_formatter_spec.rb +60 -0
- data/spec/lib/formatters/text_formatter_spec.rb +60 -0
- data/spec/lib/period_spec.rb +9 -2
- data/spec/lib/symbol_spec.rb +1 -1
- data/spec/lib/table_spec.rb +86 -167
- metadata +18 -2
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module FatCore
|
4
|
+
describe TextFormatter do
|
5
|
+
describe 'table output' do
|
6
|
+
before :each do
|
7
|
+
@aoa =
|
8
|
+
[['Ref', 'Date', 'Code', 'Raw', 'Shares', 'Price', 'Info', 'Bool'],
|
9
|
+
nil,
|
10
|
+
[1, '2013-05-02', 'P', 795_546.20, 795_546.2, 1.1850, 'ZMPEF1', 'T'],
|
11
|
+
[2, '2013-05-02', 'P', 118_186.40, 118_186.4, 11.8500, 'ZMPEF1', 'T'],
|
12
|
+
[5, '2013-05-02', 'P', 118_186.40, 118_186.4, 11.8500, 'ZMPEF1\'s "Ent"', 'T'],
|
13
|
+
[7, '2013-05-20', 'S', 12_000.00, 5046.00, 28.2804, 'ZMEAC', 'F'],
|
14
|
+
[8, '2013-05-20', 'S', 85_000.00, 35_742.50, 28.3224, 'ZMEAC', 'T'],
|
15
|
+
[9, '2013-05-20', 'S', 33_302.00, 14_003.49, 28.6383, 'ZMEAC', 'T'],
|
16
|
+
[10, '2013-05-23', 'S', 8000.00, 3364.00, 27.1083, 'ZMEAC', 'T'],
|
17
|
+
[11, '2013-05-23', 'S', 23_054.00, 9694.21, 26.8015, 'ZMEAC', 'F'],
|
18
|
+
[12, '2013-05-23', 'S', 39_906.00, 16_780.47, 25.1749, 'ZMEAC', 'T'],
|
19
|
+
[13, '2013-05-29', 'S', 13_459.00, 5659.51, 24.7464, 'ZMEAC', 'T'],
|
20
|
+
[14, '2013-05-29', 'S', 15_700.00, 6601.85, 24.7790, 'ZMEAC', 'F'],
|
21
|
+
[15, '2013-05-29', 'S', 15_900.00, 6685.95, 24.5802, 'ZMEAC', 'T'],
|
22
|
+
[16, '2013-05-30', 'S', 6_679.00, 2808.52, 25.0471, 'ZMEAC', 'T']]
|
23
|
+
@tab = Table.from_aoa(@aoa).order_by(:date)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should be able to output a table with default formatting instructions' do
|
27
|
+
txt = TextFormatter.new(@tab).output
|
28
|
+
expect(txt.class).to eq(String)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should be able to set format and output by method calls' do
|
32
|
+
fmt = TextFormatter.new(@tab)
|
33
|
+
fmt.format(ref: '5.0', code: 'C', raw: ',0.0', shares: ',0.0',
|
34
|
+
price: '0.3R', bool: 'Y', numeric: 'R')
|
35
|
+
fmt.format_for(:header, string: 'CB')
|
36
|
+
fmt.sum_gfooter(:price, :raw, :shares)
|
37
|
+
fmt.gfooter('Grp Std Dev', price: :dev, shares: :dev, bool: :one?)
|
38
|
+
fmt.sum_footer(:price, :raw, :shares)
|
39
|
+
fmt.footer('Std Dev', price: :dev, shares: :dev, bool: :all?)
|
40
|
+
fmt.footer('Any?', bool: :any?)
|
41
|
+
txt = fmt.output
|
42
|
+
expect(txt.size).to be > 1000
|
43
|
+
expect(txt).to match(/\bRef\b/)
|
44
|
+
expect(txt).to match(/\bBool\b/)
|
45
|
+
expect(txt).to match(/\b2013-05-02\b/)
|
46
|
+
expect(txt).to match(/^\|[-+]+\|$/)
|
47
|
+
expect(txt).to match(/\D795,546\D/)
|
48
|
+
expect(txt).to match(/\D1,031,919\D/)
|
49
|
+
expect(txt).to match(/\D1.185\D/)
|
50
|
+
expect(txt).to match(/\D24.885\D/)
|
51
|
+
expect(txt).to match(/\D00001\D/)
|
52
|
+
expect(txt).to match(/\bY\b/)
|
53
|
+
expect(txt).to match(/\bP\b/)
|
54
|
+
expect(txt).to match(/\bZMPEF1\b/)
|
55
|
+
expect(txt).to match(/\bGroup Total\b/)
|
56
|
+
expect(txt).to match(/\bGrp Std Dev\b/)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/spec/lib/period_spec.rb
CHANGED
@@ -458,12 +458,19 @@ describe Period do
|
|
458
458
|
}.to raise_error /unknown chunk sym/
|
459
459
|
end
|
460
460
|
|
461
|
-
it 'should raise error for too large a chunk' do
|
461
|
+
it 'should raise error for too large a chunk and no partials allowed' do
|
462
462
|
expect {
|
463
|
-
Period.new('2012-12-01', '2012-12-31').
|
463
|
+
Period.new('2012-12-01', '2012-12-31').
|
464
|
+
chunks(size: :bimonth, partial_first: false, partial_last: false)
|
464
465
|
}.to raise_error /longer than/
|
465
466
|
end
|
466
467
|
|
468
|
+
it 'should return period itself for too large chunk if partials allowed' do
|
469
|
+
pd = Period.new('2012-12-01', '2012-12-31')
|
470
|
+
expect(pd.chunks(size: :bimonth, partial_first: true).first).to eq(pd)
|
471
|
+
expect(pd.chunks(size: :bimonth, partial_last: true).first).to eq(pd)
|
472
|
+
end
|
473
|
+
|
467
474
|
it 'should not include a partial final chunk by default' do
|
468
475
|
chunks = Period.new('2012-01-01', '2012-03-30').chunks(size: :month)
|
469
476
|
expect(chunks.size).to eq(2)
|
data/spec/lib/symbol_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Symbol do
|
4
4
|
it 'should be able to convert to a capitalized string' do
|
5
5
|
expect(:i_am_a_symbol.entitle).to eq 'I Am a Symbol'
|
6
|
-
expect(:i_am_a_symbol.
|
6
|
+
expect(:i_am_a_symbol.as_string).to eq 'I Am a Symbol'
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'should respond to tex_quote' do
|
data/spec/lib/table_spec.rb
CHANGED
@@ -362,14 +362,34 @@ EOS
|
|
362
362
|
expect(dwtab.column(:g10).type).to eq('Boolean')
|
363
363
|
expect(dwtab.column(:qp10).type).to eq('Boolean')
|
364
364
|
dwo = dwtab.where('qp10 || g10')
|
365
|
-
dwo
|
366
|
-
|
367
|
-
next unless k > 1
|
368
|
-
expect(row[5]).to match(/\A(T|F)\z/)
|
365
|
+
dwo.rows.each do |row|
|
366
|
+
expect(row[:qp10].class.to_s).to match(/TrueClass|FalseClass/)
|
369
367
|
end
|
370
368
|
end
|
371
369
|
end
|
372
370
|
|
371
|
+
describe 'indexing' do
|
372
|
+
before :all do
|
373
|
+
@tab = Table.from_aoh([
|
374
|
+
{ a: '1', 'Two words' => '2', c: '3,123', d: 'apple' },
|
375
|
+
{ a: '4', 'Two words' => '5', c: '6,412', d: 'orange' },
|
376
|
+
{ a: '7', 'Two words' => '8', c: '$9,888', d: 'pear' }])
|
377
|
+
end
|
378
|
+
|
379
|
+
it 'should be able to index by column head' do
|
380
|
+
expect(@tab[:a]).to eq([1, 4, 7])
|
381
|
+
expect(@tab[:d]).to eq(%w(apple orange pear))
|
382
|
+
expect { @tab[:r] }.to raise_error /not in table/
|
383
|
+
end
|
384
|
+
|
385
|
+
it 'should be able to index by row number' do
|
386
|
+
expect(@tab[1]).to eq({a: 1, two_words: 2, c: 3123, d: 'apple'})
|
387
|
+
expect(@tab[3]).to eq({a: 7, two_words: 8, c: 9888, d: 'pear'})
|
388
|
+
expect { @tab[0] }.to raise_error(/out of range/)
|
389
|
+
expect { @tab[4] }.to raise_error(/out of range/)
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
373
393
|
describe 'column operations' do
|
374
394
|
it 'should be able to sum a column' do
|
375
395
|
aoh = [
|
@@ -378,10 +398,10 @@ EOS
|
|
378
398
|
{ a: '7', 'Two words' => '8', c: '$9,888', d: 'pear' }
|
379
399
|
]
|
380
400
|
tab = Table.from_aoh(aoh)
|
381
|
-
expect(tab
|
401
|
+
expect(tab.column(:a).sum).to eq 12
|
382
402
|
expect(tab[:two_words].sum).to eq 15
|
383
|
-
expect(tab
|
384
|
-
expect(tab
|
403
|
+
expect(tab.column(:c).sum).to eq 19_423
|
404
|
+
expect(tab.column(:d).sum).to eq 'appleorangepear'
|
385
405
|
end
|
386
406
|
|
387
407
|
it 'should be able to sum a column ignoring nils' do
|
@@ -391,10 +411,10 @@ EOS
|
|
391
411
|
{ a: '7', 'Two words' => '8', c: '$9,888', d: 'pear' }
|
392
412
|
]
|
393
413
|
tab = Table.from_aoh(aoh)
|
394
|
-
expect(tab
|
395
|
-
expect(tab
|
396
|
-
expect(tab
|
397
|
-
expect(tab
|
414
|
+
expect(tab.column(:a).sum).to eq 11
|
415
|
+
expect(tab.column(:two_words).sum).to eq 15
|
416
|
+
expect(tab.column(:c).sum).to eq 16_300
|
417
|
+
expect(tab.column(:d).sum).to eq 'appleorangepear'
|
398
418
|
end
|
399
419
|
|
400
420
|
it 'should be able to report its headings' do
|
@@ -410,8 +430,8 @@ EOS
|
|
410
430
|
{ a: '7', 'Two words' => '8', c: '$9,888', d: 'pear' }
|
411
431
|
]
|
412
432
|
tab = Table.from_aoh(aoh)
|
413
|
-
expect(tab[:a]
|
414
|
-
expect(tab[:c]
|
433
|
+
expect(tab[:a]).to eq [1, 4, 7]
|
434
|
+
expect(tab[:c]).to eq [3123, 6412, 9888]
|
415
435
|
end
|
416
436
|
|
417
437
|
it 'should be able to sum a column' do
|
@@ -421,9 +441,9 @@ EOS
|
|
421
441
|
{ a: '7', 'Two words' => '8', c: '$9,888', d: 'pear' }
|
422
442
|
]
|
423
443
|
tab = Table.from_aoh(aoh)
|
424
|
-
expect(tab
|
425
|
-
expect(tab
|
426
|
-
expect(tab
|
444
|
+
expect(tab.column(:a).sum).to eq 12
|
445
|
+
expect(tab.column(:c).sum).to eq 19_423
|
446
|
+
expect(tab.column(:c).sum.is_a?(Integer)).to be true
|
427
447
|
end
|
428
448
|
|
429
449
|
it 'should be able to average a column' do
|
@@ -433,9 +453,9 @@ EOS
|
|
433
453
|
{ a: '7', 'Two words' => '8', c: '$9,888', d: 'pear' }
|
434
454
|
]
|
435
455
|
tab = Table.from_aoh(aoh)
|
436
|
-
expect(tab
|
437
|
-
expect(tab
|
438
|
-
expect(tab
|
456
|
+
expect(tab.column(:a).avg).to eq 4
|
457
|
+
expect(tab.column(:c).avg.round(4)).to eq 6474.3333
|
458
|
+
expect(tab.column(:c).avg.class).to eq BigDecimal
|
439
459
|
end
|
440
460
|
|
441
461
|
it 'should be able to get column minimum' do
|
@@ -445,10 +465,10 @@ EOS
|
|
445
465
|
{ a: '7', 'Two words' => '8', c: '$9,888', d: 'pear' }
|
446
466
|
]
|
447
467
|
tab = Table.from_aoh(aoh)
|
448
|
-
expect(tab
|
449
|
-
expect(tab
|
450
|
-
expect(tab
|
451
|
-
expect(tab
|
468
|
+
expect(tab.column(:a).min).to eq 1
|
469
|
+
expect(tab.column(:c).min.round(4)).to eq 3123
|
470
|
+
expect(tab.column(:c).min.is_a?(Integer)).to be true
|
471
|
+
expect(tab.column(:d).min).to eq 'apple'
|
452
472
|
end
|
453
473
|
|
454
474
|
it 'should be able to get column maximum' do
|
@@ -458,68 +478,10 @@ EOS
|
|
458
478
|
{ a: '7', 'Two words' => '8', c: '$9,888', d: 'pear' }
|
459
479
|
]
|
460
480
|
tab = Table.from_aoh(aoh)
|
461
|
-
expect(tab
|
462
|
-
expect(tab
|
463
|
-
expect(tab
|
464
|
-
expect(tab
|
465
|
-
end
|
466
|
-
end
|
467
|
-
|
468
|
-
describe 'footers' do
|
469
|
-
it 'should be able to add a total footer to the table' do
|
470
|
-
aoh = [
|
471
|
-
{ a: '1', 'Two words' => '2', c: '3,123', d: 'apple' },
|
472
|
-
{ a: '4', 'Two words' => '5', c: '6,412', d: 'orange' },
|
473
|
-
{ a: '7', 'Two words' => '8', c: '$9,888', d: 'pear' }
|
474
|
-
]
|
475
|
-
tab = Table.from_aoh(aoh)
|
476
|
-
tab.add_sum_footer([:a, :c, :two_words])
|
477
|
-
expect(tab.footers[:total][:a]).to eq 12
|
478
|
-
expect(tab.footers[:total][:c]).to eq 19_423
|
479
|
-
expect(tab.footers[:total][:two_words]).to eq 15
|
480
|
-
expect(tab.footers[:total][:d]).to be_nil
|
481
|
-
end
|
482
|
-
|
483
|
-
it 'should be able to add an average footer to the table' do
|
484
|
-
aoh = [
|
485
|
-
{ a: '1', 'Two words' => '2', c: '3,123', d: 'apple' },
|
486
|
-
{ a: '4', 'Two words' => '5', c: '6,412', d: 'orange' },
|
487
|
-
{ a: '7', 'Two words' => '8', c: '$9,888', d: 'pear' }
|
488
|
-
]
|
489
|
-
tab = Table.from_aoh(aoh)
|
490
|
-
tab.add_avg_footer([:a, :c, :two_words])
|
491
|
-
expect(tab.footers[:average][:a]).to eq 4
|
492
|
-
expect(tab.footers[:average][:c].round(4)).to eq 6474.3333
|
493
|
-
expect(tab.footers[:average][:two_words]).to eq 5
|
494
|
-
expect(tab.footers[:average][:d]).to be_nil
|
495
|
-
end
|
496
|
-
|
497
|
-
it 'should be able to add a minimum footer to the table' do
|
498
|
-
aoh = [
|
499
|
-
{ a: '1', 'Two words' => '2', c: '3,123', d: 'apple' },
|
500
|
-
{ a: '4', 'Two words' => '5', c: '6,412', d: 'orange' },
|
501
|
-
{ a: '7', 'Two words' => '8', c: '$9,888', d: 'pear' }
|
502
|
-
]
|
503
|
-
tab = Table.from_aoh(aoh)
|
504
|
-
tab.add_min_footer([:a, :c, :two_words])
|
505
|
-
expect(tab.footers[:minimum][:a]).to eq 1
|
506
|
-
expect(tab.footers[:minimum][:c]).to eq 3123
|
507
|
-
expect(tab.footers[:minimum][:two_words]).to eq 2
|
508
|
-
expect(tab.footers[:minimum][:d]).to be_nil
|
509
|
-
end
|
510
|
-
|
511
|
-
it 'should be able to add a maximum footer to the table' do
|
512
|
-
aoh = [
|
513
|
-
{ a: '1', 'Two words' => '2', c: '3,123', d: 'apple' },
|
514
|
-
{ a: '4', 'Two words' => '5', c: '6,412', d: 'orange' },
|
515
|
-
{ a: '7', 'Two words' => '8', c: '$9,888', d: 'pear' }
|
516
|
-
]
|
517
|
-
tab = Table.from_aoh(aoh)
|
518
|
-
tab.add_max_footer([:a, :c, :two_words])
|
519
|
-
expect(tab.footers[:maximum][:a]).to eq 7
|
520
|
-
expect(tab.footers[:maximum][:c]).to eq 9888
|
521
|
-
expect(tab.footers[:maximum][:two_words]).to eq 8
|
522
|
-
expect(tab.footers[:maximum][:d]).to be_nil
|
481
|
+
expect(tab.column(:a).max).to eq 7
|
482
|
+
expect(tab.column(:c).max.round(4)).to eq 9888
|
483
|
+
expect(tab.column(:c).max.is_a?(Integer)).to be true
|
484
|
+
expect(tab.column(:d).max).to eq 'pear'
|
523
485
|
end
|
524
486
|
end
|
525
487
|
|
@@ -668,8 +630,8 @@ EOS
|
|
668
630
|
tab1 = Table.from_aoh(aoh)
|
669
631
|
tab2 = tab1.select(:two_words, s: 's * s', nc: 'c + c', c: 'nc+nc')
|
670
632
|
expect(tab2.headers).to eq [:two_words, :s, :nc, :c]
|
671
|
-
expect(tab2[:s]
|
672
|
-
expect(tab2[:c]
|
633
|
+
expect(tab2[:s]).to eq([26450449, 169744, 3316041])
|
634
|
+
expect(tab2[:c]).to eq([12492, 25648, 7552])
|
673
635
|
end
|
674
636
|
|
675
637
|
it 'should have access to @row and @group vars in evaluating' do
|
@@ -687,8 +649,8 @@ EOS
|
|
687
649
|
tab = Table.from_aoh(aoh).order_by(:a, :two_words)
|
688
650
|
tab2 = tab.select(:a, :two_words, number: '@row', group: '@group')
|
689
651
|
expect(tab2.headers).to eq [:a, :two_words, :number, :group]
|
690
|
-
expect(tab2[:number]
|
691
|
-
expect(tab2[:group]
|
652
|
+
expect(tab2[:number]).to eq([1, 2, 3, 4, 5, 6, 7, 8, 9])
|
653
|
+
expect(tab2[:group]).to eq([1, 1, 1, 2, 2, 2, 3, 3, 3])
|
692
654
|
end
|
693
655
|
end
|
694
656
|
|
@@ -715,7 +677,7 @@ EOS
|
|
715
677
|
[14, '2013-05-29', 'S', 15_700.00, 6601.85, 24.7790, 'ZMEAC', 'F'],
|
716
678
|
[15, '2013-05-29', 'S', 15_900.00, 6685.95, 24.5802, 'ZMEAC', 'T'],
|
717
679
|
[16, '2013-05-30', 'S', 6_679.00, 2808.52, 25.0471, 'ZMEAC', 'T']]
|
718
|
-
tab = Table.from_aoa(aoa)
|
680
|
+
tab = Table.from_aoa(aoa)
|
719
681
|
tab2 = tab.where('!bool || code == "P"')
|
720
682
|
expect(tab2.rows.size).to eq(5)
|
721
683
|
tab2 = tab.where('code == "S" && raw < 10_000')
|
@@ -728,7 +690,7 @@ EOS
|
|
728
690
|
expect(tab2.rows.size).to eq(0)
|
729
691
|
end
|
730
692
|
|
731
|
-
it 'where
|
693
|
+
it 'where clause with row and group' do
|
732
694
|
aoa =
|
733
695
|
[['Ref', 'Date', 'Code', 'Raw', 'Shares', 'Price', 'Info', 'Bool'],
|
734
696
|
nil,
|
@@ -785,8 +747,8 @@ EOS
|
|
785
747
|
join_tab = @tab_a.join(@tab_b, :id_a, :emp_id_b)
|
786
748
|
expect(join_tab.class).to eq Table
|
787
749
|
expect(join_tab.size).to eq(2)
|
788
|
-
expect(join_tab[:name]
|
789
|
-
expect(join_tab[:name]
|
750
|
+
expect(join_tab[:name]).to include('Paul')
|
751
|
+
expect(join_tab[:name]).to include('Allen')
|
790
752
|
expect(join_tab.headers).to eq([:id, :name, :age, :address, :salary,
|
791
753
|
:join_date, :id_b, :dept])
|
792
754
|
end
|
@@ -795,8 +757,8 @@ EOS
|
|
795
757
|
join_tab = @tab_a.join(@tab_b, 'id_a == emp_id_b')
|
796
758
|
expect(join_tab.class).to eq Table
|
797
759
|
expect(join_tab.size).to eq(2)
|
798
|
-
expect(join_tab[:name]
|
799
|
-
expect(join_tab[:name]
|
760
|
+
expect(join_tab[:name]).to include('Paul')
|
761
|
+
expect(join_tab[:name]).to include('Allen')
|
800
762
|
expect(join_tab.headers).to eq([:id, :name, :age, :address, :salary,
|
801
763
|
:join_date, :id_b, :dept, :emp_id])
|
802
764
|
end
|
@@ -805,12 +767,12 @@ EOS
|
|
805
767
|
join_tab = @tab_a.left_join(@tab_b, :id_a, :emp_id_b)
|
806
768
|
expect(join_tab.class).to eq Table
|
807
769
|
expect(join_tab.size).to eq(8)
|
808
|
-
expect(join_tab[:name]
|
809
|
-
expect(join_tab[:name]
|
810
|
-
expect(join_tab[:name]
|
811
|
-
expect(join_tab[:name]
|
812
|
-
expect(join_tab[:name]
|
813
|
-
expect(join_tab[:name]
|
770
|
+
expect(join_tab[:name]).to include('Paul')
|
771
|
+
expect(join_tab[:name]).to include('Allen')
|
772
|
+
expect(join_tab[:name]).to include('Teddy')
|
773
|
+
expect(join_tab[:name]).to include('Mark')
|
774
|
+
expect(join_tab[:name]).to include('David')
|
775
|
+
expect(join_tab[:name]).to include('James')
|
814
776
|
expect(join_tab.headers).to eq([:id, :name, :age, :address, :salary,
|
815
777
|
:join_date, :id_b, :dept, :emp_id])
|
816
778
|
end
|
@@ -819,11 +781,11 @@ EOS
|
|
819
781
|
join_tab = @tab_a.right_join(@tab_b, :id_a, :emp_id_b)
|
820
782
|
expect(join_tab.class).to eq Table
|
821
783
|
expect(join_tab.size).to eq(3)
|
822
|
-
expect(join_tab[:name]
|
823
|
-
expect(join_tab[:name]
|
824
|
-
expect(join_tab[:dept]
|
825
|
-
expect(join_tab[:dept]
|
826
|
-
expect(join_tab[:dept]
|
784
|
+
expect(join_tab[:name]).to include('Paul')
|
785
|
+
expect(join_tab[:name]).to include('Allen')
|
786
|
+
expect(join_tab[:dept]).to include('IT Billing')
|
787
|
+
expect(join_tab[:dept]).to include('Engineering')
|
788
|
+
expect(join_tab[:dept]).to include('Finance')
|
827
789
|
expect(join_tab.headers).to eq([:id, :name, :age, :address, :salary,
|
828
790
|
:join_date, :id_b, :dept, :emp_id])
|
829
791
|
end
|
@@ -832,15 +794,15 @@ EOS
|
|
832
794
|
join_tab = @tab_a.full_join(@tab_b, :id_a, :emp_id_b)
|
833
795
|
expect(join_tab.class).to eq Table
|
834
796
|
expect(join_tab.size).to eq(9)
|
835
|
-
expect(join_tab[:name]
|
836
|
-
expect(join_tab[:name]
|
837
|
-
expect(join_tab[:name]
|
838
|
-
expect(join_tab[:name]
|
839
|
-
expect(join_tab[:name]
|
840
|
-
expect(join_tab[:name]
|
841
|
-
expect(join_tab[:dept]
|
842
|
-
expect(join_tab[:dept]
|
843
|
-
expect(join_tab[:dept]
|
797
|
+
expect(join_tab[:name]).to include('Paul')
|
798
|
+
expect(join_tab[:name]).to include('Allen')
|
799
|
+
expect(join_tab[:name]).to include('Teddy')
|
800
|
+
expect(join_tab[:name]).to include('Mark')
|
801
|
+
expect(join_tab[:name]).to include('David')
|
802
|
+
expect(join_tab[:name]).to include('James')
|
803
|
+
expect(join_tab[:dept]).to include('IT Billing')
|
804
|
+
expect(join_tab[:dept]).to include('Engineering')
|
805
|
+
expect(join_tab[:dept]).to include('Finance')
|
844
806
|
expect(join_tab.headers).to eq([:id, :name, :age, :address, :salary,
|
845
807
|
:join_date, :id_b, :dept, :emp_id])
|
846
808
|
end
|
@@ -849,15 +811,15 @@ EOS
|
|
849
811
|
join_tab = @tab_a.cross_join(@tab_b)
|
850
812
|
expect(join_tab.class).to eq Table
|
851
813
|
expect(join_tab.size).to eq(24)
|
852
|
-
expect(join_tab[:name]
|
853
|
-
expect(join_tab[:name]
|
854
|
-
expect(join_tab[:name]
|
855
|
-
expect(join_tab[:name]
|
856
|
-
expect(join_tab[:name]
|
857
|
-
expect(join_tab[:name]
|
858
|
-
expect(join_tab[:dept]
|
859
|
-
expect(join_tab[:dept]
|
860
|
-
expect(join_tab[:dept]
|
814
|
+
expect(join_tab[:name]).to include('Paul')
|
815
|
+
expect(join_tab[:name]).to include('Allen')
|
816
|
+
expect(join_tab[:name]).to include('Teddy')
|
817
|
+
expect(join_tab[:name]).to include('Mark')
|
818
|
+
expect(join_tab[:name]).to include('David')
|
819
|
+
expect(join_tab[:name]).to include('James')
|
820
|
+
expect(join_tab[:dept]).to include('IT Billing')
|
821
|
+
expect(join_tab[:dept]).to include('Engineering')
|
822
|
+
expect(join_tab[:dept]).to include('Finance')
|
861
823
|
expect(join_tab.headers).to eq([:id, :name, :age, :address, :salary,
|
862
824
|
:join_date, :id_b, :dept, :emp_id])
|
863
825
|
end
|
@@ -1024,48 +986,5 @@ EOS
|
|
1024
986
|
expect(tab.groups[5].size).to eq(1)
|
1025
987
|
end
|
1026
988
|
end
|
1027
|
-
|
1028
|
-
describe 'output' do
|
1029
|
-
it 'should be able to return itself as an array of arrays' do
|
1030
|
-
aoh = [
|
1031
|
-
{ a: '1', 'Two words' => '2', c: '3,123', d: 'apple' },
|
1032
|
-
{ a: '4', 'Two words' => '5', c: '6,412', d: 'orange' },
|
1033
|
-
{ a: '7', 'Two words' => '8', c: '$9,888', d: 'pear' }
|
1034
|
-
]
|
1035
|
-
tab = Table.from_aoh(aoh)
|
1036
|
-
aoa = tab.to_org
|
1037
|
-
expect(aoa.class).to eq Array
|
1038
|
-
expect(aoa[0].class).to eq Array
|
1039
|
-
expect(aoa[0][0]).to eq 'A'
|
1040
|
-
end
|
1041
|
-
|
1042
|
-
it 'should be able to output an org babel aoa' do
|
1043
|
-
# This is what the data looks like when called from org babel code
|
1044
|
-
# blocks.
|
1045
|
-
aoa =
|
1046
|
-
[['Ref', 'Date', 'Code', 'Raw', 'Shares', 'Price', 'Info', 'Bool'],
|
1047
|
-
nil,
|
1048
|
-
[1, '2013-05-02', 'P', 795_546.20, 795_546.2, 1.1850, 'ZMPEF1', 'T'],
|
1049
|
-
[2, '2013-05-02', 'P', 118_186.40, 118_186.4, 11.8500, 'ZMPEF1', 'T'],
|
1050
|
-
[7, '2013-05-20', 'S', 12_000.00, 5046.00, 28.2804, 'ZMEAC', 'F'],
|
1051
|
-
[8, '2013-05-20', 'S', 85_000.00, 35_742.50, 28.3224, 'ZMEAC', 'T'],
|
1052
|
-
[9, '2013-05-20', 'S', 33_302.00, 14_003.49, 28.6383, 'ZMEAC', 'T'],
|
1053
|
-
[10, '2013-05-23', 'S', 8000.00, 3364.00, 27.1083, 'ZMEAC', 'T'],
|
1054
|
-
[11, '2013-05-23', 'S', 23_054.00, 9694.21, 26.8015, 'ZMEAC', 'F'],
|
1055
|
-
[12, '2013-05-23', 'S', 39_906.00, 16_780.47, 25.1749, 'ZMEAC', 'T'],
|
1056
|
-
[13, '2013-05-29', 'S', 13_459.00, 5659.51, 24.7464, 'ZMEAC', 'T'],
|
1057
|
-
[14, '2013-05-29', 'S', 15_700.00, 6601.85, 24.7790, 'ZMEAC', 'F'],
|
1058
|
-
[15, '2013-05-29', 'S', 15_900.00, 6685.95, 24.5802, 'ZMEAC', 'T'],
|
1059
|
-
[16, '2013-05-30', 'S', 6_679.00, 2808.52, 25.0471, 'ZMEAC', 'T']]
|
1060
|
-
tg = Table.from_aoa(aoa).add_sum_footer([:raw, :shares, :price])
|
1061
|
-
aoa = tg.to_org(formats: { raw: '%,', shares: '%,', price: '%,4' })
|
1062
|
-
expect(aoa[-1][0]).to eq 'Total'
|
1063
|
-
expect(aoa[-1][1]).to eq ''
|
1064
|
-
expect(aoa[-1][2]).to eq ''
|
1065
|
-
expect(aoa[-1][3]).to eq '1,166,733'
|
1066
|
-
expect(aoa[-1][4]).to eq '1,020,119'
|
1067
|
-
expect(aoa[-1][5]).to eq '276.5135'
|
1068
|
-
end
|
1069
|
-
end
|
1070
989
|
end
|
1071
990
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fat_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel E. Doherty
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simplecov
|
@@ -208,6 +208,12 @@ files:
|
|
208
208
|
- lib/fat_core/date.rb
|
209
209
|
- lib/fat_core/enumerable.rb
|
210
210
|
- lib/fat_core/evaluator.rb
|
211
|
+
- lib/fat_core/formatters.rb
|
212
|
+
- lib/fat_core/formatters/aoa_formatter.rb
|
213
|
+
- lib/fat_core/formatters/aoh_formatter.rb
|
214
|
+
- lib/fat_core/formatters/formatter.rb
|
215
|
+
- lib/fat_core/formatters/org_formatter.rb
|
216
|
+
- lib/fat_core/formatters/text_formatter.rb
|
211
217
|
- lib/fat_core/hash.rb
|
212
218
|
- lib/fat_core/kernel.rb
|
213
219
|
- lib/fat_core/latex_eruby.rb
|
@@ -227,6 +233,11 @@ files:
|
|
227
233
|
- spec/lib/date_spec.rb
|
228
234
|
- spec/lib/enumerable_spec.rb
|
229
235
|
- spec/lib/evaluator_spec.rb
|
236
|
+
- spec/lib/formatters/aoa_formatter_spec.rb
|
237
|
+
- spec/lib/formatters/aoh_formatter_spec.rb
|
238
|
+
- spec/lib/formatters/formatter_spec.rb
|
239
|
+
- spec/lib/formatters/org_formatter_spec.rb
|
240
|
+
- spec/lib/formatters/text_formatter_spec.rb
|
230
241
|
- spec/lib/hash_spec.rb
|
231
242
|
- spec/lib/kernel_spec.rb
|
232
243
|
- spec/lib/nil_spec.rb
|
@@ -270,6 +281,11 @@ test_files:
|
|
270
281
|
- spec/lib/date_spec.rb
|
271
282
|
- spec/lib/enumerable_spec.rb
|
272
283
|
- spec/lib/evaluator_spec.rb
|
284
|
+
- spec/lib/formatters/aoa_formatter_spec.rb
|
285
|
+
- spec/lib/formatters/aoh_formatter_spec.rb
|
286
|
+
- spec/lib/formatters/formatter_spec.rb
|
287
|
+
- spec/lib/formatters/org_formatter_spec.rb
|
288
|
+
- spec/lib/formatters/text_formatter_spec.rb
|
273
289
|
- spec/lib/hash_spec.rb
|
274
290
|
- spec/lib/kernel_spec.rb
|
275
291
|
- spec/lib/nil_spec.rb
|