Sha256: 44499b205fba2aa4289acc10060899cf7cbe7d6c81c00b0c1d3d5fb968199cb6

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 KB

Contents

module WordCountAnalyzer
  class Analyzer
    attr_reader :text, :tagger
    def initialize(text:)
      @text = text
      @tagger = EngTagger.new
    end

    def analyze
      analysis = {}
      analysis['ellipsis'] = WordCountAnalyzer::Ellipsis.new.occurrences(text)
      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: tagger, hyphen: 'single').contraction?
        hyphenated_word_count += 1 if WordCountAnalyzer::HyphenatedWord.new(token: token).hyphenated_word?
      end
      analysis['hyperlink'] = WordCountAnalyzer::Hyperlink.new.occurrences(text)
      analysis['contraction'] = contraction_count
      analysis['hyphenated_word'] = hyphenated_word_count
      analysis['date'] = WordCountAnalyzer::Date.new.occurrences(text)
      analysis['number'] = WordCountAnalyzer::Number.new(string: text).occurrences
      analysis['numbered_list'] = WordCountAnalyzer::NumberedList.new(string: text).occurrences
      analysis['xhtml'] = WordCountAnalyzer::Xhtml.new(string: text).occurrences
      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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
word_count_analyzer-1.0.1 lib/word_count_analyzer/analyzer.rb