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