Class: HexaPDF::Document::Layout::CellArgumentCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/hexapdf/document/layout.rb

Overview

This helper class is used by Layout#table_box to allow specifying the keyword arguments used when converting cell data to box instances.

Defined Under Namespace

Classes: ArgumentInfo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number_of_rows, number_of_columns) ⇒ CellArgumentCollector

Creates a new instance, providing the number of rows and columns of the table.



464
465
466
467
468
# File 'lib/hexapdf/document/layout.rb', line 464

def initialize(number_of_rows, number_of_columns)
  @argument_infos = []
  @number_of_rows = number_of_rows
  @number_of_columns = number_of_columns
end

Instance Attribute Details

#argument_infosObject (readonly)

Returns all stored ArgumentInfo instances.



461
462
463
# File 'lib/hexapdf/document/layout.rb', line 461

def argument_infos
  @argument_infos
end

Instance Method Details

#[]=(rows = 0..-1,, cols = 0..-1,, args) ⇒ Object

Stores the keyword arguments in args for the given 0-based rows and columns which can either be a single number or a range of numbers.



472
473
474
475
476
# File 'lib/hexapdf/document/layout.rb', line 472

def []=(rows = 0..-1, cols = 0..-1, args)
  rows = adjust_range(rows.kind_of?(Integer) ? rows..rows : rows, @number_of_rows)
  cols = adjust_range(cols.kind_of?(Integer) ? cols..cols : cols, @number_of_columns)
  @argument_infos << ArgumentInfo.new(rows, cols, args)
end

#retrieve_arguments_for(row, col) ⇒ Object

Retrieves the merged keyword arguments for the cell in row and col.

Earlier defined arguments are overridden by later ones.



481
482
483
484
485
486
# File 'lib/hexapdf/document/layout.rb', line 481

def retrieve_arguments_for(row, col)
  @argument_infos.each_with_object({}) do |arg_info, result|
    next unless arg_info.rows.cover?(row) && arg_info.cols.cover?(col)
    result.update(arg_info.args)
  end
end