Class: WordCountAnalyzer::HyphenatedWord

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

Constant Summary collapse

DASHED_LINE_REGEX =
/\s-{2,}(\s|$)|\A-{2,}(\s|$)/

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#tokenObject (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_multipleObject



15
16
17
# File 'lib/word_count_analyzer/hyphenated_word.rb', line 15

def count_as_multiple
  token.split(/[﹘,-]/).length
end

#hyphenated_word?Boolean

Returns:

  • (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

#replaceObject



19
20
21
# File 'lib/word_count_analyzer/hyphenated_word.rb', line 19

def replace
  token.split(/[﹘,-]/).join(' ')
end