lib/card.rb in trollolo-0.1.1 vs lib/card.rb in trollolo-0.2.0
- old
+ new
@@ -18,17 +18,18 @@
class Card
# Assuming we have card titles as follows '(8) This is the card name'
ESTIMATED_REGEX = /\(([\d.]+)\)/
SPRINT_NUMBER_REGEX = /\ASprint (\d+)/
- def initialize(board_data, card_id)
- init_data(board_data, card_id)
+ def initialize(board_data, card_id, settings = nil)
+ init_data(board_data, card_id, settings)
end
- def init_data(board_data, card_id)
+ def init_data(board_data, card_id, settings = nil)
@board_data = board_data
- @card_data = @board_data["cards"].find{|c| c["id"] == card_id}
+ @settings = settings
+ @card_data = @board_data['cards'].find{|c| c['id'] == card_id}
end
def as_json
JSON.pretty_generate(@card_data)
end
@@ -41,56 +42,46 @@
return 0.0 unless estimated?
name.match(ESTIMATED_REGEX).captures.first.to_f
end
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
+ filtered_checklists.map(&:done_tasks).sum
end
def tasks
- count = 0
- @card_data["checklists"].each do |checklist|
- if checklist["name"] != "Feedback"
- count += checklist["checkItems"].count
- end
- end
- count
+ filtered_checklists.map(&:tasks).sum
end
def card_labels
- @card_data["labels"]
+ @card_data['labels']
end
def checklists
- @card_data["checklists"].map do |checklist|
+ @card_data['checklists'].map do |checklist|
Checklist.new(checklist)
end
end
+ def filtered_checklists
+ checklists.reject do |checklist|
+ @settings && @settings.no_task_checklists.include?(checklist.name)
+ end
+ end
+
def desc
- @card_data["desc"]
+ @card_data['desc']
end
def extra?
- self.card_labels.any? do |label|
+ card_labels.any? do |label|
label['name'].include?('BelowWaterline') ||
label['name'].include?('Under waterline')
end
end
def unplanned?
- self.card_labels.any? do |label|
+ card_labels.any? do |label|
label['name'].include?('Unplanned')
end
end
def meta_card?
@@ -102,31 +93,31 @@
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')
+ 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
+ yaml = Regexp.last_match(2)
if yaml
return YAML.load(yaml) # throws an exception for invalid yaml
else
return nil
end
end
def name
- @card_data["name"]
+ @card_data['name']
end
def name=(str)
- @card_data["name"] = str
+ @card_data['name'] = str
end
def id
- @card_data["id"]
+ @card_data['id']
end
end