Class: WordCountAnalyzer::Analyzer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:) ⇒ Analyzer

Returns a new instance of Analyzer.



4
5
6
7
# File 'lib/word_count_analyzer/analyzer.rb', line 4

def initialize(text:)
  @text = text
  @tgr = EngTagger.new
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



3
4
5
# File 'lib/word_count_analyzer/analyzer.rb', line 3

def text
  @text
end

#tgrObject (readonly)

Returns the value of attribute tgr.



3
4
5
# File 'lib/word_count_analyzer/analyzer.rb', line 3

def tgr
  @tgr
end

Instance Method Details

#analyzeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/word_count_analyzer/analyzer.rb', line 9

def analyze
  analysis = {}
  analysis['ellipsis'] = WordCountAnalyzer::Ellipsis.new(string: text).occurences
  contraction_count = 0
  hyphenated_word_count = 0
  WordCountAnalyzer::Xhtml.new(string: text).replace.split(/\s+/).each_with_index do |token, index|
    contraction_count += 1 if WordCountAnalyzer::Contraction.new(token: token, following_token: text.split(/\s+/)[index + 1], tgr: tgr, hyphen: 'single').contraction?
    hyphenated_word_count += 1 if WordCountAnalyzer::HyphenatedWord.new(token: token).hyphenated_word?
  end
  analysis['hyperlink'] = WordCountAnalyzer::Hyperlink.new(string: text).occurences
  analysis['contraction'] = contraction_count
  analysis['hyphenated_word'] = hyphenated_word_count
  analysis['date'] = WordCountAnalyzer::Date.new(string: text).occurences
  analysis['number'] = WordCountAnalyzer::Number.new(string: text).occurences
  analysis['numbered_list'] = WordCountAnalyzer::NumberedList.new(string: text).occurences
  analysis['xhtml'] = WordCountAnalyzer::Xhtml.new(string: text).occurences
  analysis['forward_slash'] = WordCountAnalyzer::Slash.new(string: text).forward_slash_occurences
  analysis['backslash'] = WordCountAnalyzer::Slash.new(string: text).backslash_occurences
  analysis['dotted_line'] = WordCountAnalyzer::Punctuation.new(string: text).dotted_line_ocurrances
  analysis['dashed_line'] = WordCountAnalyzer::Punctuation.new(string: text).dashed_line_ocurrances
  analysis['underscore'] = WordCountAnalyzer::Punctuation.new(string: text).underscore_ocurrances
  analysis['stray_punctuation'] = WordCountAnalyzer::Punctuation.new(string: text).stray_punctuation_occurences
  analysis
end