fat_table 0.4.0 → 0.4.2
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/.rspec +2 -1
- data/lib/fat_table/formatters/formatter.rb +11 -6
- data/lib/fat_table/table.rb +29 -8
- data/lib/fat_table/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0f33bfa7f3d9d9c21cbc214a64c5d4f89d917dc9e704e6f7dae710630ff0907
|
4
|
+
data.tar.gz: 9bd6f3ed31da1fd4a120be80e47b1a262c846efefee24e4ed6aee47ccc5d8107
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bb8871cce72b3a70dbdf4ed114395f86d48003f0a6e590e8e3c691913625c085a4e64f067a28b278723804a5fd19deb6f5d8cc0c8ef658958163835168f2a89
|
7
|
+
data.tar.gz: efce3072c71e2231fc3768cfae9ad81d0af45a8403e0e17677c3a99b1f5dfdb57e9e69d8bbb27024db17c343e364f34e89bc982abf8d318e29c5b97acad0f5be
|
data/.rspec
CHANGED
@@ -500,7 +500,7 @@ module FatTable
|
|
500
500
|
format_h = format_h.merge(typ_fmt)
|
501
501
|
end
|
502
502
|
if fmts.key?(:nil)
|
503
|
-
typ_fmt =
|
503
|
+
typ_fmt = parse_nilclass_fmt(fmts[:nil]).first
|
504
504
|
format_h = format_h.merge(typ_fmt)
|
505
505
|
end
|
506
506
|
end
|
@@ -587,7 +587,7 @@ module FatTable
|
|
587
587
|
fmt = fmt.sub($&, '')
|
588
588
|
end
|
589
589
|
# Nil formatting can apply to strings as well
|
590
|
-
nil_hash, fmt =
|
590
|
+
nil_hash, fmt = parse_nilclass_fmt(fmt)
|
591
591
|
fmt_hash = fmt_hash.merge(nil_hash)
|
592
592
|
if fmt =~ /u/
|
593
593
|
fmt_hash[:case] = :lower
|
@@ -636,7 +636,7 @@ module FatTable
|
|
636
636
|
# instructions and the unconsumed part of the instruction string. This is
|
637
637
|
# called to cull nil-based instructions from a formatting string intended
|
638
638
|
# for other types, such as numeric, etc.
|
639
|
-
def
|
639
|
+
def parse_nilclass_fmt(fmt, _strict: true)
|
640
640
|
# We parse the more complex formatting constructs first, and after each
|
641
641
|
# parse, we remove the matched construct from fmt. At the end, any
|
642
642
|
# remaining characters in fmt should be invalid.
|
@@ -855,11 +855,16 @@ module FatTable
|
|
855
855
|
result = val.secs_to_hms
|
856
856
|
istruct.commas = false
|
857
857
|
elsif istruct.currency
|
858
|
-
prec = istruct.post_digits.zero? ? 2 : istruct.post_digits
|
859
858
|
delim = istruct.commas ? ',' : ''
|
860
|
-
result =
|
859
|
+
result =
|
860
|
+
if istruct.post_digits < 0
|
861
|
+
val.to_s(:currency, delimiter: delim,
|
861
862
|
unit: FatTable.currency_symbol)
|
862
|
-
|
863
|
+
else
|
864
|
+
val.to_s(:currency, precision: istruct.post_digits, delimiter: delim,
|
865
|
+
unit: FatTable.currency_symbol)
|
866
|
+
end
|
867
|
+
# istruct.commas = false
|
863
868
|
elsif istruct.pre_digits.positive?
|
864
869
|
if val.whole?
|
865
870
|
# No fractional part, ignore post_digits
|
data/lib/fat_table/table.rb
CHANGED
@@ -67,6 +67,23 @@ module FatTable
|
|
67
67
|
@boundaries = []
|
68
68
|
end
|
69
69
|
|
70
|
+
# :category: Constructors
|
71
|
+
|
72
|
+
# Return an empty duplicate of self. This allows the library to create an
|
73
|
+
# empty table that preserves all the instance variables from self. Even
|
74
|
+
# though FatTable::Table objects have no instance variables, a class that
|
75
|
+
# inherits from it might.
|
76
|
+
def empty_dup
|
77
|
+
self.dup.__empty!
|
78
|
+
end
|
79
|
+
|
80
|
+
def __empty!
|
81
|
+
@columns = []
|
82
|
+
@boundaries = []
|
83
|
+
self
|
84
|
+
end
|
85
|
+
|
86
|
+
|
70
87
|
# :category: Constructors
|
71
88
|
|
72
89
|
# Construct a Table from the contents of a CSV file named +fname+. Headers
|
@@ -597,8 +614,12 @@ module FatTable
|
|
597
614
|
key1 <=> key2
|
598
615
|
end
|
599
616
|
# Add the new rows to the table, but mark a group boundary at the points
|
600
|
-
# where the sort key changes value.
|
601
|
-
|
617
|
+
# where the sort key changes value. NB: I use self.class.new here
|
618
|
+
# rather than Table.new because if this class is inherited, I want the
|
619
|
+
# new_tab to be an instance of the subclass. With Table.new, this
|
620
|
+
# method's result will be an instance of FatTable::Table rather than of
|
621
|
+
# the subclass.
|
622
|
+
new_tab = empty_dup
|
602
623
|
last_key = nil
|
603
624
|
new_rows.each_with_index do |nrow, k|
|
604
625
|
new_tab << nrow
|
@@ -713,7 +734,7 @@ module FatTable
|
|
713
734
|
before: before_hook,
|
714
735
|
after: after_hook)
|
715
736
|
# Compute the new Table from this Table
|
716
|
-
result =
|
737
|
+
result = empty_dup
|
717
738
|
normalize_boundaries
|
718
739
|
rows.each_with_index do |old_row, old_k|
|
719
740
|
# Set the group number in the before hook and run the hook with the
|
@@ -770,7 +791,7 @@ module FatTable
|
|
770
791
|
# tab.where('@row.even? && shares > 500') => even rows with lots of shares
|
771
792
|
def where(expr)
|
772
793
|
expr = expr.to_s
|
773
|
-
result =
|
794
|
+
result = empty_dup
|
774
795
|
headers.each do |h|
|
775
796
|
col = Column.new(header: h)
|
776
797
|
result.add_column(col)
|
@@ -792,7 +813,7 @@ module FatTable
|
|
792
813
|
# Return a new table with all duplicate rows eliminated. Resets groups. Same
|
793
814
|
# as #uniq.
|
794
815
|
def distinct
|
795
|
-
result =
|
816
|
+
result = empty_dup
|
796
817
|
uniq_rows = rows.uniq
|
797
818
|
uniq_rows.each do |row|
|
798
819
|
result << row
|
@@ -904,7 +925,7 @@ module FatTable
|
|
904
925
|
raise UserError, msg
|
905
926
|
end
|
906
927
|
other_rows = other.rows.map { |r| r.replace_keys(headers) }
|
907
|
-
result =
|
928
|
+
result = empty_dup
|
908
929
|
new_rows = rows.send(oper, other_rows)
|
909
930
|
new_rows.each_with_index do |row, k|
|
910
931
|
result << row
|
@@ -1011,7 +1032,7 @@ module FatTable
|
|
1011
1032
|
join_exp, other_common_heads =
|
1012
1033
|
build_join_expression(exps, other, join_type)
|
1013
1034
|
ev = Evaluator.new
|
1014
|
-
result =
|
1035
|
+
result = empty_dup
|
1015
1036
|
other_rows = other.rows
|
1016
1037
|
other_row_matches = Array.new(other_rows.size, false)
|
1017
1038
|
rows.each do |self_row|
|
@@ -1259,7 +1280,7 @@ module FatTable
|
|
1259
1280
|
groups = sorted_tab.rows.group_by do |r|
|
1260
1281
|
group_cols.map { |k| r[k] }
|
1261
1282
|
end
|
1262
|
-
result =
|
1283
|
+
result = empty_dup
|
1263
1284
|
groups.each_pair do |_vals, grp_rows|
|
1264
1285
|
result << row_from_group(grp_rows, group_cols, agg_cols)
|
1265
1286
|
end
|
data/lib/fat_table/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fat_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
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: 2022-01-
|
11
|
+
date: 2022-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|