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_SINGLE_QUOTE_SLANTED_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}|\\.)*\)/
WORD_WITH_LEADING_APOSTROPHE =
/(?<=\s)'(?:[^']|'[a-zA-Z])*'\S/
BETWEEN_EM_DASHES_REGEX =
/\-\-(?>[^\-\-])*\-\-/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:) ⇒ BetweenPunctuation

Returns a new instance of BetweenPunctuation.



35
36
37
# File 'lib/pragmatic_segmenter/between_punctuation.rb', line 35

def initialize(text:)
  @text = text
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



34
35
36
# File 'lib/pragmatic_segmenter/between_punctuation.rb', line 34

def text
  @text
end

Instance Method Details

#replaceObject



39
40
41
# File 'lib/pragmatic_segmenter/between_punctuation.rb', line 39

def replace
  sub_punctuation_between_quotes_and_parens(text)
end