Class: WordCountAnalyzer::Ellipsis

Inherits:
Object
  • Object
show all
Defined in:
lib/word_count_analyzer/ellipsis.rb

Constant Summary collapse

FOUR_CONSECUTIVE_REGEX =
/(?<=[^\.]|\A)\.{3}\.(?=[^\.]|$)/
THREE_SPACE_REGEX =
/(\s\.){3}\s/
FOUR_SPACE_REGEX =
/(?<=[a-z]|\A)(\.\s){3}\.(\z|$|\n)/
OTHER_THREE_PERIOD_REGEX =
/(?<=[^\.]|\A)\.{3}(?=([^\.]|$))/
UNICODE_ELLIPSIS =
/(?<=[^…]|\A)…{1}(?=[^…]|$)/

Instance Method Summary collapse

Instance Method Details

#includes_ellipsis?(text) ⇒ Boolean



16
17
18
19
20
21
22
# File 'lib/word_count_analyzer/ellipsis.rb', line 16

def includes_ellipsis?(text)
  !(text !~ FOUR_CONSECUTIVE_REGEX) ||
  !(text !~ THREE_SPACE_REGEX) ||
  !(text !~ FOUR_SPACE_REGEX) ||
  !(text !~ OTHER_THREE_PERIOD_REGEX) ||
  !(text !~ UNICODE_ELLIPSIS)
end

#occurrences(text) ⇒ Object



32
33
34
35
36
# File 'lib/word_count_analyzer/ellipsis.rb', line 32

def occurrences(text)
  count = 0
  replace(text).split(' ').map { |token| count += 1 if token.strip.eql?('wseword') }
  count
end

#replace(text) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/word_count_analyzer/ellipsis.rb', line 24

def replace(text)
  text.gsub(FOUR_CONSECUTIVE_REGEX, ' wseword ')
        .gsub(THREE_SPACE_REGEX, ' wseword ')
        .gsub(FOUR_SPACE_REGEX, ' wseword ')
        .gsub(OTHER_THREE_PERIOD_REGEX, ' wseword ')
        .gsub(UNICODE_ELLIPSIS, ' wseword ')
end