Class: Werd::ProjectWordCounter
- Inherits:
-
Object
- Object
- Werd::ProjectWordCounter
- Includes:
- Contracts
- Defined in:
- lib/werd/project_word_counter.rb
Instance Attribute Summary collapse
-
#project_id ⇒ Object
readonly
Returns the value of attribute project_id.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #client ⇒ Object
- #document ⇒ Object
-
#initialize(token, project_id) ⇒ ProjectWordCounter
constructor
A new instance of ProjectWordCounter.
- #project ⇒ Object
- #words ⇒ Object
Constructor Details
#initialize(token, project_id) ⇒ ProjectWordCounter
Returns a new instance of ProjectWordCounter.
7 8 9 |
# File 'lib/werd/project_word_counter.rb', line 7 def initialize token, project_id @token, @project_id = token, project_id end |
Instance Attribute Details
#project_id ⇒ Object (readonly)
Returns the value of attribute project_id.
4 5 6 |
# File 'lib/werd/project_word_counter.rb', line 4 def project_id @project_id end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
4 5 6 |
# File 'lib/werd/project_word_counter.rb', line 4 def token @token end |
Instance Method Details
#client ⇒ Object
25 26 27 |
# File 'lib/werd/project_word_counter.rb', line 25 def client @client ||= TrackerApi::Client.new(token: token) end |
#document ⇒ Object
35 36 37 38 39 |
# 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 ⇒ Object
30 31 32 |
# File 'lib/werd/project_word_counter.rb', line 30 def project client.project project_id end |
#words ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# 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 |