lib/card.rb in trollolo-0.0.3 vs lib/card.rb in trollolo-0.0.4
- old
+ new
@@ -14,51 +14,95 @@
#
# To contact SUSE about this file by physical or electronic mail,
# you may find current contact information at www.suse.com
class Card
+ # Assuming we have card titles as follows '(8) This is the card name'
+ ESTIMATED_REGEX = /\(([\d.]+)\)/
+ SPRINT_NUMBER_REGEX = /\ASprint (\d+)/
- attr_accessor :sp, :tasks, :tasks_done
+ def initialize(board_data, card_id)
+ init_data(board_data, card_id)
+ end
- def self.name_to_points(card_name)
- card_name =~ /^\(([\d.]+)\)/
- return nil if $1.nil?
- $1.to_f
+ def init_data(board_data, card_id)
+ @board_data = board_data
+ @card_data = @board_data["cards"].select{|c| c["id"] == card_id}.first
end
- def initialize
- @sp = nil
- @extra = false
+ def estimated?
+ name =~ ESTIMATED_REGEX
end
-
- def has_sp?
- @sp != nil
+
+ def story_points
+ return 0.0 unless estimated?
+ name.match(ESTIMATED_REGEX).captures.first.to_f
end
-
- def extra?
- @extra
+
+ def done_tasks
+ count = 0
+ @card_data["checklists"].each do |checklist|
+ if checklist["name"] != "Feedback"
+ checklist["checkItems"].each do |checklist_item|
+ if checklist_item["state"] == "complete"
+ count += 1
+ end
+ end
+ end
+ end
+ count
end
-
- def set_extra
- @extra = true
+
+ def tasks
+ count = 0
+ @card_data["checklists"].each do |checklist|
+ if checklist["name"] != "Feedback"
+ count += checklist["checkItems"].count
+ end
+ end
+ count
end
-
- def self.parse json
- card = Card.new
- title = json["name"]
- card.sp = name_to_points(title)
+ def card_labels
+ @card_data["labels"]
+ end
- labels = json["labels"]
- labels.each do |label|
- if label["name"] == "Under waterline"
- card.set_extra
- end
+ def desc
+ @card_data["desc"]
+ end
+
+ def extra?
+ self.card_labels.any? do |label|
+ label['name'].include?('BelowWaterline') ||
+ label['name'].include?('Under waterline')
end
+ end
- card.tasks = json["badges"]["checkItems"]
- card.tasks_done = json["badges"]["checkItemsChecked"]
+ def meta_card?
+ name =~ SPRINT_NUMBER_REGEX
+ end
- card
+ def sprint_number
+ raise ArgumentError unless meta_card?
+ name.match(SPRINT_NUMBER_REGEX).captures.first.to_i
end
+ def fast_lane?
+ # TODO: move to settings
+ self.card_labels.map{|l| l['name']}.include?('FastLane')
+ end
+
+ #TODO: rethink storage for meta data for sprint
+ def self.parse_yaml_from_description(description)
+ description =~ /```(yaml)?\n(.*)```/m
+ yaml = $2
+ if yaml
+ return YAML.load(yaml) # throws an exception for invalid yaml
+ else
+ return nil
+ end
+ end
+
+ def name
+ @card_data["name"]
+ end
end