Class: Mindee::Extraction::TaxExtractor

Inherits:
OcrExtractor show all
Defined in:
lib/mindee/extraction/tax_extractor/tax_extractor.rb

Overview

Tax extractor class

Class Method Summary collapse

Class Method Details

.extract_custom_tax(ocr_result, tax_names, min_rate_percentage = 0, max_rate_percentage = 100) ⇒ Mindee::Parsing::Standard::TaxField?

Extracts a single custom type of tax. For the sake of simplicity, this only extracts the first example, unless specifically instructed otherwise.

Parameters:

  • ocr_result (Mindee::Parsing::Common::Ocr::Ocr)

    result of the OCR.

  • tax_names (Array<String>)

    list of all possible names the tax can have.

  • min_rate_percentage (Integer) (defaults to: 0)

    Minimum allowed rate on the tax.

  • max_rate_percentage (Integer) (defaults to: 100)

    Maximum allowed rate on the tax.

Returns:



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/mindee/extraction/tax_extractor/tax_extractor.rb', line 147

def self.extract_custom_tax(ocr_result, tax_names, min_rate_percentage = 0, max_rate_percentage = 100)
  return nil if ocr_result.is_a?(Mindee::Parsing::Common::Ocr) || tax_names.empty?

  tax_names.sort!
  found_hash = pick_best(extract_horizontal_tax(ocr_result, tax_names), tax_names)
  # a tax is considered found horizontally if it has a value, otherwise it is vertical
  if found_hash.nil? || found_hash['value'].nil?
    found_hash = extract_vertical_tax(ocr_result, tax_names,
                                      found_hash)
  end
  found_hash = curate_values(found_hash, min_rate_percentage, max_rate_percentage)

  return if found_hash.nil? || found_hash.empty?

  create_tax_field(found_hash)
end