class Werd::ProjectWordCounter

Attributes

project_id[R]
token[R]

Public Class Methods

new(token, project_id) click to toggle source
# File lib/werd/project_word_counter.rb, line 7
def initialize token, project_id
  @token, @project_id = token, project_id
end

Public Instance Methods

client() click to toggle source
# File lib/werd/project_word_counter.rb, line 25
def client
  @client ||= TrackerApi::Client.new(token: token)
end
document() click to toggle source
# File lib/werd/project_word_counter.rb, line 35
def document
  project.stories.map do |s|
    [s.name, s.description]
  end.flatten.join("\n")
end
project() click to toggle source
# File lib/werd/project_word_counter.rb, line 30
def project
  client.project project_id
end
words() click to toggle source
# File lib/werd/project_word_counter.rb, line 12
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