Sha256: 8b09ecd9f94bf35fefefd021d32f66de434333f15c6045d2817c99356712b9b9

Contents?: true

Size: 878 Bytes

Versions: 1

Compression:

Stored size: 878 Bytes

Contents

module Werd
  class ProjectWordCounter
    include Contracts
    attr_reader :project_id, :token

    Contract String, String => Any
    def initialize token, project_id
      @token, @project_id = token, project_id
    end

    Contract None => WordList
    def words
      counts = Hash.new 0
      document.split(/\W/).select do |str|
        str.size > 0
      end.map do |chunk|
        chunk.downcase
      end.each do |word|
        counts[word] += 1
      end
      counts.to_a.sort_by(&:last).reverse
    end

    Contract None => RespondTo[:project]
    def client
      @client ||= TrackerApi::Client.new(token: token)
    end

    Contract None => Any
    def project
      client.project project_id
    end

    Contract None => String
    def document
      project.stories.map do |s|
        [s.name, s.description]
      end.flatten.join("\n")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
werd-0.0.2 lib/werd/project_word_counter.rb