Class: Lita::Handlers::Estimate
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::Estimate
- Defined in:
- lib/lita/handlers/estimate.rb
Instance Method Summary collapse
- #average(estimates) ⇒ Object
- #estimate(response) ⇒ Object
- #key(story) ⇒ Object
- #reset_estimates(response) ⇒ Object
- #show_estimates(response) ⇒ Object
- #show_estimators(response) ⇒ Object
Instance Method Details
#average(estimates) ⇒ Object
55 56 57 |
# File 'lib/lita/handlers/estimate.rb', line 55 def average(estimates) estimates.map(&:to_i).inject(:+).to_f / estimates.size end |
#estimate(response) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/lita/handlers/estimate.rb', line 10 def estimate(response) story, points = response.matches.first if ['1','2','3','5','8','13'].include?(points) redis.hset(key(story), response.user.name, points) response.reply('Thanks!') else response.reply('Please use a Fibonacci number not larger than 13') end end |
#key(story) ⇒ Object
51 52 53 |
# File 'lib/lita/handlers/estimate.rb', line 51 def key(story) ['estimate', story].join(':') end |
#reset_estimates(response) ⇒ Object
45 46 47 48 49 |
# File 'lib/lita/handlers/estimate.rb', line 45 def reset_estimates(response) story = response.matches.flatten.first redis.del(key(story)) response.reply("Estimates reset for #{story}") end |
#show_estimates(response) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/lita/handlers/estimate.rb', line 20 def show_estimates(response) story = response.matches.flatten.first estimates = redis.hgetall(key(story)) if estimates.empty? response.reply("No estimates yet for #{story}") else lines = [] estimates.map{|dev, est| [est.to_i, dev]}.sort.each do |estimate, estimator| lines << "#{estimate} (#{estimator})" end lines << "#{sprintf('%.1f', average(estimates.values))} Average" response.reply(lines.join("\n")) end end |
#show_estimators(response) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/lita/handlers/estimate.rb', line 35 def show_estimators(response) story = response.matches.flatten.first estimates = redis.hgetall(key(story)) if estimates.empty? response.reply("No estimators yet for #{story}") else response.reply(estimates.keys.sort.join("\n")) end end |