Class: TrackedCard

Inherits:
Object
  • Object
show all
Extended by:
MongoidHelper
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/trello_effort_tracker/tracked_card.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MongoidHelper

without_mongo_raising_errors

Class Method Details

.build_from(trello_card) ⇒ Object



46
47
48
49
50
# File 'lib/trello_effort_tracker/tracked_card.rb', line 46

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

.find_by_trello_id(trello_id) ⇒ Object



22
23
24
25
26
# File 'lib/trello_effort_tracker/tracked_card.rb', line 22

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) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/trello_effort_tracker/tracked_card.rb', line 28

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

Instance Method Details

#==(other) ⇒ Object



115
116
117
118
119
# File 'lib/trello_effort_tracker/tracked_card.rb', line 115

def ==(other)
  return true if other.equal?(self)
  return false unless other.kind_of?(self.class)
  trello_id == other.trello_id
end

#add(tracking) ⇒ Object



52
53
54
# File 'lib/trello_effort_tracker/tracked_card.rb', line 52

def add(tracking)
  tracking.add_to(self)
end

#add!(tracking) ⇒ Object



56
57
58
# File 'lib/trello_effort_tracker/tracked_card.rb', line 56

def add!(tracking)
  add(tracking) && save!
end

#contains_effort?(effort) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/trello_effort_tracker/tracked_card.rb', line 60

def contains_effort?(effort)
  efforts.any? { |e| e.tracking_notification_id == effort.tracking_notification_id }
end

#contains_estimate?(estimate) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/trello_effort_tracker/tracked_card.rb', line 64

def contains_estimate?(estimate)
  estimates.any? { |e| e.tracking_notification_id == estimate.tracking_notification_id }
end

#estimate_errorsObject



100
101
102
103
104
105
106
107
108
109
# File 'lib/trello_effort_tracker/tracked_card.rb', line 100

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_dateObject



72
73
74
# File 'lib/trello_effort_tracker/tracked_card.rb', line 72

def first_activity_date
  [working_start_date, first_estimate_date].compact.min
end

#first_estimate_dateObject



80
81
82
# File 'lib/trello_effort_tracker/tracked_card.rb', line 80

def first_estimate_date
  estimates.sort_by(&:date).first.date if estimates.present?
end

#last_estimate_dateObject



84
85
86
# File 'lib/trello_effort_tracker/tracked_card.rb', line 84

def last_estimate_date
  estimates.sort_by(&:date).last.date if estimates.present?
end

#last_estimate_errorObject



96
97
98
# File 'lib/trello_effort_tracker/tracked_card.rb', line 96

def last_estimate_error
  estimate_errors.last
end

#membersObject



92
93
94
# File 'lib/trello_effort_tracker/tracked_card.rb', line 92

def members
  efforts.map(&:members).flatten.uniq
end

#no_tracking?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/trello_effort_tracker/tracked_card.rb', line 68

def no_tracking?
  first_activity_date.nil?
end

#statusObject



36
37
38
39
40
41
42
43
44
# File 'lib/trello_effort_tracker/tracked_card.rb', line 36

def status
  if done?
    :done
  elsif efforts.empty?
    :todo
  else
    :in_progress
  end
end

#to_sObject



111
112
113
# File 'lib/trello_effort_tracker/tracked_card.rb', line 111

def to_s
  "[#{name}]. Total effort: #{total_effort}h. Estimates #{estimates.map(&:to_s)}. Efforts: #{efforts.map(&:to_s)}"
end

#total_effortObject



88
89
90
# File 'lib/trello_effort_tracker/tracked_card.rb', line 88

def total_effort
  efforts.map(&:amount).inject(0, &:+)
end

#working_start_dateObject



76
77
78
# File 'lib/trello_effort_tracker/tracked_card.rb', line 76

def working_start_date
  efforts.sort_by(&:date).first.date if efforts.present?
end