Class: WordCountAnalyzer::Ellipsis
- Inherits:
-
Object
- Object
- WordCountAnalyzer::Ellipsis
- Defined in:
- lib/word_count_analyzer/ellipsis.rb
Constant Summary collapse
- THREE_CONSECUTIVE_REGEX =
Rubular: rubular.com/r/i60hCK81fz
/\.{3}(?=\s+[A-Z])/- FOUR_CONSECUTIVE_REGEX =
Rubular: rubular.com/r/mfdtSeuIf2
/(?<=[^\.])\.{3}\.(?=[^\.])/- THREE_SPACE_REGEX =
Rubular: rubular.com/r/YBG1dIHTRu
/(\s\.){3}\s/- FOUR_SPACE_REGEX =
Rubular: rubular.com/r/2VvZ8wRbd8
/(?<=[a-z])(\.\s){3}\.(\z|$|\n)/- OTHER_THREE_PERIOD_REGEX =
/[^\.]\.{3}[^\.]/- UNICODE_ELLIPSIS =
/(?<=[^…])…{1}(?=[^…])/
Instance Attribute Summary collapse
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #includes_ellipsis? ⇒ Boolean
-
#initialize(string:) ⇒ Ellipsis
constructor
A new instance of Ellipsis.
- #occurences ⇒ Object
- #replace ⇒ Object
Constructor Details
#initialize(string:) ⇒ Ellipsis
Returns a new instance of Ellipsis.
20 21 22 |
# File 'lib/word_count_analyzer/ellipsis.rb', line 20 def initialize(string:) @string = string end |
Instance Attribute Details
#string ⇒ Object (readonly)
Returns the value of attribute string.
19 20 21 |
# File 'lib/word_count_analyzer/ellipsis.rb', line 19 def string @string end |
Instance Method Details
#includes_ellipsis? ⇒ Boolean
24 25 26 27 28 29 30 31 |
# File 'lib/word_count_analyzer/ellipsis.rb', line 24 def includes_ellipsis? !(string !~ THREE_CONSECUTIVE_REGEX) || !(string !~ FOUR_CONSECUTIVE_REGEX) || !(string !~ THREE_SPACE_REGEX) || !(string !~ FOUR_SPACE_REGEX) || !(string !~ OTHER_THREE_PERIOD_REGEX) || !(string !~ UNICODE_ELLIPSIS) end |
#occurences ⇒ Object
42 43 44 45 46 |
# File 'lib/word_count_analyzer/ellipsis.rb', line 42 def occurences count = 0 replace.split(' ').map { |token| count += 1 if token.strip.eql?('wseword') } count end |
#replace ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/word_count_analyzer/ellipsis.rb', line 33 def replace string.gsub(THREE_CONSECUTIVE_REGEX, ' wseword ') .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 |