Class: Tabula::Extractors::ExtractionAlgorithm

Inherits:
Object
  • Object
show all
Defined in:
lib/tabula/extractors/extraction_algorithm.rb

Overview

Base class for table extraction algorithms

Direct Known Subclasses

Basic, Spreadsheet

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ ExtractionAlgorithm

Returns a new instance of ExtractionAlgorithm.

Parameters:

  • options (Hash) —

    algorithm options



16
17
18
# File 'lib/tabula/extractors/extraction_algorithm.rb', line 16

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

Class Method Details

.extract(page, **options) ⇒ Array<Table>

Extract tables from a page

Parameters:

  • page (Page) —

    page to extract from

  • options (Hash) —

    algorithm-specific options

Returns:

  • (Array<Table>) —

    extracted tables



11
12
13
# File 'lib/tabula/extractors/extraction_algorithm.rb', line 11

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

Instance Method Details

#extract(page) ⇒ Array<Table>

Extract tables from a page

Parameters:

  • page (Page) —

    page to extract from

Returns:

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/tabula/extractors/extraction_algorithm.rb', line 23

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

#name ⇒ String

Get algorithm name for table metadata

Returns:

  • (String)


29
30
31
# File 'lib/tabula/extractors/extraction_algorithm.rb', line 29

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