Class: BerkeleyLibrary::Util::ODS::XML::Table::TableRow

Inherits:
Repeatable show all
Defined in:
lib/berkeley_library/util/ods/xml/table/table_row.rb

Instance Attribute Summary collapse

Attributes inherited from Repeatable

#attr_name_num_repeated, #number_repeated, #table

Attributes inherited from ElementNode

#doc, #element_name, #namespace

Instance Method Summary collapse

Methods inherited from Repeatable

#increment_repeats!

Methods inherited from ElementNode

#attributes, #clear_attribute, #create_element, #element, #ensure_element!, #prefix, #prefixed_attr_name, #set_attribute

Constructor Details

#initialize(row_style, number_repeated = 1, table:, default_cell_style: nil) ⇒ TableRow

Returns a new instance of TableRow.

Parameters:

  • table (Table)

    the table

  • default_cell_style (Style::CellStyle) (defaults to: nil)

    the default cell style



24
25
26
27
28
29
30
# File 'lib/berkeley_library/util/ods/xml/table/table_row.rb', line 24

def initialize(row_style, number_repeated = 1, table:, default_cell_style: nil)
  super('table-row', 'number-rows-repeated', number_repeated, table: table)
  @row_style = row_style
  @default_cell_style = default_cell_style

  set_default_attributes!
end

Instance Attribute Details

#default_cell_styleObject (readonly)

Returns the value of attribute default_cell_style.



17
18
19
# File 'lib/berkeley_library/util/ods/xml/table/table_row.rb', line 17

def default_cell_style
  @default_cell_style
end

#row_styleObject (readonly)


Accessors



16
17
18
# File 'lib/berkeley_library/util/ods/xml/table/table_row.rb', line 16

def row_style
  @row_style
end

Instance Method Details

#add_child(child) ⇒ Object


Public XML::ElementNode overrides



46
47
48
49
50
# File 'lib/berkeley_library/util/ods/xml/table/table_row.rb', line 46

def add_child(child)
  return add_table_cell(child) if child.is_a?(TableCell)

  child.tap { |c| other_children << c }
end

#add_table_cell(cell) ⇒ Object (protected)


Protected utility methods

Raises:

  • (ArgumentError)


60
61
62
63
64
# File 'lib/berkeley_library/util/ods/xml/table/table_row.rb', line 60

def add_table_cell(cell)
  return cell.tap { |c| explicit_cells << c } if explicit_cell_count < table.column_count

  raise ArgumentError, "Can't add cell at column index #{explicit_cell_count} to table with only #{table.column_count} columns"
end

#childrenObject (protected)


Protected XML::ElementNode overrides



69
70
71
72
73
74
# File 'lib/berkeley_library/util/ods/xml/table/table_row.rb', line 69

def children
  [].tap do |cc|
    each_cell { |c| cc << c }
    cc.concat(other_children)
  end
end

#get_value_at(column_index) ⇒ Object



39
40
41
# File 'lib/berkeley_library/util/ods/xml/table/table_row.rb', line 39

def get_value_at(column_index)
  (cell = explicit_cells[column_index]) && cell.value
end

#set_value_at(column_index, value = nil, cell_style = nil) ⇒ Object


Public utility methods



35
36
37
# File 'lib/berkeley_library/util/ods/xml/table/table_row.rb', line 35

def set_value_at(column_index, value = nil, cell_style = nil)
  explicit_cells[column_index] = TableCell.new(value, cell_style || default_cell_style, table: table)
end