Class: Tabula::Detectors::DetectionAlgorithm

Inherits:
Object
  • Object
show all
Defined in:
lib/tabula/detectors/detection_algorithm.rb

Overview

Base class for table detection algorithms

Direct Known Subclasses

Nurminen, SpreadsheetDetection

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ DetectionAlgorithm

Returns a new instance of DetectionAlgorithm.

Parameters:

  • options (Hash) —

    algorithm options



16
17
18
# File 'lib/tabula/detectors/detection_algorithm.rb', line 16

def initialize(**options)
  @options = options
end

Class Method Details

.detect(page, **options) ⇒ Array<Rectangle>

Detect table areas on a page

Parameters:

  • page (Page) —

    page to detect tables on

  • options (Hash) —

    algorithm-specific options

Returns:

  • (Array<Rectangle>) —

    detected table areas



11
12
13
# File 'lib/tabula/detectors/detection_algorithm.rb', line 11

def self.detect(page, **options)
  new(**options).detect(page)
end

Instance Method Details

#detect(page) ⇒ Array<Rectangle>

Detect table areas on a page

Parameters:

  • page (Page) —

    page to detect tables on

Returns:

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/tabula/detectors/detection_algorithm.rb', line 23

def detect(page)
  raise NotImplementedError, 'Subclasses must implement #detect'
end

#name ⇒ String

Get algorithm name

Returns:

  • (String)


29
30
31
# File 'lib/tabula/detectors/detection_algorithm.rb', line 29

def name
  self.class.name.split('::').last
end