Class: Tabula::Detectors::SpreadsheetDetection

Inherits:
DetectionAlgorithm show all
Defined in:
lib/tabula/detectors/spreadsheet_detection_algorithm.rb

Overview

Detects table areas using ruling line analysis. Suitable for PDFs with clear table borders.

Constant Summary collapse

MIN_CELLS =

Minimum cells for a valid table

4
MIN_DIMENSION =

Minimum table dimension (in points)

10

Instance Method Summary collapse

Methods inherited from DetectionAlgorithm

detect, #initialize, #name

Constructor Details

This class inherits a constructor from Tabula::Detectors::DetectionAlgorithm

Instance Method Details

#detect(page) ⇒ Array<Rectangle>

Detect table areas on a page

Parameters:

  • page (Page) —

    page to detect tables on

Returns:

  • (Array<Rectangle>) —

    detected table areas



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tabula/detectors/spreadsheet_detection_algorithm.rb', line 17

def detect(page)
  horizontal = page.horizontal_rulings
  vertical = page.vertical_rulings

  return [] if horizontal.empty? || vertical.empty?

  # Find cells from ruling intersections
  cells = find_cells(horizontal, vertical)
  return [] if cells.size < MIN_CELLS

  # Group cells into table regions
  regions = find_table_regions(cells)

  # Filter valid regions
  regions.select { |r| valid_table_region?(r) }
end