html-table 1.6.3 → 1.7.1

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.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/{CHANGES.rdoc → CHANGES.md} +76 -68
  4. data/Gemfile +2 -0
  5. data/MANIFEST.md +57 -0
  6. data/{README.rdoc → README.md} +80 -71
  7. data/Rakefile +122 -146
  8. data/doc/attributes.md +160 -0
  9. data/doc/table.md +173 -0
  10. data/doc/table_body.md +9 -0
  11. data/doc/table_caption.md +10 -0
  12. data/doc/table_colgroup.md +8 -0
  13. data/doc/table_colgroup_col.md +7 -0
  14. data/doc/table_content.md +17 -0
  15. data/doc/table_foot.md +8 -0
  16. data/doc/table_head.md +10 -0
  17. data/doc/table_row.md +114 -0
  18. data/doc/table_row_data.md +100 -0
  19. data/doc/table_row_header.md +6 -0
  20. data/examples/simple1.rb +7 -5
  21. data/html-table.gemspec +16 -11
  22. data/lib/html/body.rb +9 -7
  23. data/lib/html/caption.rb +4 -2
  24. data/lib/html/col.rb +37 -34
  25. data/lib/html/colgroup.rb +90 -97
  26. data/lib/html/content.rb +3 -6
  27. data/lib/html/data.rb +3 -1
  28. data/lib/html/foot.rb +53 -45
  29. data/lib/html/head.rb +54 -47
  30. data/lib/html/header.rb +5 -3
  31. data/lib/html/mixin/attribute_handler.rb +59 -55
  32. data/lib/html/mixin/html_handler.rb +33 -35
  33. data/lib/html/mixin/strongtyping.rb +6 -6
  34. data/lib/html/mixin/tag_handler.rb +6 -2
  35. data/lib/html/row.rb +156 -183
  36. data/lib/html/table.rb +45 -45
  37. data/lib/html/tablesection.rb +51 -46
  38. data/spec/attribute_handler_spec.rb +374 -0
  39. data/spec/body_spec.rb +98 -0
  40. data/spec/caption_spec.rb +83 -0
  41. data/spec/colgroup_col_spec.rb +34 -0
  42. data/spec/colgroup_spec.rb +97 -0
  43. data/spec/data_spec.rb +88 -0
  44. data/spec/foot_spec.rb +116 -0
  45. data/spec/head_spec.rb +116 -0
  46. data/spec/header_spec.rb +85 -0
  47. data/spec/html_handler_spec.rb +35 -0
  48. data/spec/row_spec.rb +163 -0
  49. data/spec/table_spec.rb +186 -0
  50. data/spec/tablesection_spec.rb +36 -0
  51. data/spec/tag_handler_spec.rb +85 -0
  52. data.tar.gz.sig +0 -0
  53. metadata +118 -92
  54. metadata.gz.sig +0 -0
  55. data/MANIFEST.rdoc +0 -56
  56. data/doc/attributes.rdoc +0 -143
  57. data/doc/table.rdoc +0 -156
  58. data/doc/table_body.rdoc +0 -9
  59. data/doc/table_caption.rdoc +0 -9
  60. data/doc/table_colgroup.rdoc +0 -8
  61. data/doc/table_colgroup_col.rdoc +0 -9
  62. data/doc/table_content.rdoc +0 -15
  63. data/doc/table_foot.rdoc +0 -8
  64. data/doc/table_head.rdoc +0 -11
  65. data/doc/table_row.rdoc +0 -105
  66. data/doc/table_row_data.rdoc +0 -92
  67. data/doc/table_row_header.rdoc +0 -7
  68. data/test/test_attribute_handler.rb +0 -361
  69. data/test/test_body.rb +0 -87
  70. data/test/test_caption.rb +0 -80
  71. data/test/test_col.rb +0 -40
  72. data/test/test_colgroup.rb +0 -89
  73. data/test/test_data.rb +0 -77
  74. data/test/test_foot.rb +0 -111
  75. data/test/test_head.rb +0 -104
  76. data/test/test_header.rb +0 -77
  77. data/test/test_html_handler.rb +0 -37
  78. data/test/test_row.rb +0 -141
  79. data/test/test_table.rb +0 -159
  80. data/test/test_tablesection.rb +0 -42
  81. data/test/test_tag_handler.rb +0 -90
data/doc/table_row.md ADDED
@@ -0,0 +1,114 @@
1
+ ## Description
2
+ A Table::Row object represents a single <TR></TR> instance for an HTML
3
+ Table. Although it is nested under Table, it is not a subclass of Table.
4
+ It is, however, a subclass of Array.
5
+
6
+ ## Synopsis
7
+ ```ruby
8
+ require "html/table"
9
+ include HTML
10
+
11
+ table = HTML::Table.new
12
+
13
+ row1 = Table::Row.new{ |r|
14
+ r.align = "left"
15
+ r.bgcolor = "green"
16
+ r.content = ["foo","bar","baz"]
17
+ }
18
+
19
+ row2 = Table::Row.new{ |r|
20
+ r.align = "right"
21
+ r.bgcolor = "blue"
22
+ r.content = "hello world"
23
+ }
24
+
25
+ table.push row1, row2
26
+
27
+ row1.content = "foofoo"
28
+ row1.configure(3){ |d| d.bgcolor = "pink" }
29
+
30
+ row1.push Table::Row::Header.new{ |h|
31
+ h.colspan = 2
32
+ h.content = "This is a table header"
33
+ }
34
+
35
+ row2.push Table::Row::Header.new{ |h|
36
+ h.colspan = 2
37
+ h.content = "This is also a table header"
38
+ }
39
+
40
+ puts table.html
41
+ #### output ####
42
+ ```
43
+ ```html
44
+ <table>
45
+ <tr align='left' bgcolor='green'>
46
+ <td>foo</td>
47
+ <td>bar</td>
48
+ <td>baz</td>
49
+ <td bgcolor='pink'>foofoo</td>
50
+ <th colspan=2>This is a table header</th>
51
+ </tr>
52
+ <tr align='right' bgcolor='blue'>
53
+ <td>hello world</td>
54
+ <th colspan=2>This is also a table header</th>
55
+ </tr>
56
+ </table>
57
+ ```
58
+
59
+ See the 'examples' directory for more examples.
60
+
61
+ ## Mixins
62
+ Table::Row is a subclass of Array and therefore mixes in Enumerable. It
63
+ also mixes in Attribute_Handler.
64
+
65
+ ## Class Methods
66
+ ```
67
+ Table::Row.new(arg=nil)
68
+ Table::Row.new(arg=nil){ |t| ... }
69
+ ```
70
+
71
+ Creates a new table. You can set attributes for the TableRow by passing a block.
72
+
73
+ If `arg` is supplied, it is automatically interpreted to be content.
74
+ This is a shortcut for Table::Row.new{ |r| r.content = '...' }.
75
+
76
+ ## Instance Methods
77
+ `Table::Row#[]=(index, obj)`
78
+
79
+ Assigns `obj` to index. The `obj` must be a Table::Row::Header or
80
+ Table::Row::Data object, or a TypeError is raised.
81
+
82
+ Table::Row#content
83
+ Returns the HTML content of the TableRow instance, i.e. the stuff between
84
+ the `<TR>` and `</TR>` tags.
85
+
86
+ `Table::Row#content=(args)`
87
+
88
+ Because a Table::Row doesn't store any of its own content, the arguments
89
+ to this method must be a Table::Row::Data object, a Table::Row::Header
90
+ object, or a String (or an array of any of these). In the latter case,
91
+ a single Table::Row::Data object is created for each string.
92
+
93
+ `Table::Row#html`
94
+
95
+ Returns the entire HTML content of the TableRow instance.
96
+
97
+ `Table::Row#push(obj)`
98
+
99
+ Pushes `obj` onto the Table::Row. The +obj+ must be a Table::Row::Data
100
+ or Table::Row::Header object, or a TypeError is raised.
101
+
102
+ `Table::Row#unshift(obj)`
103
+
104
+ Unshifts +obj+ onto the Table::Row. The same rules for push apply
105
+ to unshift as well.
106
+
107
+ ## Notes
108
+ String attributes are quoted. Numeric attributes are not.
109
+
110
+ Some attributes have type checking. Some check for valid arguments. In
111
+ the latter case, it is case-insensitive.
112
+
113
+ Using a non-standard extension (e.g. "background") will send a warning to
114
+ STDERR in $VERBOSE (-w) mode.
@@ -0,0 +1,100 @@
1
+ ## Description
2
+ A Table::Row::Data object represents a single <TD></TD> instance for an HTML
3
+ Table. For purposes of html-table, it also represents a "column".
4
+
5
+ ## Synopsis
6
+ ```ruby
7
+ require "html/table"
8
+ require HTML
9
+
10
+ Table::Row.end_tags = false
11
+ Table::Row::Data.end_tags = false
12
+
13
+ table = Table.new{ |t| t.border = 1 }
14
+ row = Table::Row.new
15
+
16
+ col1 = Table::Row::Data.new{ |d|
17
+ d.abbr = "test"
18
+ d.align = "right"
19
+ d.content = "hello world"
20
+ }
21
+
22
+ col2 = Table::Row::Data.new{ |d|
23
+ d.align = "center"
24
+ d.content = "Matz rules!"
25
+ }
26
+
27
+ col3 = Table::Row::Data.new{ |d|
28
+ d.align = "left"
29
+ d.content = "Foo!"
30
+ }
31
+
32
+ row.push col1, col2, col3
33
+
34
+ puts table.html
35
+ ```
36
+
37
+ output:
38
+
39
+ ```html
40
+ <table border=1>
41
+ <tr>
42
+ <td abbr='test' align='right'>hello world
43
+ <td align='center'>Matz rules!
44
+ <td align='left'>Foo!
45
+ </table>
46
+ ```
47
+
48
+ See the 'examples' directory under 'doc' for more examples.
49
+
50
+ ## Mixins
51
+ Table::Row::Data mixes in Attribute_Handler.
52
+
53
+ ## Class Methods
54
+ ```
55
+ Table::Row::Data.new(arg=nil)
56
+ Table::Row::Data.new(arg=nil){ |t| ... }
57
+ ```
58
+ Creates a new table. You can set attributes for the Table::Row::Data by passing a block.
59
+
60
+ If `arg` is supplied, it is automatically interpreted to be content.
61
+ This is a shortcut for Table::Row::Data.new{ |d| d.content = '...' }.
62
+
63
+ `Table::Row::Data.end_tags`
64
+
65
+ Returns true or false to indicate whether end tags are included or not.
66
+
67
+ `Table::Row::Data.end_tags=(bool)`
68
+
69
+ Sets whether or not end tags are included in the html.
70
+
71
+ `Table::Row::Data.indent_level`
72
+ Returns the current number of spaces that `<TD>` tags are indented. The default is 6.
73
+
74
+ `Table::Row::Data.indent_level=(num)`
75
+
76
+ Sets the number of spaces that `<TD>` tags are indented.
77
+
78
+ ## Instance Methods
79
+ TableData#content
80
+
81
+ Returns the content of the TableData object, i.e. the stuff between `<TD>` and `</TD>`.
82
+
83
+ Table::Row::Data#content=(string)
84
+
85
+ Sets the content for the TableData object, i.e. the stuff between `<TD>` and `</TD>`.
86
+
87
+ Table::Row::Data#html
88
+
89
+ Returns all html content for the TableData instance.
90
+
91
+ ## Notes
92
+ The end tags for Table::Row::Data objects are are the same line as the begin tags.
93
+
94
+ String attributes are quoted. Numeric attributes are not.
95
+
96
+ Some attributes have type checking. Some check for valid arguments. In
97
+ the latter case, it is case-insensitive.
98
+
99
+ Using a non-standard extension (e.g. "background") will send a warning to
100
+ STDERR in $VERBOSE (-w) mode.
@@ -0,0 +1,6 @@
1
+ ## Description
2
+ A Table::Row::Header object represents a single `<TH></TH>` instance for an HTML Table.
3
+
4
+ ## Notes
5
+ The Table::Row::Header class is identical in every way to the
6
+ Table::Row::Data class, except for the begin and end tags.
data/examples/simple1.rb CHANGED
@@ -9,13 +9,15 @@ require 'html/table'
9
9
  include HTML
10
10
 
11
11
  table = Table.new{ |t|
12
- t.content = [
13
- %w/foo bar baz/,
14
- %w/1 2 3/,
15
- %w/hello world/
16
- ]
12
+ t.content = [
13
+ %w[foo bar baz],
14
+ %w[1 2 3],
15
+ %w[hello world]
16
+ ]
17
17
  }
18
18
 
19
+ #Table.global_end_tags = false
20
+
19
21
  puts table.html
20
22
 
21
23
  =begin
data/html-table.gemspec CHANGED
@@ -2,30 +2,35 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'html-table'
5
- spec.version = '1.6.3'
5
+ spec.version = '1.7.1'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.license = 'Apache-2.0'
8
8
  spec.email = 'djberg96@gmail.com'
9
9
  spec.homepage = 'http://github.com/djberg96/html-table'
10
10
  spec.summary = 'A Ruby interface for generating HTML tables'
11
- spec.test_files = Dir['test/*.rb']
11
+ spec.test_files = Dir['spec/*.rb']
12
12
  spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
13
  spec.cert_chain = ['certs/djberg96_pub.pem']
14
14
 
15
- spec.extra_rdoc_files = ['README.rdoc', 'CHANGES.rdoc'] + Dir['doc/*.rdoc']
15
+ spec.extra_rdoc_files = ['README.md', 'CHANGES.md', 'MANIFEST.md'] + Dir['doc/*.md']
16
16
 
17
- spec.add_dependency('structured_warnings', '~> 0.3.0')
17
+ spec.add_dependency('structured_warnings', '~> 0.4.0')
18
18
 
19
- spec.add_development_dependency('test-unit')
19
+ spec.add_development_dependency('rspec', '~> 3.9')
20
20
  spec.add_development_dependency('rake')
21
+ spec.add_development_dependency('rubocop')
22
+ spec.add_development_dependency('rubocop-rspec')
21
23
 
22
24
  spec.metadata = {
23
- 'homepage_uri' => 'https://github.com/djberg96/html-table',
24
- 'bug_tracker_uri' => 'https://github.com/djberg96/html-table/issues',
25
- 'changelog_uri' => 'https://github.com/djberg96/html-table/blob/master/CHANGES',
26
- 'documentation_uri' => 'https://github.com/djberg96/html-table/wiki',
27
- 'source_code_uri' => 'https://github.com/djberg96/html-table',
28
- 'wiki_uri' => 'https://github.com/djberg96/html-table/wiki'
25
+ 'homepage_uri' => 'https://github.com/djberg96/html-table',
26
+ 'bug_tracker_uri' => 'https://github.com/djberg96/html-table/issues',
27
+ 'changelog_uri' => 'https://github.com/djberg96/html-table/blob/main/CHANGES.md',
28
+ 'documentation_uri' => 'https://djberg96.github.io/html-table',
29
+ 'source_code_uri' => 'https://github.com/djberg96/html-table',
30
+ 'wiki_uri' => 'https://github.com/djberg96/html-table/wiki',
31
+ 'rubygems_mfa_required' => 'true',
32
+ 'github_repo' => 'https://github.com/djberg96/html-table',
33
+ 'funding_uri' => 'https://github.com/sponsors/djberg96'
29
34
  }
30
35
 
31
36
  spec.description = <<-EOF
data/lib/html/body.rb CHANGED
@@ -1,9 +1,11 @@
1
+ # The HTML module serves as a namespace only.
1
2
  module HTML
2
-
3
3
  # This class represents an HTML table body (<tbody>). It is a
4
4
  # subclass of Table::TableSection.
5
5
  #
6
6
  class Table::Body < Table::TableSection
7
+ extend HTML::Mixin::StrongTyping
8
+
7
9
  @indent_level = 3
8
10
  @end_tags = true
9
11
 
@@ -11,12 +13,12 @@ module HTML
11
13
  # an argument is provided, it is treated as content.
12
14
  #
13
15
  def initialize(arg = nil, &block)
14
- @html_begin = "<tbody"
15
- @html_end = "</tbody>"
16
- instance_eval(&block) if block_given?
16
+ @html_begin = '<tbody'
17
+ @html_end = '</tbody>'
18
+ super(&block)
17
19
  self.content = arg if arg
18
20
  end
19
-
21
+
20
22
  # Returns a boolean indicating whether or not end tags, </tbody>, are
21
23
  # included for each Body object in the final HTML output. The
22
24
  # default is true.
@@ -24,13 +26,13 @@ module HTML
24
26
  def self.end_tags?
25
27
  @end_tags
26
28
  end
27
-
29
+
28
30
  # Sets whether or not end tags are included for each Body object in
29
31
  # the final HTML output. The default is true. Only true or false are
30
32
  # valid arguments.
31
33
  #
32
34
  def self.end_tags=(bool)
33
- expect(bool,[TrueClass, FalseClass])
35
+ expect(bool, [TrueClass, FalseClass])
34
36
  @end_tags = bool
35
37
  end
36
38
  end
data/lib/html/caption.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # The HTML module serves as a namespace only.
1
2
  module HTML
2
3
 
3
4
  # This class represents an HTML Caption. Despite the name, it is not
@@ -6,6 +7,7 @@ module HTML
6
7
  class Table::Caption
7
8
  include HTML::Mixin::AttributeHandler
8
9
  include HTML::Mixin::HtmlHandler
10
+ extend HTML::Mixin::StrongTyping
9
11
 
10
12
  undef_method :configure
11
13
  @indent_level = 3
@@ -38,8 +40,8 @@ module HTML
38
40
  # Sets the number of spaces that tags for this class are indented.
39
41
  #
40
42
  def self.indent_level=(num)
41
- expect(num,Integer)
42
- raise ArgumentError, "indent level must be >= 0" if num < 0
43
+ expect(num, Integer)
44
+ raise ArgumentError, 'indent level must be >= 0' if num < 0
43
45
  @indent_level = num
44
46
  end
45
47
 
data/lib/html/col.rb CHANGED
@@ -1,41 +1,44 @@
1
+ # The HTML module serves as a namespace only.
1
2
  module HTML
2
- # This class represents an HTML ColGroup column (<col>). Despite the
3
- # name, it is not a subclass of ColGroup or Table.
4
- #
5
- class Table::ColGroup::Col
6
- include HTML::Mixin::AttributeHandler
7
- include HTML::Mixin::HtmlHandler
8
3
 
9
- undef_method :configure, :content
10
- @indent_level = 6
4
+ # This class represents an HTML ColGroup column (<col>). Despite the
5
+ # name, it is not a subclass of ColGroup or Table.
6
+ #
7
+ class Table::ColGroup::Col
8
+ include HTML::Mixin::AttributeHandler
9
+ include HTML::Mixin::HtmlHandler
10
+ extend HTML::Mixin::StrongTyping
11
11
 
12
- # Creates and returns a new ColGroup object. Optionally takes a block.
13
- # Note that it does not accept an argument - col tags do not have content.
14
- #
15
- def initialize(&block)
16
- @html_begin = '<col'
17
- @html_body = ''
18
- @html_end = ''
19
- instance_eval(&block) if block_given?
20
- end
12
+ undef_method :configure, :content
13
+ @indent_level = 6
21
14
 
22
- # Returns the indentation level for the tags of this class. The
23
- # default is 6.
24
- #
25
- def self.indent_level
26
- @indent_level
27
- end
15
+ # Creates and returns a new ColGroup object. Optionally takes a block.
16
+ # Note that it does not accept an argument - col tags do not have content.
17
+ #
18
+ def initialize(&block)
19
+ @html_begin = '<col'
20
+ @html_body = ''
21
+ @html_end = ''
22
+ instance_eval(&block) if block_given?
23
+ end
28
24
 
29
- # Sets the indentation level for the tags of this class. The default
30
- # is 6.
31
- #
32
- def self.indent_level=(num)
33
- expect(num,Integer)
34
- raise ArgumentError, "num must be >= 0" if num < 0
35
- @indent_level = num
36
- end
25
+ # Returns the indentation level for the tags of this class. The
26
+ # default is 6.
27
+ #
28
+ def self.indent_level
29
+ @indent_level
30
+ end
37
31
 
38
- alias to_s html
39
- alias to_str html
40
- end
32
+ # Sets the indentation level for the tags of this class. The default
33
+ # is 6.
34
+ #
35
+ def self.indent_level=(num)
36
+ expect(num, Integer)
37
+ raise ArgumentError, 'num must be >= 0' if num < 0
38
+ @indent_level = num
39
+ end
40
+
41
+ alias to_s html
42
+ alias to_str html
43
+ end
41
44
  end
data/lib/html/colgroup.rb CHANGED
@@ -1,113 +1,106 @@
1
+ # The HTML module serves as a namespace only.
1
2
  module HTML
2
- # This class represents an HTML column group (<colgroup>). It is a
3
- # subclass of Array. The only elements it may contain are instances
4
- # of the ColGroup::Col class.
5
- #
6
- class Table::ColGroup < Array
7
- include HTML::Mixin::AttributeHandler
8
- include HTML::Mixin::HtmlHandler
9
3
 
10
- @indent_level = 3
11
- @end_tags = true
4
+ # This class represents an HTML column group (<colgroup>). It is a
5
+ # subclass of Array. The only elements it may contain are instances
6
+ # of the ColGroup::Col class.
7
+ #
8
+ class Table::ColGroup < Array
9
+ include HTML::Mixin::AttributeHandler
10
+ include HTML::Mixin::HtmlHandler
11
+ include HTML::Mixin::StrongTyping
12
+ extend HTML::Mixin::StrongTyping
12
13
 
13
- undef_method :content
14
+ @indent_level = 3
15
+ @end_tags = true
14
16
 
15
- # Returns a new ColGroup object. Optionally takes a block. If an
16
- # argument is provided, it is treated as content.
17
- #
18
- def initialize(arg = nil, &block)
19
- @html_begin = '<colgroup'
20
- @html_body = ''
21
- @html_end = '</colgroup>'
22
- instance_eval(&block) if block_given?
23
- self.push(arg) if arg
24
- end
17
+ undef_method :content
25
18
 
26
- # Returns the indentation level for the tags of this class. The
27
- # default is 3.
28
- #
29
- def self.indent_level
30
- @indent_level
31
- end
19
+ # Returns a new ColGroup object. Optionally takes a block. If an
20
+ # argument is provided, it is treated as content.
21
+ #
22
+ def initialize(arg = nil, &block)
23
+ @html_begin = '<colgroup'
24
+ @html_body = ''
25
+ @html_end = '</colgroup>'
26
+ super(&block)
27
+ push(arg) if arg
28
+ end
32
29
 
33
- # Sets the indentation level for the tags of this class. The default
34
- # is 3.
35
- #
36
- def self.indent_level=(num)
37
- expect(num,Integer)
38
- raise ArgumentError,"indent_level must be >= 0" if num < 0
39
- @indent_level = num
40
- end
30
+ # Returns the indentation level for the tags of this class. The
31
+ # default is 3.
32
+ #
33
+ def self.indent_level
34
+ @indent_level
35
+ end
41
36
 
42
- # This method has been redefined to only allow ColGroup::Col objects
43
- # to be assigned.
44
- #
45
- def []=(index,obj)
46
- if obj.kind_of?(Array)
47
- expect(obj.first,Col) # In case of 0 length Array
48
- obj.each{ |o|
49
- expect(o,Col)
50
- }
51
- else
52
- expect(obj,Col)
53
- end
54
- super
55
- end
37
+ # Sets the indentation level for the tags of this class. The default
38
+ # is 3.
39
+ #
40
+ def self.indent_level=(num)
41
+ expect(num, Integer)
42
+ raise ArgumentError, 'indent_level must be >= 0' if num < 0
43
+ @indent_level = num
44
+ end
56
45
 
57
- # This method has been redefined to only allow ColGroup::Col objects
58
- # to be pushed onto a ColGroup instance.
59
- #
60
- def push(*args)
61
- args.each do |obj|
62
- unless obj.kind_of?(Table::ColGroup::Col)
63
- msg = "Can only assign Col objects to ColGroup class"
64
- msg += ": " + obj.class.to_s
65
- raise TypeError, msg
66
- end
67
- super(obj)
68
- end
46
+ # This method has been redefined to only allow ColGroup::Col objects
47
+ # to be assigned.
48
+ #
49
+ def []=(index, obj)
50
+ if obj.is_a?(Array)
51
+ expect(obj.first, Col) # In case of 0 length Array
52
+ obj.each do |o|
53
+ expect(o, Col)
54
+ end
55
+ else
56
+ expect(obj, Col)
69
57
  end
58
+ super
59
+ end
70
60
 
71
- # This method has been redefined to only allow ColGroup::Col objects
72
- # to be pushed onto a ColGroup instance.
73
- #
74
- def <<(obj)
75
- unless obj.kind_of?(Table::ColGroup::Col)
76
- msg = "Can only assign Col objects to ColGroup class"
77
- msg += ": " + obj.class.to_s
78
- raise TypeError, msg
79
- end
80
- super(obj)
61
+ # This method has been redefined to only allow ColGroup::Col objects
62
+ # to be pushed onto a ColGroup instance.
63
+ #
64
+ def push(*args)
65
+ args.each do |obj|
66
+ expect(obj, Table::ColGroup::Col)
67
+ super(obj)
81
68
  end
69
+ end
82
70
 
83
- # This method has been redefined to only allow ColGroup::Col objects
84
- # to be unshifted onto a ColGroup instance.
85
- #
86
- def unshift(obj)
87
- unless obj.kind_of?(Table::ColGroup::Col)
88
- msg = "Can only assign Data and Header objects to Row class"
89
- raise TypeError, msg
90
- end
91
- super
92
- end
71
+ # This method has been redefined to only allow ColGroup::Col objects
72
+ # to be pushed onto a ColGroup instance.
73
+ #
74
+ def <<(obj)
75
+ expect(obj, Table::ColGroup::Col)
76
+ super
77
+ end
93
78
 
94
- # Returns a boolean indicating whether or not end tags are included for
95
- # each ColGroup object in the final HTML output. The default is true.
96
- #
97
- def self.end_tags?
98
- @end_tags
99
- end
79
+ # This method has been redefined to only allow ColGroup::Col objects
80
+ # to be unshifted onto a ColGroup instance.
81
+ #
82
+ def unshift(obj)
83
+ expect(obj, Table::ColGroup::Col)
84
+ super
85
+ end
100
86
 
101
- # Sets whether or not end tags are included for each ColGroup object in
102
- # the final HTML output. The default is true. Only true or false are
103
- # valid arguments.
104
- #
105
- def self.end_tags=(bool)
106
- expect(bool,[TrueClass,FalseClass])
107
- @end_tags = bool
108
- end
87
+ # Returns a boolean indicating whether or not end tags are included for
88
+ # each ColGroup object in the final HTML output. The default is true.
89
+ #
90
+ def self.end_tags?
91
+ @end_tags
92
+ end
93
+
94
+ # Sets whether or not end tags are included for each ColGroup object in
95
+ # the final HTML output. The default is true. Only true or false are
96
+ # valid arguments.
97
+ #
98
+ def self.end_tags=(bool)
99
+ expect(bool, [TrueClass, FalseClass])
100
+ @end_tags = bool
101
+ end
109
102
 
110
- alias to_s html
111
- alias to_str html
112
- end
103
+ alias to_s html
104
+ alias to_str html
105
+ end
113
106
  end
data/lib/html/content.rb CHANGED
@@ -1,12 +1,9 @@
1
- ########################################################################
2
- # content.rb
3
- #
4
- # This class handles content for Table::Row::Data, Table::Row::Header,
5
- # and Table::Row::Caption objects.
6
- ########################################################################
7
1
  require_relative 'mixin/tag_handler'
8
2
 
3
+ # The HTML module is a namespace only.
9
4
  module HTML
5
+ # The Table::Content class handles content for Table::Row::Data,
6
+ # Table::Row::Header, and Table::Row::Caption objects.
10
7
  class Table::Content < String
11
8
  include HTML::Mixin::TagHandler
12
9