Class: OpenStax::Utilities::Blocks::TableBlock
- Defined in:
- lib/openstax/utilities/blocks/table_block.rb
Instance Attribute Summary collapse
-
#column_names ⇒ Object
readonly
Returns the value of attribute column_names.
-
#row_blocks ⇒ Object
readonly
Returns the value of attribute row_blocks.
-
#title ⇒ Object
Returns the value of attribute title.
Attributes inherited from BlockBase
Instance Method Summary collapse
- #add_column(column_name) ⇒ Object
- #add_row(*args) ⇒ Object
- #add_row_block(&block) ⇒ Object
- #add_section_heading(heading) ⇒ Object
-
#initialize(template, block) ⇒ TableBlock
constructor
A new instance of TableBlock.
- #set_title(table_title) ⇒ Object
- #show_caption? ⇒ Boolean
Methods inherited from BlockBase
Constructor Details
#initialize(template, block) ⇒ TableBlock
Returns a new instance of TableBlock.
16 17 18 19 20 21 22 23 |
# File 'lib/openstax/utilities/blocks/table_block.rb', line 16 def initialize(template, block) super(template, "table", block) self.column_names = [] self.row_blocks = [] self.table_class_add "table-block-table" end |
Instance Attribute Details
#column_names ⇒ Object
Returns the value of attribute column_names.
12 13 14 |
# File 'lib/openstax/utilities/blocks/table_block.rb', line 12 def column_names @column_names end |
#row_blocks ⇒ Object
Returns the value of attribute row_blocks.
13 14 15 |
# File 'lib/openstax/utilities/blocks/table_block.rb', line 13 def row_blocks @row_blocks end |
#title ⇒ Object
Returns the value of attribute title.
14 15 16 |
# File 'lib/openstax/utilities/blocks/table_block.rb', line 14 def title @title end |
Instance Method Details
#add_column(column_name) ⇒ Object
36 37 38 39 |
# File 'lib/openstax/utilities/blocks/table_block.rb', line 36 def add_column(column_name) self.column_names << column_name self end |
#add_row(*args) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/openstax/utilities/blocks/table_block.rb', line 46 def add_row(*args) trb = h.table_row_block do |rb| args.each do |arg| rb.add_cell(arg) end end self.row_blocks << trb self end |
#add_row_block(&block) ⇒ Object
41 42 43 44 |
# File 'lib/openstax/utilities/blocks/table_block.rb', line 41 def add_row_block(&block) self.row_blocks << h.table_row_block(&block) self end |
#add_section_heading(heading) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/openstax/utilities/blocks/table_block.rb', line 56 def add_section_heading(heading) trb = h.table_row_block do |rb| rb.set_section_heading(heading, column_names.count) end self.row_blocks << trb self end |
#set_title(table_title) ⇒ Object
25 26 27 28 |
# File 'lib/openstax/utilities/blocks/table_block.rb', line 25 def set_title(table_title) self.title = table_title self end |
#show_caption? ⇒ Boolean
64 65 66 |
# File 'lib/openstax/utilities/blocks/table_block.rb', line 64 def show_caption? title.present? end |