class Tracco::TrackedCard
Public Class Methods
all_tracked_cards(sorting_options = {})
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 41 def self.all_tracked_cards(sorting_options = {}) cards = all.reject(&:no_tracking?) cards.sort_by!(&sorting_options[:sort_by].to_sym) if sorting_options[:sort_by] cards.reverse! if sorting_options[:order] == :desc return cards end
build_from(trello_card)
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 48 def self.build_from(trello_card) trello_card_id = trello_card.id trello_card.attributes.delete(:id) new(trello_card.attributes.merge(trello_id: trello_card_id)) end
efforts_between(search_options)
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 54 def self.efforts_between(search_options) condition = {} {'$gte' => :from_date, '$lte' => :to_date}.each do |selection, option_key| condition[selection] = search_options[option_key] if search_options[option_key] end where("efforts.date" => condition) end
find_by_trello_id(trello_id)
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 27 def self.find_by_trello_id(trello_id) without_mongo_raising_errors do find_by(trello_id: trello_id) end end
update_or_create_with(trello_card)
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 33 def self.update_or_create_with(trello_card) tracked_card = find_or_create_by(trello_id: trello_card.id) trello_card.attributes.delete(:id) tracked_card_attributes = trello_card.attributes.merge(done: trello_card.in_done_column?) updated_successfully = tracked_card.update_attributes(tracked_card_attributes) return tracked_card if updated_successfully end
Public Instance Methods
==(other)
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 142 def ==(other) return true if other.equal?(self) return false unless other.kind_of?(self.class) trello_id == other.trello_id end
add(tracking)
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 73 def add(tracking) tracking.add_to(self) end
add!(tracking)
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 77 def add!(tracking) add(tracking) && save! end
contains_effort?(effort)
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 81 def contains_effort?(effort) efforts.unscoped.any? { |e| e.tracking_notification_id == effort.tracking_notification_id } end
contains_estimate?(estimate)
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 85 def contains_estimate?(estimate) estimates.any? { |e| e.tracking_notification_id == estimate.tracking_notification_id } end
estimate_errors()
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 121 def estimate_errors return [] if estimates.empty? || efforts.empty? estimate_errors = [] estimates.each do |each| estimate_errors << (100 * ((total_effort - each.amount) / each.amount * 1.0)).round(2) end estimate_errors end
first_activity_date()
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 93 def first_activity_date [working_start_date, first_estimate_date].compact.min end
first_estimate_date()
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 101 def first_estimate_date estimates.sort_by(&:date).first.date if estimates.present? end
last_estimate_date()
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 105 def last_estimate_date estimates.sort_by(&:date).last.date if estimates.present? end
last_estimate_error()
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 117 def last_estimate_error estimate_errors.last end
members()
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 113 def members efforts.map(&:members).flatten.uniq end
no_tracking?()
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 89 def no_tracking? first_activity_date.nil? end
status()
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 63 def status if done? :done elsif efforts.empty? :todo else :in_progress end end
to_s()
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 138 def to_s "[#{name}]. Total effort: #{total_effort}h. Estimates #{estimates.map(&:to_s)}. Efforts: #{efforts.map(&:to_s)}" end
total_effort()
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 109 def total_effort efforts.map(&:amount).inject(0, &:+) end
trello_notifications()
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 132 def trello_notifications # TODO select all efforts, even the muted ones? notification_ids = efforts.map(&:tracking_notification_id) | estimates.map(&:tracking_notification_id) notification_ids.map { |id| Trello::Notification.find(id) rescue nil }.compact.sort_by(&:date) end
working_start_date()
click to toggle source
# File lib/tracco/models/tracked_card.rb, line 97 def working_start_date efforts.sort_by(&:date).first.date if efforts.present? end