class PragmaticSegmenter::BetweenPunctuation
This class searches for punctuation between quotes or parenthesis and replaces it
Constants
- BETWEEN_DOUBLE_QUOTES_REGEX
Rubular: rubular.com/r/3Pw1QlXOjd
- BETWEEN_EM_DASHES_REGEX
Rubular: rubular.com/r/jTtDKfjxzr
- BETWEEN_PARENS_REGEX
Rubular: rubular.com/r/6tTityPflI
- BETWEEN_QUOTE_ARROW_REGEX
Rubular: rubular.com/r/x6s4PZK8jc
- BETWEEN_QUOTE_SLANTED_REGEX
Rubular: rubular.com/r/JbAIpKdlSq
- BETWEEN_SINGLE_QUOTES_REGEX
Rubular: rubular.com/r/2YFrKWQUYi
- BETWEEN_SINGLE_QUOTE_SLANTED_REGEX
- BETWEEN_SQUARE_BRACKETS_REGEX
Rubular: rubular.com/r/WX4AvnZvlX
- WORD_WITH_LEADING_APOSTROPHE
Rubular: rubular.com/r/mXf8cW025o
Attributes
text[R]
Public Class Methods
new(text:)
click to toggle source
# File lib/pragmatic_segmenter/between_punctuation.rb, line 34 def initialize(text:) @text = text end
Public Instance Methods
replace()
click to toggle source
# File lib/pragmatic_segmenter/between_punctuation.rb, line 38 def replace sub_punctuation_between_quotes_and_parens(text) end
Private Instance Methods
btwn_dbl_quote(txt)
click to toggle source
# File lib/pragmatic_segmenter/between_punctuation.rb, line 93 def btwn_dbl_quote(txt) txt.scan(BETWEEN_DOUBLE_QUOTES_REGEX) end
sub_punctuation_between_double_quotes(txt)
click to toggle source
# File lib/pragmatic_segmenter/between_punctuation.rb, line 86 def sub_punctuation_between_double_quotes(txt) PragmaticSegmenter::PunctuationReplacer.new( matches_array: btwn_dbl_quote(txt), text: txt ).replace end
sub_punctuation_between_em_dashes(txt)
click to toggle source
# File lib/pragmatic_segmenter/between_punctuation.rb, line 104 def sub_punctuation_between_em_dashes(txt) PragmaticSegmenter::PunctuationReplacer.new( matches_array: txt.scan(BETWEEN_EM_DASHES_REGEX), text: txt ).replace end
sub_punctuation_between_parens(txt)
click to toggle source
# File lib/pragmatic_segmenter/between_punctuation.rb, line 55 def sub_punctuation_between_parens(txt) PragmaticSegmenter::PunctuationReplacer.new( matches_array: txt.scan(BETWEEN_PARENS_REGEX), text: txt ).replace end
sub_punctuation_between_quotes_and_parens(txt)
click to toggle source
# File lib/pragmatic_segmenter/between_punctuation.rb, line 44 def sub_punctuation_between_quotes_and_parens(txt) sub_punctuation_between_single_quotes(txt) sub_punctuation_between_single_quote_slanted(txt) sub_punctuation_between_double_quotes(txt) sub_punctuation_between_square_brackets(txt) sub_punctuation_between_parens(txt) sub_punctuation_between_quotes_arrow(txt) sub_punctuation_between_em_dashes(txt) sub_punctuation_between_quotes_slanted(txt) end
sub_punctuation_between_quotes_arrow(txt)
click to toggle source
# File lib/pragmatic_segmenter/between_punctuation.rb, line 97 def sub_punctuation_between_quotes_arrow(txt) PragmaticSegmenter::PunctuationReplacer.new( matches_array: txt.scan(BETWEEN_QUOTE_ARROW_REGEX), text: txt ).replace end
sub_punctuation_between_quotes_slanted(txt)
click to toggle source
# File lib/pragmatic_segmenter/between_punctuation.rb, line 111 def sub_punctuation_between_quotes_slanted(txt) PragmaticSegmenter::PunctuationReplacer.new( matches_array: txt.scan(BETWEEN_QUOTE_SLANTED_REGEX), text: txt ).replace end
sub_punctuation_between_single_quote_slanted(txt)
click to toggle source
# File lib/pragmatic_segmenter/between_punctuation.rb, line 79 def sub_punctuation_between_single_quote_slanted(txt) PragmaticSegmenter::PunctuationReplacer.new( matches_array: txt.scan(BETWEEN_SINGLE_QUOTE_SLANTED_REGEX), text: txt ).replace end
sub_punctuation_between_single_quotes(txt)
click to toggle source
# File lib/pragmatic_segmenter/between_punctuation.rb, line 69 def sub_punctuation_between_single_quotes(txt) unless !(txt !~ WORD_WITH_LEADING_APOSTROPHE) && txt !~ /'\s/ PragmaticSegmenter::PunctuationReplacer.new( matches_array: txt.scan(BETWEEN_SINGLE_QUOTES_REGEX), text: txt, match_type: 'single' ).replace end end
sub_punctuation_between_square_brackets(txt)
click to toggle source
# File lib/pragmatic_segmenter/between_punctuation.rb, line 62 def sub_punctuation_between_square_brackets(txt) PragmaticSegmenter::PunctuationReplacer.new( matches_array: txt.scan(BETWEEN_SQUARE_BRACKETS_REGEX), text: txt ).replace end