lib/burndown_data.rb in trollolo-0.2.0 vs lib/burndown_data.rb in trollolo-0.3.0

- old
+ new

@@ -31,13 +31,35 @@ def total @open + @done end end + class SwimlaneResult + attr_accessor :todo, :doing, :done + + def add_todo(story_points) + @todo += story_points + end + + def add_doing(story_points) + @doing += story_points + end + + def add_done(story_points) + @done += story_points + end + + def initialize + @todo = 0 + @doing = 0 + @done = 0 + end + end + attr_accessor :story_points, :tasks, :extra_story_points, :extra_tasks, :unplanned_story_points, :unplanned_tasks, - :board_id, :fast_lane_cards, :date_time + :board_id, :fast_lane_cards, :date_time, :swimlanes attr_reader :meta def initialize(settings) @settings = settings @story_points = Result.new @@ -46,10 +68,15 @@ @extra_tasks = Result.new @unplanned_story_points = Result.new @unplanned_tasks = Result.new @fast_lane_cards = Result.new @date_time = Time.now + + @swimlanes = {} + settings.swimlanes.each do |swimlane| + @swimlanes[swimlane] = SwimlaneResult.new + end end def to_hash base = { 'date' => date_time.to_date.to_s, @@ -67,29 +94,48 @@ }, 'tasks_extra' => { 'done' => extra_tasks.done } } - if fast_lane_cards.total > 0 - base['fast_lane'] = { - 'total' => fast_lane_cards.total, - 'open' => fast_lane_cards.open - } - end + + base['fast_lane'] = fast_lane_to_hash if fast_lane_cards.total > 0 + if unplanned_story_points.total > 0 base['unplanned_story_points'] = { 'total' => unplanned_story_points.total, 'open' => unplanned_story_points.open } base['unplanned_tasks'] = { 'total' => unplanned_tasks.total, 'open' => unplanned_tasks.open } end + + base['swimlanes'] = swimlanes_to_hash unless swimlanes.empty? + base end + def fast_lane_to_hash + { + 'total' => fast_lane_cards.total, + 'open' => fast_lane_cards.open + } + end + + def swimlanes_to_hash + swimlanes_element = {} + swimlanes.each do |name, swimlane_result| + swimlanes_element[name] = { + 'todo' => swimlane_result.todo, + 'doing' => swimlane_result.doing, + 'done' => swimlane_result.done + } + end + swimlanes_element + end + def trello @trello ||= TrelloWrapper.new(@settings) end def board @@ -111,9 +157,36 @@ @unplanned_tasks.done = board.unplanned_closed_tasks @unplanned_tasks.open = board.unplanned_tasks - board.unplanned_closed_tasks @fast_lane_cards.done = board.done_fast_lane_cards_count @fast_lane_cards.open = board.open_fast_lane_cards_count @date_time = DateTime.now + + fetch_swimlanes + end + + def fetch_swimlanes + @settings.swimlanes.each do |swimlane| + board.todo_columns.each do |column| + column.cards.each do |card| + @swimlanes[swimlane].add_todo(card.story_points) if card.label?(swimlane) + end + end + + board.doing_columns.each do |column| + column.cards.each do |card| + @swimlanes[swimlane].add_doing(card.story_points) if card.label?(swimlane) + end + end + + board.done_column.cards.each do |card| + @swimlanes[swimlane].add_done(card.story_points) if card.label?(swimlane) + end + board.accepted_columns.each do |column| + column.cards.each do |card| + @swimlanes[swimlane].add_done(card.story_points) if card.label?(swimlane) + end + end + end end private def get_meta