Class: OpenStax::Utilities::Blocks::TableRowBlock

Inherits:
BlockBase
  • Object
show all
Defined in:
lib/openstax/utilities/blocks/table_row_block.rb

Instance Attribute Summary collapse

Attributes inherited from BlockBase

#captured_block

Instance Method Summary collapse

Methods inherited from BlockBase

#to_s

Constructor Details

#initialize(template, block) ⇒ TableRowBlock

Returns a new instance of TableRowBlock.



10
11
12
13
14
# File 'lib/openstax/utilities/blocks/table_row_block.rb', line 10

def initialize(template, block)
  super(template, "table_row", block)
  self.cell_blocks     = []
  self.section_heading = false
end

Instance Attribute Details

#cell_blocksObject

Returns the value of attribute cell_blocks.



7
8
9
# File 'lib/openstax/utilities/blocks/table_row_block.rb', line 7

def cell_blocks
  @cell_blocks
end

#section_headingObject

Returns the value of attribute section_heading.



8
9
10
# File 'lib/openstax/utilities/blocks/table_row_block.rb', line 8

def section_heading
  @section_heading
end

Instance Method Details

#add_cell(value) ⇒ Object



21
22
23
# File 'lib/openstax/utilities/blocks/table_row_block.rb', line 21

def add_cell(value)
  self.cell_blocks << TableCellBlock.from_value(h, value)
end

#add_cell_block(&block) ⇒ Object



16
17
18
19
# File 'lib/openstax/utilities/blocks/table_row_block.rb', line 16

def add_cell_block(&block)
  self.cell_blocks << h.table_cell_block(&block)
  self
end

#section_heading?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/openstax/utilities/blocks/table_row_block.rb', line 25

def section_heading?
  section_heading
end

#set_section_heading(heading, colspan) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/openstax/utilities/blocks/table_row_block.rb', line 29

def set_section_heading(heading, colspan)
  raise "TableRowBlock cannot be a table section heading if it contains cells" \
    if cell_blocks.any?
  raise "TableRowBlock section heading cannot be changed once initialized" \
    if section_heading?

  tcb = TableCellBlock.from_value(h, heading)
  tcb.set_section_heading(colspan)
  self.cell_blocks << tcb

  self.section_heading = true
  self
end