fat_table 0.6.6 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9661335d0ae8ec4d87b9e16c3055552af05a354c5222b9838d51f8109ddd749
4
- data.tar.gz: fe23c745a61b2fff7d3380221ee133b5e38c3bdd9d4ff429bdce2094cbe47755
3
+ metadata.gz: ba8791fd0b89302cb5127adc325afd0a84bee337298955ecb48119805bcff53a
4
+ data.tar.gz: da6f4923fe75df0707c3fc21f96fef52127188e76f8a9ae1b923ea768689d31e
5
5
  SHA512:
6
- metadata.gz: 201d3df5ba9820b96e22b1a035013c128c2f8cf2efd054cd16b9b6f372c13381334db9cc11b268daa0537d25e2d0475c35cd73f1749d08d8a008a2498010ead1
7
- data.tar.gz: e067fc5bedae6541e0ce88e41025fffbff64a16a3545fccd89a6b171f2b6d648fd8e1716227ceafd770db509417361781c3c6d4cc718824ec8b9098a266eafab
6
+ metadata.gz: 7f9b047a93e55f7752173dc7f2c927db2bf45669ede7de1d652b89f1052054f90763c7910b850f84d80ea86a959c82e48f9f9d5b5fe9192ff6b15f9dabb104a7
7
+ data.tar.gz: 498eb355cce5f5fa8597ad23657d4699cfead201b6bbf5200386f50773c846061199de0373edbe41ff94c79e1a5d90da8c1f9a37d275c580a0a021109c2d8780
@@ -53,35 +53,38 @@ module FatTable
53
53
  # 'Average'.
54
54
  attr_reader :gfooters
55
55
 
56
- class_attribute :default_format
57
- self.default_format = {
58
- nil_text: '',
59
- case: :none,
60
- alignment: :left,
61
- bold: false,
62
- italic: false,
63
- color: 'none',
64
- bgcolor: 'none',
65
- hms: false,
66
- pre_digits: 0,
67
- post_digits: 0,
68
- commas: false,
69
- currency: false,
70
- datetime_fmt: '%F %H:%M:%S',
71
- date_fmt: '%F',
72
- true_text: 'T',
73
- false_text: 'F',
74
- true_color: 'none',
75
- true_bgcolor: 'none',
76
- false_color: 'none',
77
- false_bgcolor: 'none',
78
- underline: false,
79
- blink: false,
80
- }
81
-
82
56
  class_attribute :valid_colors
83
57
  self.valid_colors = ['none']
84
58
 
59
+ def self.default_format
60
+ {
61
+ nil_text: '',
62
+ case: :none,
63
+ alignment: :left,
64
+ bold: false,
65
+ italic: false,
66
+ color: 'none',
67
+ bgcolor: 'none',
68
+ hms: false,
69
+ pre_digits: 0,
70
+ post_digits: 0,
71
+ commas: false,
72
+ currency: false,
73
+ datetime_fmt: '%F %H:%M:%S',
74
+ date_fmt: '%F',
75
+ true_text: 'T',
76
+ false_text: 'F',
77
+ true_color: 'none',
78
+ true_bgcolor: 'none',
79
+ false_color: 'none',
80
+ false_bgcolor: 'none',
81
+ underline: false,
82
+ blink: false,
83
+ _h: nil,
84
+ _location: nil
85
+ }
86
+ end
87
+
85
88
  # :category: Constructors
86
89
 
87
90
  # Return a new Formatter for the given +table+ which must be of the class
@@ -659,7 +662,7 @@ module FatTable
659
662
  # hash.
660
663
  format_h =
661
664
  if format_at[location][h].empty?
662
- default_format.dup
665
+ default_format
663
666
  else
664
667
  format_at[location][h].to_h
665
668
  end
@@ -700,17 +703,17 @@ module FatTable
700
703
  # format_for call with those locations.
701
704
  if location == :body
702
705
  format_h.each_pair do |k, v|
703
- if format_at[:bfirst][h].send(k) == default_format[k]
706
+ if format_at[:bfirst][h].send(k) == self.class.default_format[k]
704
707
  format_at[:bfirst][h].send("#{k}=", v)
705
708
  end
706
- if format_at[:gfirst][h].send(k) == default_format[k]
709
+ if format_at[:gfirst][h].send(k) == self.class.default_format[k]
707
710
  format_at[:gfirst][h].send("#{k}=", v)
708
711
  end
709
712
  end
710
713
  elsif location == :gfirst
711
714
  # Copy :gfirst formatting to :bfirst if it is still the default
712
715
  format_h.each_pair do |k, v|
713
- if format_at[:bfirst][h].send(k) == default_format[k]
716
+ if format_at[:bfirst][h].send(k) == self.class.default_format[k]
714
717
  format_at[:bfirst][h].send("#{k}=", v)
715
718
  end
716
719
  end
@@ -942,9 +945,10 @@ module FatTable
942
945
  # Convert a value to a string based on the instructions in istruct,
943
946
  # depending on the type of val. "Formatting," which changes the content of
944
947
  # the string, such as adding commas, is always performed, except alignment
945
- # which is only performed when the width parameter is non-nil. "Decorating",
946
- # which changes the appearance without changing the content, is performed
947
- # only if the decorate parameter is true.
948
+ # which is only performed when the width parameter is
949
+ # non-nil. "Decorating", which changes the appearance without changing the
950
+ # content, is performed only if the decorate parameter is true. Priority:
951
+ # lowest to highest: type, location, column_name
948
952
  def format_cell(val, istruct, width: nil, decorate: false)
949
953
  case val
950
954
  when Numeric
@@ -982,8 +986,6 @@ module FatTable
982
986
  end
983
987
  end
984
988
 
985
- private
986
-
987
989
  # Add LaTeX control sequences, ANSI terminal escape codes, or other
988
990
  # decorations to string to decorate it with the given attributes. None of
989
991
  # the decorations may affect the displayed width of the string. Return the
@@ -992,6 +994,8 @@ module FatTable
992
994
  str
993
995
  end
994
996
 
997
+ private
998
+
995
999
  # Convert a boolean to a string according to instructions in istruct, which
996
1000
  # is assumed to be the result of parsing a formatting instruction string as
997
1001
  # above. Only device-independent formatting is done here. Device dependent
@@ -1099,7 +1103,7 @@ module FatTable
1099
1103
  val
1100
1104
  end
1101
1105
  if width && aligned?
1102
- pad = width - width(val)
1106
+ pad = [width - width(val), 0].max
1103
1107
  case istruct.alignment
1104
1108
  when :left
1105
1109
  val += ' ' * pad
@@ -95,18 +95,6 @@ module FatTable
95
95
  result
96
96
  end
97
97
 
98
- private
99
-
100
- def color_valid?(clr)
101
- valid_colors.include?(clr)
102
- end
103
-
104
- def invalid_color_msg(clr)
105
- valid_colors_list = valid_colors.join(' ').wrap
106
- "LaTeXFormatter invalid color '#{clr}'. Valid colors are:\n" +
107
- valid_colors_list
108
- end
109
-
110
98
  # Add LaTeX control sequences. Ignore background color, underline, and
111
99
  # blink. Alignment needs to be done by LaTeX, so we have to take it into
112
100
  # account unless it's the same as the body alignment, since that is the
@@ -119,15 +107,29 @@ module FatTable
119
107
  result = "{\\textcolor{#{istruct.color}}{#{result}}}"
120
108
  end
121
109
  if istruct.bgcolor && istruct.bgcolor != 'none'
122
- result = "\\cellcolor{#{istruct.bgcolor}}#{result}"
110
+ result = "{\\cellcolor{#{istruct.bgcolor}}{#{result}}}"
123
111
  end
124
- unless istruct.alignment == format_at[:body][istruct._h].alignment
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)
125
115
  ac = alignment_code(istruct.alignment)
126
116
  result = "\\multicolumn{1}{#{ac}}{#{result}}"
127
117
  end
128
118
  result
129
119
  end
130
120
 
121
+ private
122
+
123
+ def color_valid?(clr)
124
+ valid_colors.include?(clr)
125
+ end
126
+
127
+ def invalid_color_msg(clr)
128
+ valid_colors_list = valid_colors.join(' ').wrap
129
+ "LaTeXFormatter invalid color '#{clr}'. Valid colors are:\n" +
130
+ valid_colors_list
131
+ end
132
+
131
133
  # Return +str+ with quote marks oriented and special TeX characters quoted.
132
134
  def quote(str)
133
135
  # Replace single and double quotes with TeX oriented quotes.
@@ -159,7 +161,7 @@ module FatTable
159
161
  end
160
162
 
161
163
  def alignment_code(al_sym)
162
- case al_sym
164
+ case al_sym.to_sym
163
165
  when :center
164
166
  'c'
165
167
  when :right
@@ -6,9 +6,12 @@ module FatTable
6
6
  # timestamps and the connector at the beginning of hlines is a '|' rather than
7
7
  # a '+' as for text tables.
8
8
  class OrgFormatter < Formatter
9
- self.default_format = default_format.dup
10
- default_format[:date_fmt] = '[%F %a]'
11
- default_format[:datetime_fmt] = '[%F %a %H:%M:%S]'
9
+ def self.default_format
10
+ fmt = super
11
+ fmt[:date_fmt] = '[%F %a]'
12
+ fmt[:datetime_fmt] = '[%F %a %H:%M:%S]'
13
+ fmt
14
+ end
12
15
 
13
16
  private
14
17
 
@@ -38,6 +38,17 @@ module FatTable
38
38
  self.valid_colors = ['none'] +
39
39
  ::Rainbow::X11ColorNames::NAMES.keys.map(&:to_s).sort
40
40
 
41
+ # Add ANSI codes to string to implement the given decorations
42
+ def decorate_string(str, istruct)
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
49
+ result
50
+ end
51
+
41
52
  private
42
53
 
43
54
  def color_valid?(clr)
@@ -66,17 +77,6 @@ module FatTable
66
77
  str.gsub(/\e\[[0-9;]+m/, '')
67
78
  end
68
79
 
69
- # Add ANSI codes to string to implement the given decorations
70
- def decorate_string(str, istruct)
71
- result = Rainbow(str)
72
- result = colorize(result, istruct.color, istruct.bgcolor)
73
- result = result.bold if istruct.bold
74
- result = result.italic if istruct.italic
75
- result = result.underline if istruct.underline
76
- result = result.blink if istruct.blink
77
- result
78
- end
79
-
80
80
  def colorize(str, fg_color, bg_color)
81
81
  fg_color = nil if fg_color == 'none'
82
82
  bg_color = nil if bg_color == 'none'
@@ -2,5 +2,5 @@
2
2
 
3
3
  module FatTable
4
4
  # The current version of FatTable
5
- VERSION = '0.6.6'
5
+ VERSION = '0.7.0'
6
6
  end
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.6.6
4
+ version: 0.7.0
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: 2023-01-09 00:00:00.000000000 Z
11
+ date: 2023-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler