Class: Pello::Actions::Report
- Inherits:
-
Object
- Object
- Pello::Actions::Report
- Defined in:
- lib/pello/actions/report.rb
Constant Summary collapse
- POMODORI_ADDED_COMMENT =
/\((\d+) -> (\d+)\)$/.freeze
Instance Method Summary collapse
- #cached_author_name(author_id) ⇒ Object
- #lines_with_pomodori_increases_in(comment) ⇒ Object
- #pello_log?(comment) ⇒ Boolean
- #pomodori_before_and_after_from(comment_line) ⇒ Object
- #print_counters(counters, label) ⇒ Object
- #run(user, board_url) ⇒ Object
- #update_counters(counters, author_name, amount_to_add) ⇒ Object
Instance Method Details
#cached_author_name(author_id) ⇒ Object
57 58 59 60 61 |
# File 'lib/pello/actions/report.rb', line 57 def () @author_names ||= {} @author_names[] ||= Trello::Member.find().full_name @author_names[] end |
#lines_with_pomodori_increases_in(comment) ⇒ Object
39 40 41 |
# File 'lib/pello/actions/report.rb', line 39 def lines_with_pomodori_increases_in(comment) comment.data['text'].split("\n").select { |line| line.match? POMODORI_ADDED_COMMENT } end |
#pello_log?(comment) ⇒ Boolean
43 44 45 |
# File 'lib/pello/actions/report.rb', line 43 def pello_log?(comment) comment.data['text'] =~ /PELLO LOG/ end |
#pomodori_before_and_after_from(comment_line) ⇒ Object
35 36 37 |
# File 'lib/pello/actions/report.rb', line 35 def pomodori_before_and_after_from(comment_line) comment_line.match(POMODORI_ADDED_COMMENT)[1, 2].map(&:to_i) end |
#print_counters(counters, label) ⇒ Object
52 53 54 55 |
# File 'lib/pello/actions/report.rb', line 52 def print_counters(counters, label) puts "\n-- #{label}:" counters.each { |, | puts "* #{}: #{}" } end |
#run(user, board_url) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pello/actions/report.rb', line 8 def run(user, board_url) board = Pello::Inputs.choose_board user, board_url return unless board board_totals = {} lists = board.lists lists.each do |list| list_totals = {} list.cards.each do |card| card.comments.select { |comment| pello_log?(comment) }.each do |comment| lines_with_pomodori_increases_in(comment).each do |line| = (comment.creator_id) pom_before, pom_after = pomodori_before_and_after_from(line) update_counters(list_totals, , (pom_after - pom_before)) update_counters(board_totals, , (pom_after - pom_before)) end end end print_counters(list_totals, list.name) if list_totals.any? end print_counters(board_totals, 'Totals') puts "\n" end |
#update_counters(counters, author_name, amount_to_add) ⇒ Object
47 48 49 50 |
# File 'lib/pello/actions/report.rb', line 47 def update_counters(counters, , amount_to_add) counters[] ||= 0 counters[] = counters[] + amount_to_add end |