Class: TextExtractor::Guard

Inherits:
Record
  • Object
show all
Defined in:
lib/text_extractor/guard.rb

Constant Summary collapse

INDENTED =
{
  description: 'indented line',
  block: proc {
    /
    ^[^\n\S]+[^\n]*$
    /
  }
}.freeze
UNINDENTED =
{
  description: 'unindented line',
  block: proc {
    /
    ^\S+[^\n]*$
    /
  }
}.freeze
DEFAULT =
[
  INDENTED,
  UNINDENTED
].freeze

Instance Attribute Summary

Attributes inherited from Record

#factory, #regexp, #values

Instance Method Summary collapse

Methods inherited from Record

#build_extraction, #build_regexp, #expand_regexp, #extract_fills, #extract_values, #ignore_regexp, #initialize_inline_values, #match, #options, #regexp_line_ignorer, #regexp_line_stripper, #source, #strip_regexp

Constructor Details

#initialize(_regexp, description:, **kwargs) ⇒ Guard

Returns a new instance of Guard.



5
6
7
8
# File 'lib/text_extractor/guard.rb', line 5

def initialize(_regexp, description:, **kwargs)
  super
  @description = description
end

Instance Method Details

#extraction(match, _fill) ⇒ Object

Raises:



10
11
12
13
14
# File 'lib/text_extractor/guard.rb', line 10

def extraction(match, _fill)
  text = match[0]
  text = @factory.call(text) if @factory
  raise GuardError, "#{@description} near #{text.inspect}"
end