Class: ActivePivot::Story

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/active_pivot/story.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.acceptedObject



65
66
67
# File 'lib/active_pivot/story.rb', line 65

def self.accepted
  where.not(accepted_at: nil)
end

.accepted_after(date) ⇒ Object



69
70
71
# File 'lib/active_pivot/story.rb', line 69

def self.accepted_after(date)
  where("#{table_name}.accepted_at >= ?", date)
end

.accepted_before(date) ⇒ Object



73
74
75
# File 'lib/active_pivot/story.rb', line 73

def self.accepted_before(date)
  where("#{table_name}.accepted_at <= ?", date)
end

.for_project(project_id) ⇒ Object



21
22
23
# File 'lib/active_pivot/story.rb', line 21

def self.for_project(project_id)
  where(project_id: project_id)
end

.order_by_project_nameObject



37
38
39
# File 'lib/active_pivot/story.rb', line 37

def self.order_by_project_name
  joins(:project).merge(Project.alphabetized)
end

.select_allObject



61
62
63
# File 'lib/active_pivot/story.rb', line 61

def self.select_all
  select("#{table_name}.*")
end

.select_points(as = :accepted_points) ⇒ Object



77
78
79
# File 'lib/active_pivot/story.rb', line 77

def self.select_points(as = :accepted_points)
  select("SUM(#{table_name}.estimate) as #{as}")
end

.subselect(scope, attribute = :id) ⇒ Object



41
42
43
# File 'lib/active_pivot/story.rb', line 41

def self.subselect(scope, attribute = :id)
  where("#{table_name}.id IN (#{scope.select(attribute).to_sql})")
end

.unique_estimatesObject



57
58
59
# File 'lib/active_pivot/story.rb', line 57

def self.unique_estimates
  group(:estimate).pluck(:estimate).reject(&:blank?)
end

.unique_statusesObject



53
54
55
# File 'lib/active_pivot/story.rb', line 53

def self.unique_statuses
  group(:current_state).pluck(:current_state)
end

.with_estimate(estimate) ⇒ Object



29
30
31
# File 'lib/active_pivot/story.rb', line 29

def self.with_estimate(estimate)
  where(estimate: estimate)
end

.with_number(number) ⇒ Object



33
34
35
# File 'lib/active_pivot/story.rb', line 33

def self.with_number(number)
  where(pivotal_id: number)
end

.with_status(status) ⇒ Object



25
26
27
# File 'lib/active_pivot/story.rb', line 25

def self.with_status(status)
  where(current_state: status)
end

.with_tags(*tags) ⇒ Object



81
82
83
# File 'lib/active_pivot/story.rb', line 81

def self.with_tags(*tags)
  where("#{table_name}.tags @> ARRAY[?]", tags.join(","))
end

.worked_on_after(date) ⇒ Object



49
50
51
# File 'lib/active_pivot/story.rb', line 49

def self.worked_on_after(date)
  subselect Story.unscoped.joins(:time_entries).merge(TimeEntry.worked_on_after(date))
end

.worked_on_before(date) ⇒ Object



45
46
47
# File 'lib/active_pivot/story.rb', line 45

def self.worked_on_before(date)
  subselect Story.unscoped.joins(:time_entries).merge(TimeEntry.worked_on_before(date))
end

Instance Method Details

#accepted?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/active_pivot/story.rb', line 132

def accepted?
  accepted_at?
end

#billed_amountObject



112
113
114
# File 'lib/active_pivot/story.rb', line 112

def billed_amount
  (read_attribute(:billed_amount) || time_entries.map(&:billed_amount).sum).to_f
end

#billed_amount_per_pointObject



116
117
118
# File 'lib/active_pivot/story.rb', line 116

def billed_amount_per_point
  estimate.to_i.zero? ? 0 : billed_amount / estimate.to_i
end

#hoursObject



104
105
106
# File 'lib/active_pivot/story.rb', line 104

def hours
  read_attribute(:minutes) ? (minutes / 60.0) : time_entries.map(&:hours).sum
end

#hours_per_pointObject



120
121
122
# File 'lib/active_pivot/story.rb', line 120

def hours_per_point
  estimate.to_i.zero? ? 0 : hours / estimate.to_i
end

#human_stateObject



96
97
98
# File 'lib/active_pivot/story.rb', line 96

def human_state
  state.titleize
end

#human_typeObject



100
101
102
# File 'lib/active_pivot/story.rb', line 100

def human_type
  story_type.titleize
end

#invoice_hoursObject



108
109
110
# File 'lib/active_pivot/story.rb', line 108

def invoice_hours
  read_attribute(:invoice_minutes) ? (invoice_minutes / 60.0) : time_entries.map(&:invoice_hours).sum
end

#invoice_hours_per_pointObject



124
125
126
# File 'lib/active_pivot/story.rb', line 124

def invoice_hours_per_point
  estimate.to_i.zero? ? 0 : invoice_hours / estimate.to_i
end

#labels=(labels) ⇒ Object



85
86
87
88
89
90
# File 'lib/active_pivot/story.rb', line 85

def labels=(labels)
  super(Array.wrap(labels))

  self.epics = extract_epics_for_labels(labels)
  self.tags  = extract_tags_for_labels(labels)
end

#remote_activities(params = {}) ⇒ Object



17
18
19
# File 'lib/active_pivot/story.rb', line 17

def remote_activities(params = {})
  Api::Activity.for_project(project_id, pivotal_id, params)
end

#stateObject



92
93
94
# File 'lib/active_pivot/story.rb', line 92

def state
  current_state
end

#to_paramObject



128
129
130
# File 'lib/active_pivot/story.rb', line 128

def to_param
  pivotal_id
end