Class: PragmaticSegmenter::BetweenPunctuation

Inherits:
Object
  • Object
show all
Defined in:
lib/pragmatic_segmenter/between_punctuation.rb

Overview

This class searches for punctuation between quotes or parenthesis and replaces it

Constant Summary collapse

BETWEEN_SINGLE_QUOTES_REGEX =
/(?<=\s)'(?:[^']|'[a-zA-Z])*'/
BETWEEN_DOUBLE_QUOTES_REGEX =
/"(?>[^"\\]+|\\{2}|\\.)*"/
BETWEEN_QUOTE_ARROW_REGEX =
/«(?>[^»\\]+|\\{2}|\\.)*»/
BETWEEN_QUOTE_SLANTED_REGEX =
/“(?>[^”\\]+|\\{2}|\\.)*”/
BETWEEN_SQUARE_BRACKETS_REGEX =
/\[(?>[^\]\\]+|\\{2}|\\.)*\]/
BETWEEN_PARENS_REGEX =
/\((?>[^\(\)\\]+|\\{2}|\\.)*\)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:) ⇒ BetweenPunctuation

Returns a new instance of BetweenPunctuation.



27
28
29
# File 'lib/pragmatic_segmenter/between_punctuation.rb', line 27

def initialize(text:)
  @text = text
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



26
27
28
# File 'lib/pragmatic_segmenter/between_punctuation.rb', line 26

def text
  @text
end

Instance Method Details

#replaceObject



31
32
33
# File 'lib/pragmatic_segmenter/between_punctuation.rb', line 31

def replace
  sub_punctuation_between_quotes_and_parens(text)
end