class ActivePivot::Story
Public Class Methods
accepted()
click to toggle source
# File lib/active_pivot/story.rb, line 65 def self.accepted where.not(accepted_at: nil) end
accepted_after(date)
click to toggle source
# File lib/active_pivot/story.rb, line 69 def self.accepted_after(date) where("#{table_name}.accepted_at >= ?", date) end
accepted_before(date)
click to toggle source
# File lib/active_pivot/story.rb, line 73 def self.accepted_before(date) where("#{table_name}.accepted_at <= ?", date) end
for_project(project_id)
click to toggle source
# File lib/active_pivot/story.rb, line 21 def self.for_project(project_id) where(project_id: project_id) end
order_by_project_name()
click to toggle source
# File lib/active_pivot/story.rb, line 37 def self.order_by_project_name joins(:project).merge(Project.alphabetized) end
select_all()
click to toggle source
# File lib/active_pivot/story.rb, line 61 def self.select_all select("#{table_name}.*") end
select_points(as = :accepted_points)
click to toggle source
# 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)
click to toggle source
# 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_estimates()
click to toggle source
# File lib/active_pivot/story.rb, line 57 def self.unique_estimates group(:estimate).pluck(:estimate).reject(&:blank?) end
unique_statuses()
click to toggle source
# File lib/active_pivot/story.rb, line 53 def self.unique_statuses group(:current_state).pluck(:current_state) end
with_estimate(estimate)
click to toggle source
# File lib/active_pivot/story.rb, line 29 def self.with_estimate(estimate) where(estimate: estimate) end
with_number(number)
click to toggle source
# File lib/active_pivot/story.rb, line 33 def self.with_number(number) where(pivotal_id: number) end
with_status(status)
click to toggle source
# File lib/active_pivot/story.rb, line 25 def self.with_status(status) where(current_state: status) end
worked_on_after(date)
click to toggle source
# 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)
click to toggle source
# 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
Public Instance Methods
accepted?()
click to toggle source
# File lib/active_pivot/story.rb, line 132 def accepted? accepted_at? end
billed_amount()
click to toggle source
# 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_point()
click to toggle source
# File lib/active_pivot/story.rb, line 116 def billed_amount_per_point estimate.to_i.zero? ? 0 : billed_amount / estimate.to_i end
hours()
click to toggle source
# File lib/active_pivot/story.rb, line 104 def hours read_attribute(:minutes) ? (minutes / 60.0) : time_entries.map(&:hours).sum end
hours_per_point()
click to toggle source
# File lib/active_pivot/story.rb, line 120 def hours_per_point estimate.to_i.zero? ? 0 : hours / estimate.to_i end
human_state()
click to toggle source
# File lib/active_pivot/story.rb, line 96 def human_state state.titleize end
human_type()
click to toggle source
# File lib/active_pivot/story.rb, line 100 def human_type story_type.titleize end
invoice_hours()
click to toggle source
# 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_point()
click to toggle source
# 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)
click to toggle source
Calls superclass method
# 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 = {})
click to toggle source
# File lib/active_pivot/story.rb, line 17 def remote_activities(params = {}) Api::Activity.for_project(project_id, pivotal_id, params) end
state()
click to toggle source
# File lib/active_pivot/story.rb, line 92 def state current_state end
to_param()
click to toggle source
# File lib/active_pivot/story.rb, line 128 def to_param pivotal_id end
Private Instance Methods
extract_epics_for_labels(labels)
click to toggle source
# File lib/active_pivot/story.rb, line 142 def extract_epics_for_labels(labels) label_ids = Array.wrap(labels).reject(&:blank?).map { |label| label['id'] } Epic.where.not(label_id: nil).where(label_id: label_ids) end