Skip to content

Commit e077b2b

Browse files
committed
Standardize Markup::Table
1 parent 82450bd commit e077b2b

File tree

1 file changed

+48
-40
lines changed

1 file changed

+48
-40
lines changed

lib/rdoc/markup/table.rb

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,60 @@
11
# frozen_string_literal: true
2-
##
3-
# A section of table
42

5-
class RDoc::Markup::Table
6-
# headers of each column
7-
attr_accessor :header
3+
module RDoc
4+
class Markup
5+
# A section of table
6+
class Table < Element
7+
# Headers of each column
8+
#: Array[String]
9+
attr_accessor :header
810

9-
# alignments of each column
10-
attr_accessor :align
11+
# Alignments of each column
12+
#: Array[Symbol?]
13+
attr_accessor :align
1114

12-
# body texts of each column
13-
attr_accessor :body
15+
# Body texts of each column
16+
#: Array[String]
17+
attr_accessor :body
1418

15-
# Creates new instance
16-
def initialize(header, align, body)
17-
@header, @align, @body = header, align, body
18-
end
19-
20-
# :stopdoc:
21-
def ==(other)
22-
self.class == other.class and
23-
@header == other.header and
24-
@align == other.align and
25-
@body == other.body
26-
end
19+
#: (Array[String], Array[Symbol?], Array[String]) -> void
20+
def initialize(header, align, body)
21+
@header, @align, @body = header, align, body
22+
end
2723

28-
def accept(visitor)
29-
visitor.accept_table @header, @body, @align
30-
end
24+
#: (Object) -> bool
25+
def ==(other)
26+
self.class == other.class && @header == other.header &&
27+
@align == other.align && @body == other.body
28+
end
3129

32-
def pretty_print(q)
33-
q.group 2, '[Table: ', ']' do
34-
q.group 2, '[Head: ', ']' do
35-
q.seplist @header.zip(@align) do |text, align|
36-
q.pp text
37-
if align
38-
q.text ":"
39-
q.breakable
40-
q.text align.to_s
41-
end
42-
end
30+
# @override
31+
#: (untyped) -> void
32+
def accept(visitor)
33+
visitor.accept_table(@header, @body, @align)
4334
end
44-
q.breakable
45-
q.group 2, '[Body: ', ']' do
46-
q.seplist @body do |body|
47-
q.group 2, '[', ']' do
48-
q.seplist body do |text|
35+
36+
# @override
37+
#: (untyped) -> String
38+
def pretty_print(q)
39+
q.group 2, '[Table: ', ']' do
40+
q.group 2, '[Head: ', ']' do
41+
q.seplist @header.zip(@align) do |text, align|
4942
q.pp text
43+
if align
44+
q.text ":"
45+
q.breakable
46+
q.text align.to_s
47+
end
48+
end
49+
end
50+
q.breakable
51+
q.group 2, '[Body: ', ']' do
52+
q.seplist @body do |body|
53+
q.group 2, '[', ']' do
54+
q.seplist body do |text|
55+
q.pp text
56+
end
57+
end
5058
end
5159
end
5260
end

0 commit comments

Comments
 (0)