fat_table 0.9.7 → 0.9.9

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.
@@ -25,9 +25,9 @@ module FatTable
25
25
 
26
26
  # A Hash of Hashes with the outer Hash keyed on location. The value for
27
27
  # the outer Hash is an inner Hash keyed on column names. The values of
28
- # the inner Hash are OpenStruct objects that contain the formatting
29
- # instructions for the location and column. For example,
30
- # +format_at[:body][:shares].commas+ is set either true or false depending
28
+ # the inner Hash are hashes that contain the formatting instructions for
29
+ # the location and column. For example,
30
+ # +format_at[:body][:shares][:commas]+ is set either true or false depending
31
31
  # on whether the +:shares+ column in the table body is to have grouping
32
32
  # commas inserted in the output.
33
33
  attr_reader :format_at
@@ -111,7 +111,7 @@ module FatTable
111
111
  # hash of hashes. The outer hash is keyed on the location, and each inner
112
112
  # hash is keyed on either a column sym or a type sym, :string, :numeric,
113
113
  # :datetime, :boolean, or :nil. The value of the inner hashes are
114
- # OpenStruct structs.
114
+ # also hashes.
115
115
  @format_at = {}
116
116
  %i[header bfirst gfirst body footer gfooter].each do |loc|
117
117
  @format_at[loc] = {}
@@ -119,7 +119,7 @@ module FatTable
119
119
  fmt_hash = self.class.default_format
120
120
  fmt_hash[:_h] = h
121
121
  fmt_hash[:_location] = loc
122
- format_at[loc][h] = OpenStruct.new(fmt_hash)
122
+ format_at[loc][h] = fmt_hash
123
123
  end
124
124
  end
125
125
  yield self if block_given?
@@ -172,7 +172,7 @@ module FatTable
172
172
  # price.
173
173
  # fmtr.footer.('Summary', :shares, date: :avg, price: :avg)
174
174
  def footer(label, label_col = nil, *sum_cols, **agg_cols)
175
- foot = Footer.new(label, table, label_col: label_col)
175
+ foot = Footer.new(table, label: label, label_col: label_col)
176
176
  sum_cols.each do |h|
177
177
  foot.add_value(h, :sum)
178
178
  end
@@ -252,7 +252,7 @@ module FatTable
252
252
  # to the lamda's column.
253
253
  #
254
254
  def foot(label: 'Total', label_col: nil, **agg_cols)
255
- foot = Footer.new(label, table, label_col: label_col)
255
+ foot = Footer.new(table, label: label, label_col: label_col)
256
256
  agg_cols.each_pair do |h, agg|
257
257
  foot.add_value(h, agg)
258
258
  end
@@ -280,7 +280,7 @@ module FatTable
280
280
  # Do some sums and some other aggregates: sum shares, average date and
281
281
  # price. fmtr.gfooter.('Summary', :shares, date: :avg, price: :avg)
282
282
  def gfooter(label, label_col = nil, *sum_cols, **agg_cols)
283
- foot = Footer.new(label, table, label_col: label_col, group: true)
283
+ foot = Footer.new(table, label: label, label_col: label_col, group: true)
284
284
  sum_cols.each do |h|
285
285
  foot.add_value(h, :sum)
286
286
  end
@@ -377,7 +377,7 @@ module FatTable
377
377
  # values (using f[:other_col]) as well as the Column object corresponding
378
378
  # to the lamda's column.
379
379
  def gfoot(label: 'Group Total', label_col: nil, **agg_cols)
380
- foot = Footer.new(label, table, label_col: label_col, group: true)
380
+ foot = Footer.new(table, label: label, label_col: label_col, group: true)
381
381
  agg_cols.each_pair do |h, agg|
382
382
  foot.add_value(h, agg)
383
383
  end
@@ -683,8 +683,11 @@ module FatTable
683
683
  parse_typ_method_name = 'parse_' + typ.to_s + '_fmt'
684
684
  if fmts[h]
685
685
  # Merge in column formatting
686
- col_fmt = send(parse_typ_method_name, fmts[h],
687
- strict: location != :header).first
686
+ col_fmt = send(
687
+ parse_typ_method_name,
688
+ fmts[h],
689
+ strict: location != :header,
690
+ ).first
688
691
  format_h = format_h.merge(col_fmt)
689
692
  elsif fmts.key?(typ)
690
693
  # Merge in type-based formatting
@@ -697,18 +700,18 @@ module FatTable
697
700
  # format_for call with those locations.
698
701
  if location == :body
699
702
  format_h.each_pair do |k, v|
700
- if format_at[:bfirst][h].send(k) == self.class.default_format[k]
701
- format_at[:bfirst][h].send("#{k}=", v)
703
+ if format_at[:bfirst][h][k] == self.class.default_format[k]
704
+ format_at[:bfirst][h][k] = v
702
705
  end
703
- if format_at[:gfirst][h].send(k) == self.class.default_format[k]
704
- format_at[:gfirst][h].send("#{k}=", v)
706
+ if format_at[:gfirst][h][k] == self.class.default_format[k]
707
+ format_at[:gfirst][h][k] = v
705
708
  end
706
709
  end
707
710
  elsif location == :gfirst
708
711
  # Copy :gfirst formatting to :bfirst if it is still the default
709
712
  format_h.each_pair do |k, v|
710
- if format_at[:bfirst][h].send(k) == self.class.default_format[k]
711
- format_at[:bfirst][h].send("#{k}=", v)
713
+ if format_at[:bfirst][h][k] == self.class.default_format[k]
714
+ format_at[:bfirst][h][k] = v
712
715
  end
713
716
  end
714
717
  end
@@ -717,7 +720,7 @@ module FatTable
717
720
  # headers named h or location) and convert to struct
718
721
  format_h[:_h] = h
719
722
  format_h[:_location] = location
720
- format_at[location][h] = OpenStruct.new(format_h)
723
+ format_at[location][h] = format_h
721
724
  end
722
725
  self
723
726
  end
@@ -726,10 +729,10 @@ module FatTable
726
729
  # Parsing and validation routines
727
730
  ############################################################################
728
731
 
729
- private
730
-
731
732
  # Re to match a color name
732
- CLR_RE = /(?:[-_a-zA-Z0-9 ]*)/.freeze
733
+ CLR_RE = /(?:[-_a-zA-Z0-9 ]*)/
734
+
735
+ private
733
736
 
734
737
  # Return a hash that reflects the formatting instructions given in the
735
738
  # string fmt. Raise an error if it contains invalid formatting instructions.
@@ -753,27 +756,28 @@ module FatTable
753
756
  # parse, we remove the matched construct from fmt. At the end, any
754
757
  # remaining characters in fmt should be invalid.
755
758
  fmt_hash = {}
756
- if fmt =~ /c\[(?<co>#{CLR_RE})(\.(?<bg>#{CLR_RE}))?\]/
759
+ if fmt =~ /c\[(?<co>#{CLR_RE})(\.(?<bg>#{CLR_RE}))?\]/o
757
760
  fmt_hash[:color] = Regexp.last_match[:co] unless Regexp.last_match[:co].blank?
758
761
  fmt_hash[:bgcolor] = Regexp.last_match[:bg] unless Regexp.last_match[:bg].blank?
759
762
  validate_color(fmt_hash[:color])
760
763
  validate_color(fmt_hash[:bgcolor])
761
764
  fmt = fmt.sub($&, '')
762
765
  end
766
+ # binding.break
763
767
  # Nil formatting can apply to strings as well
764
768
  nil_hash, fmt = parse_nilclass_fmt(fmt)
765
769
  fmt_hash = fmt_hash.merge(nil_hash)
766
- if fmt =~ /u/
770
+ if fmt.include?('u')
767
771
  fmt_hash[:case] = :lower
768
- fmt = fmt.sub($&, '')
772
+ fmt = fmt.delete('u')
769
773
  end
770
- if fmt =~ /U/
774
+ if fmt.include?('U')
771
775
  fmt_hash[:case] = :upper
772
- fmt = fmt.sub($&, '')
776
+ fmt = fmt.delete('U')
773
777
  end
774
- if fmt =~ /t/
778
+ if fmt.include?('t')
775
779
  fmt_hash[:case] = :title
776
- fmt = fmt.sub($&, '')
780
+ fmt = fmt.delete('t')
777
781
  end
778
782
  if fmt =~ /(?<neg>~\s*)?B/
779
783
  fmt_hash[:bold] = !Regexp.last_match[:neg]
@@ -783,17 +787,17 @@ module FatTable
783
787
  fmt_hash[:italic] = !Regexp.last_match[:neg]
784
788
  fmt = fmt.sub($&, '')
785
789
  end
786
- if fmt =~ /R/
790
+ if fmt.include?('R')
787
791
  fmt_hash[:alignment] = :right
788
- fmt = fmt.sub($&, '')
792
+ fmt = fmt.delete('R')
789
793
  end
790
- if fmt =~ /C/
794
+ if fmt.include?('C')
791
795
  fmt_hash[:alignment] = :center
792
- fmt = fmt.sub($&, '')
796
+ fmt = fmt.delete('C')
793
797
  end
794
- if fmt =~ /L/
798
+ if fmt.include?('L')
795
799
  fmt_hash[:alignment] = :left
796
- fmt = fmt.sub($&, '')
800
+ fmt = fmt.delete('L')
797
801
  end
798
802
  if fmt =~ /(?<neg>~\s*)?_/
799
803
  fmt_hash[:underline] = !Regexp.last_match[:neg]
@@ -895,8 +899,8 @@ module FatTable
895
899
  end
896
900
  # Since true_text, false_text and nil_text may want to have internal
897
901
  # spaces, defer removing extraneous spaces until after they are parsed.
898
- if fmt =~ /c\[(#{CLR_RE})(\.(#{CLR_RE}))?,
899
- \s*(#{CLR_RE})(\.(#{CLR_RE}))?\]/x
902
+ if fmt =~ %r{c\[(#{CLR_RE})(\.(#{CLR_RE}))?,
903
+ \s*(#{CLR_RE})(\.(#{CLR_RE}))?\]}xo
900
904
  tco, _, tbg, fco, _, fbg = Regexp.last_match.captures
901
905
  fmt_hash[:true_color] = tco unless tco.blank?
902
906
  fmt_hash[:true_bgcolor] = tbg unless tbg.blank?
@@ -906,20 +910,20 @@ module FatTable
906
910
  end
907
911
  str_fmt_hash, fmt = parse_string_fmt(fmt)
908
912
  fmt_hash = fmt_hash.merge(str_fmt_hash)
909
- if fmt =~ /Y/
913
+ if fmt.include?('Y')
910
914
  fmt_hash[:true_text] = 'Y'
911
915
  fmt_hash[:false_text] = 'N'
912
- fmt = fmt.sub(Regexp.last_match[0], '')
916
+ fmt = fmt.delete('Y')
913
917
  end
914
- if fmt =~ /T/
918
+ if fmt.include?('T')
915
919
  fmt_hash[:true_text] = 'T'
916
920
  fmt_hash[:false_text] = 'F'
917
- fmt = fmt.sub(Regexp.last_match[0], '')
921
+ fmt = fmt.delete('T')
918
922
  end
919
- if fmt =~ /X/
923
+ if fmt.include?('X')
920
924
  fmt_hash[:true_text] = 'X'
921
925
  fmt_hash[:false_text] = ''
922
- fmt = fmt.sub(Regexp.last_match[0], '')
926
+ fmt = fmt.delete('X')
923
927
  end
924
928
  unless fmt.blank? || !strict
925
929
  raise UserError, "unrecognized boolean formatting instructions '#{fmt}'"
@@ -957,18 +961,18 @@ module FatTable
957
961
  str = format_boolean(val, istruct)
958
962
  str = format_string(str, istruct, width)
959
963
  true_istruct = istruct.dup
960
- true_istruct.color = istruct.true_color
961
- true_istruct.bgcolor = istruct.true_bgcolor
964
+ true_istruct[:color] = istruct[:true_color]
965
+ true_istruct[:bgcolor] = istruct[:true_bgcolor]
962
966
  decorate ? decorate_string(str, true_istruct) : str
963
967
  when FalseClass
964
968
  str = format_boolean(val, istruct)
965
969
  str = format_string(str, istruct, width)
966
970
  false_istruct = istruct.dup
967
- false_istruct.color = istruct.false_color
968
- false_istruct.bgcolor = istruct.false_bgcolor
971
+ false_istruct[:color] = istruct[:false_color]
972
+ false_istruct[:bgcolor] = istruct[:false_bgcolor]
969
973
  decorate ? decorate_string(str, false_istruct) : str
970
974
  when NilClass
971
- str = istruct.nil_text
975
+ str = istruct[:nil_text]
972
976
  str = format_string(str, istruct, width)
973
977
  decorate ? decorate_string(str, istruct) : str
974
978
  when String
@@ -996,9 +1000,9 @@ module FatTable
996
1000
  # formatting (e.g., color) can be done in a subclass of Formatter by
997
1001
  # specializing this method.
998
1002
  def format_boolean(val, istruct)
999
- return istruct.nil_text if val.nil?
1003
+ return istruct[:nil_text] if val.nil?
1000
1004
 
1001
- val ? istruct.true_text : istruct.false_text
1005
+ val ? istruct[:true_text] : istruct[:false_text]
1002
1006
  end
1003
1007
 
1004
1008
  # Convert a datetime to a string according to instructions in istruct, which
@@ -1007,13 +1011,13 @@ module FatTable
1007
1011
  # formatting (e.g., color) can be done in a subclass of Formatter by
1008
1012
  # specializing this method.
1009
1013
  def format_datetime(val, istruct)
1010
- return istruct.nil_text if val.nil?
1014
+ return istruct[:nil_text] if val.nil?
1011
1015
 
1012
1016
  if val.to_date == val
1013
1017
  # It is a Date, with no time component.
1014
- val.strftime(istruct.date_fmt)
1018
+ val.strftime(istruct[:date_fmt])
1015
1019
  else
1016
- val.strftime(istruct.datetime_fmt)
1020
+ val.strftime(istruct[:datetime_fmt])
1017
1021
  end
1018
1022
  end
1019
1023
 
@@ -1023,32 +1027,32 @@ module FatTable
1023
1027
  # formatting (e.g., color) can be done in a subclass of Formatter by
1024
1028
  # specializing this method.
1025
1029
  def format_numeric(val, istruct)
1026
- return istruct.nil_text if val.nil?
1027
- return val.secs_to_hms if istruct.hms
1030
+ return istruct[:nil_text] if val.nil?
1031
+ return val.secs_to_hms if istruct[:hms]
1028
1032
 
1029
- if istruct.commas
1033
+ if istruct[:commas]
1030
1034
  # Commify the whole number part if not done already.
1031
- result = val.commas(istruct.post_digits)
1035
+ result = val.commas(istruct[:post_digits])
1032
1036
  else
1033
- result = val.round(istruct.post_digits).to_s
1037
+ result = val.round(istruct[:post_digits]).to_s
1034
1038
  match = result.match(/\.(\d+)\z/)
1035
- if match && match[1]&.size < istruct.post_digits
1039
+ if match && (match[1]&.size&.< istruct[:post_digits])
1036
1040
  # Add trailing zeros to pad out post_digits
1037
- n_zeros = [istruct.post_digits - match[1].size, 0].max
1041
+ n_zeros = [istruct[:post_digits] - match[1].size, 0].max
1038
1042
  zeros = '0' * n_zeros
1039
- result = result + zeros
1043
+ result += zeros
1040
1044
  end
1041
1045
  result
1042
1046
  end
1043
1047
 
1044
- if istruct.pre_digits.positive?
1048
+ if istruct[:pre_digits].positive?
1045
1049
  match = result.match(/\A([\d,]+)(\.\d+)?\z/)
1046
1050
  whole_part = match[1]
1047
1051
  frac_part = match[2]
1048
- n_zeros = [istruct.pre_digits - whole_part.gsub(',', '').size, 0].max
1052
+ n_zeros = [istruct[:pre_digits] - whole_part.delete(',').size, 0].max
1049
1053
  result =
1050
1054
  if n_zeros.positive?
1051
- if istruct.commas
1055
+ if istruct[:commas]
1052
1056
  # Insert leading zeros with commas
1053
1057
  pre_comma_match = whole_part.match(/\A(\d+),/)
1054
1058
  if pre_comma_match
@@ -1059,7 +1063,7 @@ module FatTable
1059
1063
  zeros = ''
1060
1064
  if n_zeros.positive?
1061
1065
  zeros = "0" * n_zeros
1062
- if n_zeros > 3 && istruct.commas
1066
+ if n_zeros > 3 && istruct[:commas]
1063
1067
  zeros = zeros.reverse.gsub!(/([0-9]{3})/, "\\1,").reverse
1064
1068
  end
1065
1069
  end
@@ -1075,7 +1079,7 @@ module FatTable
1075
1079
  else
1076
1080
  result
1077
1081
  end
1078
- if istruct.currency
1082
+ if istruct[:currency]
1079
1083
  result = "#{FatTable.currency_symbol}#{result}"
1080
1084
  end
1081
1085
  result
@@ -1085,20 +1089,20 @@ module FatTable
1085
1089
  def format_string(val, istruct, width = nil)
1086
1090
  val = istruct.nil_text if val.nil?
1087
1091
  val =
1088
- case istruct.case
1092
+ case istruct[:case]
1089
1093
  when :lower
1090
1094
  val.downcase
1091
1095
  when :upper
1092
1096
  val.upcase
1093
1097
  when :title
1094
- # Note: fat_core entitle keeps all uppercase words as upper case,
1098
+ # NOTE: fat_core entitle keeps all uppercase words as upper case,
1095
1099
  val.downcase.entitle
1096
1100
  when :none
1097
1101
  val
1098
1102
  end
1099
1103
  if width && aligned?
1100
1104
  pad = [width - width(val), 0].max
1101
- case istruct.alignment
1105
+ case istruct[:alignment]
1102
1106
  when :left
1103
1107
  val += ' ' * pad
1104
1108
  when :right
@@ -1229,7 +1233,10 @@ module FatTable
1229
1233
 
1230
1234
  # If this Formatter targets a ruby data structure (e.g., AoaFormatter), we
1231
1235
  # eval the string to get the object.
1236
+ #
1237
+ # rubocop:disable Security/Eval
1232
1238
  evaluate? ? eval(result) : result
1239
+ # rubocop:enable Security/Eval
1233
1240
  end
1234
1241
 
1235
1242
  private
@@ -1244,7 +1251,7 @@ module FatTable
1244
1251
  map = {}
1245
1252
  table.headers.each do |h|
1246
1253
  istruct = format_at[:header][h]
1247
- map[h] = [h, format_cell(h.as_string, istruct, decorate: decorate)]
1254
+ map[h] = [h, format_cell(h.entitle, istruct, decorate: decorate)]
1248
1255
  end
1249
1256
  map
1250
1257
  end
@@ -1277,7 +1284,7 @@ module FatTable
1277
1284
  end
1278
1285
 
1279
1286
  out_row = {}
1280
- row.each_pair do |h, v|
1287
+ row.each_pair do |h, _v|
1281
1288
  istruct = format_at[location][h]
1282
1289
  out_row[h] = [row[h], format_cell(row[h], istruct, decorate: decorate)]
1283
1290
  end
@@ -1285,9 +1292,9 @@ module FatTable
1285
1292
  tbl_row_k += 1
1286
1293
  end
1287
1294
  # Format group footers
1288
- gfooters.each_pair do |label, gfooter|
1295
+ gfooters.each_pair do |_label, gfooter|
1289
1296
  out_rows << nil
1290
- gfoot_row = Hash.new([nil, ''])
1297
+ gfoot_row = Hash.new([nil, ''].freeze)
1291
1298
  gfooter.to_h(grp_k).each_pair do |h, v|
1292
1299
  istruct = format_at[:gfooter][h]
1293
1300
  gfoot_row[h] = [v, format_cell(v, istruct, decorate: decorate)]
@@ -1304,9 +1311,9 @@ module FatTable
1304
1311
  decorate = !aligned?
1305
1312
  out_rows = []
1306
1313
 
1307
- footers.each_pair do |label, foot|
1314
+ footers.each_pair do |_label, foot|
1308
1315
  out_rows << nil
1309
- foot_row = Hash.new([nil, ''])
1316
+ foot_row = Hash.new([nil, ''].freeze)
1310
1317
  foot.to_h.each_pair do |h, v|
1311
1318
  istruct = format_at[:gfooter][h]
1312
1319
  foot_row[h] = [v, format_cell(v, istruct, decorate: decorate)]
@@ -26,58 +26,8 @@ module FatTable
26
26
  end
27
27
 
28
28
  # Taken from the Rainbow gem's list of valid colors.
29
- self.valid_colors = %w[
30
- none black blue brown cyan darkgray gray green lightgray lime magenta
31
- olive orange pink purple red teal violet white yellow AntiqueWhite1
32
- AntiqueWhite2 AntiqueWhite3 AntiqueWhite4 Aquamarine1 Aquamarine2
33
- Aquamarine3 Aquamarine4 Azure1 Azure2 Azure3 Azure4 Bisque1 Bisque2
34
- Bisque3 Bisque4 Blue1 Blue2 Blue3 Blue4 Brown1 Brown2 Brown3 Brown4
35
- Burlywood1 Burlywood2 Burlywood3 Burlywood4 CadetBlue1 CadetBlue2
36
- CadetBlue3 CadetBlue4 Chartreuse1 Chartreuse2 Chartreuse3 Chartreuse4
37
- Chocolate1 Chocolate2 Chocolate3 Chocolate4 Coral1 Coral2 Coral3 Coral4
38
- Cornsilk1 Cornsilk2 Cornsilk3 Cornsilk4 Cyan1 Cyan2 Cyan3 Cyan4
39
- DarkGoldenrod1 DarkGoldenrod2 DarkGoldenrod3 DarkGoldenrod4
40
- DarkOliveGreen1 DarkOliveGreen2 DarkOliveGreen3 DarkOliveGreen4
41
- DarkOrange1 DarkOrange2 DarkOrange3 DarkOrange4 DarkOrchid1 DarkOrchid2
42
- DarkOrchid3 DarkOrchid4 DarkSeaGreen1 DarkSeaGreen2 DarkSeaGreen3
43
- DarkSeaGreen4 DarkSlateGray1 DarkSlateGray2 DarkSlateGray3 DarkSlateGray4
44
- DeepPink1 DeepPink2 DeepPink3 DeepPink4 DeepSkyBlue1 DeepSkyBlue2
45
- DeepSkyBlue3 DeepSkyBlue4 DodgerBlue1 DodgerBlue2 DodgerBlue3 DodgerBlue4
46
- Firebrick1 Firebrick2 Firebrick3 Firebrick4 Gold1 Gold2 Gold3 Gold4
47
- Goldenrod1 Goldenrod2 Goldenrod3 Goldenrod4 Gray0 Green0 Green1 Green2
48
- Green3 Green4 Grey0 Honeydew1 Honeydew2 Honeydew3 Honeydew4 HotPink1
49
- HotPink2 HotPink3 HotPink4 IndianRed1 IndianRed2 IndianRed3 IndianRed4
50
- Ivory1 Ivory2 Ivory3 Ivory4 Khaki1 Khaki2 Khaki3 Khaki4 LavenderBlush1
51
- LavenderBlush2 LavenderBlush3 LavenderBlush4 LemonChiffon1 LemonChiffon2
52
- LemonChiffon3 LemonChiffon4 LightBlue1 LightBlue2 LightBlue3 LightBlue4
53
- LightCyan1 LightCyan2 LightCyan3 LightCyan4 LightGoldenrod1
54
- LightGoldenrod2 LightGoldenrod3 LightGoldenrod4 LightPink1 LightPink2
55
- LightPink3 LightPink4 LightSalmon1 LightSalmon2 LightSalmon3 LightSalmon4
56
- LightSkyBlue1 LightSkyBlue2 LightSkyBlue3 LightSkyBlue4 LightSteelBlue1
57
- LightSteelBlue2 LightSteelBlue3 LightSteelBlue4 LightYellow1 LightYellow2
58
- LightYellow3 LightYellow4 Magenta1 Magenta2 Magenta3 Magenta4 Maroon0
59
- Maroon1 Maroon2 Maroon3 Maroon4 MediumOrchid1 MediumOrchid2 MediumOrchid3
60
- MediumOrchid4 MediumPurple1 MediumPurple2 MediumPurple3 MediumPurple4
61
- MistyRose1 MistyRose2 MistyRose3 MistyRose4 NavajoWhite1 NavajoWhite2
62
- NavajoWhite3 NavajoWhite4 OliveDrab1 OliveDrab2 OliveDrab3 OliveDrab4
63
- Orange1 Orange2 Orange3 Orange4 OrangeRed1 OrangeRed2 OrangeRed3
64
- OrangeRed4 Orchid1 Orchid2 Orchid3 Orchid4 PaleGreen1 PaleGreen2
65
- PaleGreen3 PaleGreen4 PaleTurquoise1 PaleTurquoise2 PaleTurquoise3
66
- PaleTurquoise4 PaleVioletRed1 PaleVioletRed2 PaleVioletRed3 PaleVioletRed4
67
- PeachPuff1 PeachPuff2 PeachPuff3 PeachPuff4 Pink1 Pink2 Pink3 Pink4 Plum1
68
- Plum2 Plum3 Plum4 Purple0 Purple1 Purple2 Purple3 Purple4 Red1 Red2 Red3
69
- Red4 RosyBrown1 RosyBrown2 RosyBrown3 RosyBrown4 RoyalBlue1 RoyalBlue2
70
- RoyalBlue3 RoyalBlue4 Salmon1 Salmon2 Salmon3 Salmon4 SeaGreen1 SeaGreen2
71
- SeaGreen3 SeaGreen4 Seashell1 Seashell2 Seashell3 Seashell4 Sienna1
72
- Sienna2 Sienna3 Sienna4 SkyBlue1 SkyBlue2 SkyBlue3 SkyBlue4 SlateBlue1
73
- SlateBlue2 SlateBlue3 SlateBlue4 SlateGray1 SlateGray2 SlateGray3
74
- SlateGray4 Snow1 Snow2 Snow3 Snow4 SpringGreen1 SpringGreen2 SpringGreen3
75
- SpringGreen4 SteelBlue1 SteelBlue2 SteelBlue3 SteelBlue4 Tan1 Tan2 Tan3
76
- Tan4 Thistle1 Thistle2 Thistle3 Thistle4 Tomato1 Tomato2 Tomato3 Tomato4
77
- Turquoise1 Turquoise2 Turquoise3 Turquoise4 VioletRed1 VioletRed2
78
- VioletRed3 VioletRed4 Wheat1 Wheat2 Wheat3 Wheat4 Yellow1 Yellow2 Yellow3
79
- Yellow4
80
- ]
29
+
30
+ self.valid_colors = File.readlines(File.join(__dir__, 'xcolors.txt'), chomp: true)
81
31
 
82
32
  # LaTeX commands to load the needed packages based on the :environement
83
33
  # option. For now, just handles the default 'longtable' :environment. The
@@ -101,18 +51,18 @@ module FatTable
101
51
  # default.
102
52
  def decorate_string(str, istruct)
103
53
  str = quote(str)
104
- result = istruct.italic ? "\\itshape{#{str}}" : str
105
- result = istruct.bold ? "\\bfseries{#{result}}" : result
106
- if istruct.color && istruct.color != 'none'
107
- result = "{\\textcolor{#{istruct.color}}{#{result}}}"
54
+ result = istruct[:italic] ? "\\itshape{#{str}}" : str
55
+ result = istruct[:bold] ? "\\bfseries{#{result}}" : result
56
+ if istruct[:color] && istruct[:color] != 'none'
57
+ result = "{\\textcolor{#{istruct[:color]}}{#{result}}}"
108
58
  end
109
- if istruct.bgcolor && istruct.bgcolor != 'none'
110
- result = "{\\cellcolor{#{istruct.bgcolor}}{#{result}}}"
59
+ if istruct[:bgcolor] && istruct[:bgcolor] != 'none'
60
+ result = "{\\cellcolor{#{istruct[:bgcolor]}}{#{result}}}"
111
61
  end
112
- if (istruct._h && format_at[:body][istruct._h] &&
113
- istruct.alignment != format_at[:body][istruct._h].alignment) ||
114
- (istruct._h.nil? && istruct.alignment.to_sym != :left)
115
- ac = alignment_code(istruct.alignment)
62
+ if (istruct[:_h] && format_at[:body][istruct[:_h]] &&
63
+ istruct[:alignment] != format_at[:body][istruct[:_h]][:alignment]) ||
64
+ (istruct[:_h].nil? && istruct[:alignment].to_sym != :left)
65
+ ac = alignment_code(istruct[:alignment])
116
66
  result = "\\multicolumn{1}{#{ac}}{#{result}}"
117
67
  end
118
68
  result
@@ -148,7 +98,7 @@ module FatTable
148
98
  end
149
99
  result += "\\begin{#{@options[:environment]}}{"
150
100
  table.headers.each do |h|
151
- result += alignment_code(format_at[:body][h].alignment)
101
+ result += alignment_code(format_at[:body][h][:alignment])
152
102
  end
153
103
  result += "}\n"
154
104
  result
@@ -41,14 +41,32 @@ module FatTable
41
41
  # Add ANSI codes to string to implement the given decorations
42
42
  def decorate_string(str, istruct)
43
43
  result = Rainbow(str)
44
- result = colorize(result, istruct.color, istruct.bgcolor)
45
- result = result.bold if istruct.bold
46
- result = result.italic if istruct.italic
47
- result = result.underline if istruct.underline
48
- result = result.blink if istruct.blink
44
+ result = colorize(result, istruct[:color], istruct[:bgcolor])
45
+ result = result.bold if istruct[:bold]
46
+ result = result.italic if istruct[:italic]
47
+ result = result.underline if istruct[:underline]
48
+ result = result.blink if istruct[:blink]
49
49
  result
50
50
  end
51
51
 
52
+ # :stopdoc:
53
+ # Unicode line-drawing characters. We use double lines before and after the
54
+ # table and single lines for the sides and hlines between groups and
55
+ # footers.
56
+ UPPER_LEFT = "\u2552"
57
+ UPPER_RIGHT = "\u2555"
58
+ DOUBLE_RULE = "\u2550"
59
+ UPPER_TEE = "\u2564"
60
+ VERTICAL_RULE = "\u2502"
61
+ LEFT_TEE = "\u251C"
62
+ HORIZONTAL_RULE = "\u2500"
63
+ SINGLE_CROSS = "\u253C"
64
+ RIGHT_TEE = "\u2524"
65
+ LOWER_LEFT = "\u2558"
66
+ LOWER_RIGHT = "\u255B"
67
+ LOWER_TEE = "\u2567"
68
+ # :startdoc:
69
+
52
70
  private
53
71
 
54
72
  def color_valid?(clr)
@@ -99,24 +117,6 @@ module FatTable
99
117
  colorize(str, @options[:frame_fg], @options[:frame_bg])
100
118
  end
101
119
 
102
- # :stopdoc:
103
- # Unicode line-drawing characters. We use double lines before and after the
104
- # table and single lines for the sides and hlines between groups and
105
- # footers.
106
- UPPER_LEFT = "\u2552"
107
- UPPER_RIGHT = "\u2555"
108
- DOUBLE_RULE = "\u2550"
109
- UPPER_TEE = "\u2564"
110
- VERTICAL_RULE = "\u2502"
111
- LEFT_TEE = "\u251C"
112
- HORIZONTAL_RULE = "\u2500"
113
- SINGLE_CROSS = "\u253C"
114
- RIGHT_TEE = "\u2524"
115
- LOWER_LEFT = "\u2558"
116
- LOWER_RIGHT = "\u255B"
117
- LOWER_TEE = "\u2567"
118
- # :startdoc:
119
-
120
120
  def upper_left
121
121
  if options[:unicode]
122
122
  UPPER_LEFT