Class: Houston::Roadmaps::MilestonePresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/houston/roadmaps/milestone_presenter.rb

Instance Method Summary collapse

Constructor Details

#initialize(milestones) ⇒ MilestonePresenter

Returns a new instance of MilestonePresenter.



3
4
5
# File 'app/presenters/houston/roadmaps/milestone_presenter.rb', line 3

def initialize(milestones)
  @milestones = OneOrMany.new(milestones)
end

Instance Method Details

#as_json(*args) ⇒ Object



7
8
9
# File 'app/presenters/houston/roadmaps/milestone_presenter.rb', line 7

def as_json(*args)
  @milestones.map(&method(:to_hash))
end

#to_hash(milestone) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/presenters/houston/roadmaps/milestone_presenter.rb', line 11

def to_hash(milestone)
  project = milestone.project
  { id: milestone.id,
    name: milestone.name,
    roadmaps: milestone.roadmap_ids,
    projectId: project.id,
    projectColor: project.color,
    projectName: project.name,
    tickets: milestone.tickets_count,
    ticketsCompleted: milestone.closed_tickets_count,
    percentComplete: percent_complete(milestone),
    completed: milestone.completed?,
    band: milestone.band,
    lanes: milestone.lanes,
    locked: milestone.locked? || milestone.completed?,
    startDate: milestone.start_date,
    endDate: milestone.end_date,
    removed: milestone.destroyed_at.present? }
end