Class: WordCountAnalyzer::HyphenatedWord
- Inherits:
-
Object
- Object
- WordCountAnalyzer::HyphenatedWord
- Defined in:
- lib/word_count_analyzer/hyphenated_word.rb
Constant Summary collapse
- DASHED_LINE_REGEX =
Rubular: rubular.com/r/RjZ7qi0uFf
/\s-{2,}(\s|$)|\A-{2,}(\s|$)/
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #count_as_multiple ⇒ Object
- #hyphenated_word? ⇒ Boolean
-
#initialize(token:) ⇒ HyphenatedWord
constructor
A new instance of HyphenatedWord.
- #replace ⇒ Object
Constructor Details
#initialize(token:) ⇒ HyphenatedWord
Returns a new instance of HyphenatedWord.
7 8 9 |
# File 'lib/word_count_analyzer/hyphenated_word.rb', line 7 def initialize(token:) @token = token.gsub(DASHED_LINE_REGEX, '') end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
6 7 8 |
# File 'lib/word_count_analyzer/hyphenated_word.rb', line 6 def token @token end |
Instance Method Details
#count_as_multiple ⇒ Object
15 16 17 |
# File 'lib/word_count_analyzer/hyphenated_word.rb', line 15 def count_as_multiple token.split(/[﹘,-]/).length end |
#hyphenated_word? ⇒ Boolean
11 12 13 |
# File 'lib/word_count_analyzer/hyphenated_word.rb', line 11 def hyphenated_word? (token.include?('-') || token.include?('﹘')) && !WordCountAnalyzer::Hyperlink.new(string: token).hyperlink? end |
#replace ⇒ Object
19 20 21 |
# File 'lib/word_count_analyzer/hyphenated_word.rb', line 19 def replace token.split(/[﹘,-]/).join(' ') end |