tty-table 0.11.0 → 0.12.0
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/CHANGELOG.md +13 -0
- data/LICENSE.txt +1 -1
- data/README.md +104 -98
- data/lib/tty-table.rb +1 -1
- data/lib/tty/table.rb +70 -34
- data/lib/tty/table/alignment_set.rb +1 -3
- data/lib/tty/table/border.rb +50 -57
- data/lib/tty/table/border/ascii.rb +16 -16
- data/lib/tty/table/border/null.rb +19 -22
- data/lib/tty/table/border/row_line.rb +3 -2
- data/lib/tty/table/border/unicode.rb +16 -16
- data/lib/tty/table/border_dsl.rb +24 -22
- data/lib/tty/table/border_options.rb +32 -27
- data/lib/tty/table/column_constraint.rb +12 -9
- data/lib/tty/table/columns.rb +6 -6
- data/lib/tty/table/field.rb +46 -28
- data/lib/tty/table/header.rb +5 -5
- data/lib/tty/table/indentation.rb +7 -4
- data/lib/tty/table/operation/alignment.rb +1 -1
- data/lib/tty/table/operation/escape.rb +1 -2
- data/lib/tty/table/operation/padding.rb +1 -1
- data/lib/tty/table/operation/truncation.rb +1 -1
- data/lib/tty/table/operation/wrapped.rb +1 -1
- data/lib/tty/table/options.rb +1 -1
- data/lib/tty/table/orientation.rb +4 -4
- data/lib/tty/table/renderer.rb +8 -8
- data/lib/tty/table/renderer/ascii.rb +2 -2
- data/lib/tty/table/renderer/basic.rb +37 -40
- data/lib/tty/table/renderer/unicode.rb +1 -1
- data/lib/tty/table/row.rb +7 -7
- data/lib/tty/table/validatable.rb +23 -7
- data/lib/tty/table/version.rb +1 -1
- metadata +23 -272
- data/Rakefile +0 -10
- data/examples/alignment.rb +0 -10
- data/examples/basic.rb +0 -6
- data/examples/orientation.rb +0 -13
- data/examples/padding.rb +0 -15
- data/examples/resize.rb +0 -15
- data/spec/spec_helper.rb +0 -50
- data/spec/unit/access_spec.rb +0 -84
- data/spec/unit/add_row_spec.rb +0 -26
- data/spec/unit/alignment_set/each_spec.rb +0 -15
- data/spec/unit/alignment_set/new_spec.rb +0 -25
- data/spec/unit/alignment_set/to_ary_spec.rb +0 -12
- data/spec/unit/alignment_spec.rb +0 -69
- data/spec/unit/border/ascii/rendering_spec.rb +0 -88
- data/spec/unit/border/new_spec.rb +0 -25
- data/spec/unit/border/null/rendering_spec.rb +0 -128
- data/spec/unit/border/options/from_spec.rb +0 -36
- data/spec/unit/border/options/new_spec.rb +0 -12
- data/spec/unit/border/unicode/rendering_spec.rb +0 -61
- data/spec/unit/border_options/new_spec.rb +0 -18
- data/spec/unit/border_options/update_spec.rb +0 -16
- data/spec/unit/column_constraint/enforce_spec.rb +0 -68
- data/spec/unit/column_constraint/widths_spec.rb +0 -33
- data/spec/unit/columns/extract_widths_spec.rb +0 -41
- data/spec/unit/columns/total_width_spec.rb +0 -11
- data/spec/unit/columns/widths_from_spec.rb +0 -49
- data/spec/unit/data_spec.rb +0 -10
- data/spec/unit/each_spec.rb +0 -24
- data/spec/unit/each_with_index_spec.rb +0 -49
- data/spec/unit/empty_spec.rb +0 -21
- data/spec/unit/eql_spec.rb +0 -32
- data/spec/unit/field/equality_spec.rb +0 -49
- data/spec/unit/field/length_spec.rb +0 -33
- data/spec/unit/field/lines_spec.rb +0 -19
- data/spec/unit/field/new_spec.rb +0 -27
- data/spec/unit/field/width_spec.rb +0 -21
- data/spec/unit/filter_spec.rb +0 -20
- data/spec/unit/header/call_spec.rb +0 -28
- data/spec/unit/header/color_spec.rb +0 -17
- data/spec/unit/header/equality_spec.rb +0 -49
- data/spec/unit/header/height_spec.rb +0 -25
- data/spec/unit/header/new_spec.rb +0 -13
- data/spec/unit/header/set_spec.rb +0 -18
- data/spec/unit/header/to_ary_spec.rb +0 -12
- data/spec/unit/header_spec.rb +0 -11
- data/spec/unit/indentation/indent_spec.rb +0 -15
- data/spec/unit/new_spec.rb +0 -71
- data/spec/unit/operation/alignment/call_spec.rb +0 -37
- data/spec/unit/operation/escape/call_spec.rb +0 -13
- data/spec/unit/operation/filter/call_spec.rb +0 -14
- data/spec/unit/operation/truncation/call_spec.rb +0 -28
- data/spec/unit/operation/wrapped/call_spec.rb +0 -38
- data/spec/unit/operations/new_spec.rb +0 -28
- data/spec/unit/options/access_spec.rb +0 -12
- data/spec/unit/options_spec.rb +0 -23
- data/spec/unit/orientation_spec.rb +0 -143
- data/spec/unit/padding_spec.rb +0 -115
- data/spec/unit/properties_spec.rb +0 -23
- data/spec/unit/render_repeat_spec.rb +0 -39
- data/spec/unit/render_spec.rb +0 -61
- data/spec/unit/render_with_spec.rb +0 -104
- data/spec/unit/renderer/ascii/coloring_spec.rb +0 -83
- data/spec/unit/renderer/ascii/indentation_spec.rb +0 -39
- data/spec/unit/renderer/ascii/multiline_spec.rb +0 -99
- data/spec/unit/renderer/ascii/padding_spec.rb +0 -115
- data/spec/unit/renderer/ascii/render_spec.rb +0 -66
- data/spec/unit/renderer/ascii/resizing_spec.rb +0 -112
- data/spec/unit/renderer/ascii/separator_spec.rb +0 -38
- data/spec/unit/renderer/basic/alignment_spec.rb +0 -86
- data/spec/unit/renderer/basic/coloring_spec.rb +0 -59
- data/spec/unit/renderer/basic/extract_column_widths_spec.rb +0 -26
- data/spec/unit/renderer/basic/filter_spec.rb +0 -51
- data/spec/unit/renderer/basic/indentation_spec.rb +0 -46
- data/spec/unit/renderer/basic/multiline_spec.rb +0 -72
- data/spec/unit/renderer/basic/new_spec.rb +0 -24
- data/spec/unit/renderer/basic/options_spec.rb +0 -50
- data/spec/unit/renderer/basic/padding_spec.rb +0 -74
- data/spec/unit/renderer/basic/render_spec.rb +0 -55
- data/spec/unit/renderer/basic/resizing_spec.rb +0 -94
- data/spec/unit/renderer/basic/separator_spec.rb +0 -41
- data/spec/unit/renderer/basic/single_row_separator_spec.rb +0 -80
- data/spec/unit/renderer/basic/truncation_spec.rb +0 -33
- data/spec/unit/renderer/basic/wrapping_spec.rb +0 -38
- data/spec/unit/renderer/border_spec.rb +0 -102
- data/spec/unit/renderer/render_spec.rb +0 -34
- data/spec/unit/renderer/select_spec.rb +0 -20
- data/spec/unit/renderer/unicode/coloring_spec.rb +0 -68
- data/spec/unit/renderer/unicode/indentation_spec.rb +0 -39
- data/spec/unit/renderer/unicode/padding_spec.rb +0 -59
- data/spec/unit/renderer/unicode/render_spec.rb +0 -66
- data/spec/unit/renderer/unicode/separator_spec.rb +0 -36
- data/spec/unit/renderer_spec.rb +0 -17
- data/spec/unit/rotate_spec.rb +0 -84
- data/spec/unit/row/access_spec.rb +0 -23
- data/spec/unit/row/call_spec.rb +0 -43
- data/spec/unit/row/data_spec.rb +0 -24
- data/spec/unit/row/each_spec.rb +0 -29
- data/spec/unit/row/equality_spec.rb +0 -71
- data/spec/unit/row/height_spec.rb +0 -25
- data/spec/unit/row/new_spec.rb +0 -39
- data/spec/unit/row/to_ary_spec.rb +0 -12
- data/spec/unit/to_s_spec.rb +0 -56
- data/spec/unit/transformation/extract_tuples_spec.rb +0 -33
- data/spec/unit/utf_spec.rb +0 -31
- data/spec/unit/validatable/validate_options_spec.rb +0 -31
- data/spec/unit/validatable_spec.rb +0 -30
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-table.gemspec +0 -41
@@ -9,8 +9,9 @@ module TTY
|
|
9
9
|
#
|
10
10
|
# @api public
|
11
11
|
def colorize(border, style)
|
12
|
-
|
13
|
-
self.
|
12
|
+
self.right = border.set_color(style, right)
|
13
|
+
self.center = border.set_color(style, center)
|
14
|
+
self.left = border.set_color(style, left)
|
14
15
|
end
|
15
16
|
end # RowLine
|
16
17
|
end # Border
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "../border"
|
4
4
|
|
5
5
|
module TTY
|
6
6
|
class Table
|
@@ -11,21 +11,21 @@ module TTY
|
|
11
11
|
class Unicode < Border
|
12
12
|
|
13
13
|
def_border do
|
14
|
-
top
|
15
|
-
top_mid
|
16
|
-
top_left
|
17
|
-
top_right
|
18
|
-
bottom
|
19
|
-
bottom_mid
|
20
|
-
bottom_left
|
21
|
-
bottom_right
|
22
|
-
mid
|
23
|
-
mid_mid
|
24
|
-
mid_left
|
25
|
-
mid_right
|
26
|
-
left
|
27
|
-
center
|
28
|
-
right
|
14
|
+
top "─"
|
15
|
+
top_mid "┬"
|
16
|
+
top_left "┌"
|
17
|
+
top_right "┐"
|
18
|
+
bottom "─"
|
19
|
+
bottom_mid "┴"
|
20
|
+
bottom_left "└"
|
21
|
+
bottom_right "┘"
|
22
|
+
mid "─"
|
23
|
+
mid_mid "┼"
|
24
|
+
mid_left "├"
|
25
|
+
mid_right "┤"
|
26
|
+
left "│"
|
27
|
+
center "│"
|
28
|
+
right "│"
|
29
29
|
end
|
30
30
|
|
31
31
|
end # Unicode
|
data/lib/tty/table/border_dsl.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "forwardable"
|
4
4
|
|
5
|
-
require_relative
|
5
|
+
require_relative "border_options"
|
6
6
|
|
7
7
|
module TTY
|
8
8
|
class Table
|
@@ -29,9 +29,8 @@ module TTY
|
|
29
29
|
# @return [undefined]
|
30
30
|
#
|
31
31
|
# @api private
|
32
|
-
def initialize(
|
33
|
-
@options = TTY::Table::BorderOptions.
|
34
|
-
@options.characters = characters if characters
|
32
|
+
def initialize(border_opts = nil, &block)
|
33
|
+
@options = TTY::Table::BorderOptions.from(border_opts)
|
35
34
|
yield_or_eval(&block) if block_given?
|
36
35
|
end
|
37
36
|
|
@@ -45,6 +44,7 @@ module TTY
|
|
45
44
|
# @api public
|
46
45
|
def style(value = (not_set = true))
|
47
46
|
return options.style if not_set
|
47
|
+
|
48
48
|
options.style = value
|
49
49
|
end
|
50
50
|
|
@@ -56,8 +56,10 @@ module TTY
|
|
56
56
|
# @return [undefined]
|
57
57
|
#
|
58
58
|
# @api public
|
59
|
-
def separator(value)
|
60
|
-
|
59
|
+
def separator(value = (not_set = true))
|
60
|
+
return options.separator if not_set
|
61
|
+
|
62
|
+
options.separator = value
|
61
63
|
end
|
62
64
|
|
63
65
|
# Set top border character
|
@@ -69,7 +71,7 @@ module TTY
|
|
69
71
|
#
|
70
72
|
# @api public
|
71
73
|
def top(value)
|
72
|
-
|
74
|
+
characters["top"] = value
|
73
75
|
end
|
74
76
|
|
75
77
|
# Set top middle border character
|
@@ -81,7 +83,7 @@ module TTY
|
|
81
83
|
#
|
82
84
|
# @api public
|
83
85
|
def top_mid(value)
|
84
|
-
|
86
|
+
characters["top_mid"] = value
|
85
87
|
end
|
86
88
|
|
87
89
|
# Set top left corner border character
|
@@ -93,7 +95,7 @@ module TTY
|
|
93
95
|
#
|
94
96
|
# @api public
|
95
97
|
def top_left(value)
|
96
|
-
|
98
|
+
characters["top_left"] = value
|
97
99
|
end
|
98
100
|
|
99
101
|
# Set top right corner border character
|
@@ -105,7 +107,7 @@ module TTY
|
|
105
107
|
#
|
106
108
|
# @api public
|
107
109
|
def top_right(value)
|
108
|
-
|
110
|
+
characters["top_right"] = value
|
109
111
|
end
|
110
112
|
|
111
113
|
# Set bottom border character
|
@@ -117,7 +119,7 @@ module TTY
|
|
117
119
|
#
|
118
120
|
# @api public
|
119
121
|
def bottom(value)
|
120
|
-
|
122
|
+
characters["bottom"] = value
|
121
123
|
end
|
122
124
|
|
123
125
|
# Set bottom middle border character
|
@@ -129,7 +131,7 @@ module TTY
|
|
129
131
|
#
|
130
132
|
# @api public
|
131
133
|
def bottom_mid(value)
|
132
|
-
|
134
|
+
characters["bottom_mid"] = value
|
133
135
|
end
|
134
136
|
|
135
137
|
# Set bottom left corner border character
|
@@ -141,7 +143,7 @@ module TTY
|
|
141
143
|
#
|
142
144
|
# @api public
|
143
145
|
def bottom_left(value)
|
144
|
-
|
146
|
+
characters["bottom_left"] = value
|
145
147
|
end
|
146
148
|
|
147
149
|
# Set bottom right corner border character
|
@@ -153,7 +155,7 @@ module TTY
|
|
153
155
|
#
|
154
156
|
# @api public
|
155
157
|
def bottom_right(value)
|
156
|
-
|
158
|
+
characters["bottom_right"] = value
|
157
159
|
end
|
158
160
|
|
159
161
|
# Set middle border character
|
@@ -165,7 +167,7 @@ module TTY
|
|
165
167
|
#
|
166
168
|
# @api public
|
167
169
|
def mid(value)
|
168
|
-
|
170
|
+
characters["mid"] = value
|
169
171
|
end
|
170
172
|
|
171
173
|
# Set middle border character
|
@@ -177,7 +179,7 @@ module TTY
|
|
177
179
|
#
|
178
180
|
# @api public
|
179
181
|
def mid_mid(value)
|
180
|
-
|
182
|
+
characters["mid_mid"] = value
|
181
183
|
end
|
182
184
|
|
183
185
|
# Set middle left corner border character
|
@@ -189,7 +191,7 @@ module TTY
|
|
189
191
|
#
|
190
192
|
# @api public
|
191
193
|
def mid_left(value)
|
192
|
-
|
194
|
+
characters["mid_left"] = value
|
193
195
|
end
|
194
196
|
|
195
197
|
# Set middle right corner border character
|
@@ -201,7 +203,7 @@ module TTY
|
|
201
203
|
#
|
202
204
|
# @api public
|
203
205
|
def mid_right(value)
|
204
|
-
|
206
|
+
characters["mid_right"] = value
|
205
207
|
end
|
206
208
|
|
207
209
|
# Set left border character
|
@@ -213,7 +215,7 @@ module TTY
|
|
213
215
|
#
|
214
216
|
# @api public
|
215
217
|
def left(value)
|
216
|
-
|
218
|
+
characters["left"] = value
|
217
219
|
end
|
218
220
|
|
219
221
|
# Set center border character
|
@@ -225,7 +227,7 @@ module TTY
|
|
225
227
|
#
|
226
228
|
# @api public
|
227
229
|
def center(value)
|
228
|
-
|
230
|
+
characters["center"] = value
|
229
231
|
end
|
230
232
|
|
231
233
|
# Set right border character
|
@@ -237,7 +239,7 @@ module TTY
|
|
237
239
|
#
|
238
240
|
# @api public
|
239
241
|
def right(value)
|
240
|
-
|
242
|
+
characters["right"] = value
|
241
243
|
end
|
242
244
|
|
243
245
|
private
|
@@ -7,49 +7,54 @@ module TTY
|
|
7
7
|
# Used internally by {Table::Border} to manage options such as style
|
8
8
|
#
|
9
9
|
# @api private
|
10
|
-
class BorderOptions
|
11
|
-
# Initialize a BorderOptions
|
12
|
-
#
|
13
|
-
# @api public
|
14
|
-
def initialize(*args)
|
15
|
-
super(*args)
|
16
|
-
self.characters = {} unless characters
|
17
|
-
end
|
18
|
-
|
10
|
+
class BorderOptions
|
19
11
|
# Create options instance from hash
|
20
12
|
#
|
21
13
|
# @api public
|
22
|
-
def self.from(
|
23
|
-
|
14
|
+
def self.from(options)
|
15
|
+
return new if options.nil?
|
16
|
+
|
17
|
+
opts = case options
|
18
|
+
when self.class
|
19
|
+
options.to_hash
|
20
|
+
else
|
21
|
+
options
|
22
|
+
end
|
23
|
+
new(**opts)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
attr_accessor :characters
|
27
|
+
|
28
|
+
attr_accessor :separator
|
29
|
+
|
30
|
+
attr_accessor :style
|
31
|
+
|
32
|
+
# Initialize a BorderOptions
|
29
33
|
#
|
30
|
-
# @
|
34
|
+
# @param [String] style
|
35
|
+
# the style like :red
|
36
|
+
# @param [String] separator
|
37
|
+
# the separator character
|
38
|
+
# @param [Hash] characters
|
39
|
+
# the border characters
|
31
40
|
#
|
32
41
|
# @api public
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
self
|
42
|
+
def initialize(characters: {}, separator: nil, style: nil)
|
43
|
+
@characters = characters
|
44
|
+
@separator = separator
|
45
|
+
@style = style
|
38
46
|
end
|
39
47
|
|
40
48
|
# Convert to hash
|
41
49
|
#
|
50
|
+
# @return [Hash]
|
51
|
+
#
|
42
52
|
# @api public
|
43
53
|
def to_hash
|
44
|
-
|
45
|
-
members.each do |key|
|
46
|
-
value = send(key)
|
47
|
-
hash[key.to_sym] = value if value
|
48
|
-
end
|
49
|
-
hash
|
54
|
+
{ characters: characters, separator: separator, style: style }
|
50
55
|
end
|
51
56
|
|
52
|
-
#
|
57
|
+
# Check if there should be a separator AFTER this line
|
53
58
|
#
|
54
59
|
# @param [Integer] line
|
55
60
|
#
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
3
|
+
require_relative "border/null"
|
4
|
+
require_relative "columns"
|
5
|
+
require_relative "error"
|
6
6
|
|
7
7
|
module TTY
|
8
8
|
class Table
|
@@ -111,9 +111,8 @@ module TTY
|
|
111
111
|
#
|
112
112
|
# @api private
|
113
113
|
def rotate
|
114
|
-
Kernel.warn
|
115
|
-
|
116
|
-
'orientation.'
|
114
|
+
Kernel.warn "The table size exceeds the currently set width." \
|
115
|
+
"Defaulting to vertical orientation."
|
117
116
|
table.orientation = :vertical
|
118
117
|
table.rotate
|
119
118
|
Columns.widths_from(table)
|
@@ -141,7 +140,11 @@ module TTY
|
|
141
140
|
ratio = ((natural_width - renderer.width) / column_size.to_f).ceil
|
142
141
|
|
143
142
|
widths = (0...column_size).reduce([]) do |lengths, col|
|
144
|
-
|
143
|
+
width = (renderer.column_widths[col] - ratio)
|
144
|
+
# basically ruby 2.4 Numeric#clamp
|
145
|
+
width = width < minimum_width ? minimum_width : width
|
146
|
+
width = width > renderer.width ? renderer.width : width
|
147
|
+
lengths << width
|
145
148
|
end
|
146
149
|
distribute_extra_width(widths)
|
147
150
|
end
|
@@ -154,8 +157,8 @@ module TTY
|
|
154
157
|
def assert_minimum_width
|
155
158
|
width = renderer.width
|
156
159
|
return unless width <= minimum_width
|
157
|
-
|
158
|
-
|
160
|
+
raise ResizeError, "Table's width is too small to contain the content " \
|
161
|
+
"(min width #{minimum_width}, currently set #{width})"
|
159
162
|
end
|
160
163
|
|
161
164
|
# Distribute remaining width to meet the total width requirement.
|
data/lib/tty/table/columns.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "error"
|
4
4
|
|
5
5
|
module TTY
|
6
6
|
class Table
|
@@ -69,7 +69,7 @@ module TTY
|
|
69
69
|
when NilClass
|
70
70
|
extract_widths(table.data)
|
71
71
|
else
|
72
|
-
|
72
|
+
raise TypeError, "Invalid type for column widths"
|
73
73
|
end
|
74
74
|
end
|
75
75
|
module_function :widths_from
|
@@ -85,12 +85,12 @@ module TTY
|
|
85
85
|
# @api public
|
86
86
|
def assert_widths(column_widths, table_widths)
|
87
87
|
if column_widths.empty?
|
88
|
-
|
89
|
-
|
88
|
+
raise InvalidArgument, "Value for :column_widths must be " \
|
89
|
+
"a non-empty array"
|
90
90
|
end
|
91
91
|
if column_widths.size != table_widths
|
92
|
-
|
93
|
-
|
92
|
+
raise InvalidArgument, "Value for :column_widths must match " \
|
93
|
+
"table column count"
|
94
94
|
end
|
95
95
|
end
|
96
96
|
module_function :assert_widths
|
data/lib/tty/table/field.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require 'pastel'
|
5
|
-
require 'strings'
|
3
|
+
require "strings"
|
6
4
|
|
7
5
|
module TTY
|
8
6
|
class Table
|
@@ -13,32 +11,15 @@ module TTY
|
|
13
11
|
#
|
14
12
|
# @api private
|
15
13
|
class Field
|
16
|
-
include Equatable
|
17
|
-
|
18
14
|
# The value inside the field
|
19
15
|
#
|
20
16
|
# @api public
|
21
|
-
|
17
|
+
attr_accessor :value
|
22
18
|
|
23
19
|
# The formatted value inside the field used for display
|
24
20
|
#
|
25
21
|
# @api public
|
26
|
-
|
27
|
-
|
28
|
-
# The name for the value
|
29
|
-
#
|
30
|
-
# @api public
|
31
|
-
attr_reader :name
|
32
|
-
|
33
|
-
# The actual value
|
34
|
-
#
|
35
|
-
# @api public
|
36
|
-
attr_writer :value
|
37
|
-
|
38
|
-
# The formatted string
|
39
|
-
#
|
40
|
-
# @api public
|
41
|
-
attr_writer :content
|
22
|
+
attr_accessor :content
|
42
23
|
|
43
24
|
# Number of columns this field spans. Defaults to 1.
|
44
25
|
#
|
@@ -58,15 +39,15 @@ module TTY
|
|
58
39
|
# Initialize a Field
|
59
40
|
#
|
60
41
|
# @example
|
61
|
-
# field = TTY::Table::Field.new
|
42
|
+
# field = TTY::Table::Field.new "a1"
|
62
43
|
# field.value # => a1
|
63
44
|
#
|
64
45
|
# @example
|
65
|
-
# field = TTY::Table::Field.new value:
|
46
|
+
# field = TTY::Table::Field.new value: "a1"
|
66
47
|
# field.value # => a1
|
67
48
|
#
|
68
49
|
# @example
|
69
|
-
# field = TTY::Table::Field.new value:
|
50
|
+
# field = TTY::Table::Field.new value: "a1", alignment: :center
|
70
51
|
# field.value # => a1
|
71
52
|
# field.alignment # => :center
|
72
53
|
#
|
@@ -75,9 +56,9 @@ module TTY
|
|
75
56
|
@value, options = extract_options(value)
|
76
57
|
@content = @value.to_s
|
77
58
|
@width = options[:width]
|
78
|
-
@alignment = options.fetch(:alignment
|
79
|
-
@colspan = options.fetch(:colspan
|
80
|
-
@rowspan = options.fetch(:rowspan
|
59
|
+
@alignment = options.fetch(:alignment, nil)
|
60
|
+
@colspan = options.fetch(:colspan, 1)
|
61
|
+
@rowspan = options.fetch(:rowspan, 1)
|
81
62
|
end
|
82
63
|
|
83
64
|
# Extract options and set value
|
@@ -152,6 +133,43 @@ module TTY
|
|
152
133
|
def to_s
|
153
134
|
content
|
154
135
|
end
|
136
|
+
|
137
|
+
# Compare fields for equality of value attribute
|
138
|
+
#
|
139
|
+
# @return [Boolean]
|
140
|
+
#
|
141
|
+
# @api public
|
142
|
+
def eql?(other)
|
143
|
+
instance_of?(other.class) && value.eql?(other.value)
|
144
|
+
end
|
145
|
+
|
146
|
+
# Compare fields for equivalence of value attribute
|
147
|
+
#
|
148
|
+
# @return [Boolean]
|
149
|
+
#
|
150
|
+
# @api public
|
151
|
+
def ==(other)
|
152
|
+
other.is_a?(self.class) && value == other.value
|
153
|
+
end
|
154
|
+
|
155
|
+
# Inspect this instance attributes
|
156
|
+
#
|
157
|
+
# @return [String]
|
158
|
+
#
|
159
|
+
# @api public
|
160
|
+
def inspect
|
161
|
+
"#<#{self.class.name} value=#{value.inspect} " \
|
162
|
+
"rowspan=#{rowspan.inspect} colspan=#{colspan.inspect}>"
|
163
|
+
end
|
164
|
+
|
165
|
+
# Hash for this instance and its attributes
|
166
|
+
#
|
167
|
+
# @return [Numeric]
|
168
|
+
#
|
169
|
+
# @api public
|
170
|
+
def hash
|
171
|
+
[self.class, value].hash
|
172
|
+
end
|
155
173
|
end # Field
|
156
174
|
end # Table
|
157
175
|
end # TTY
|