Class: Trajectory::Iterations

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/trajectory/domain/iterations.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*iterations) ⇒ Iterations

Creates a new collection of Trajectory::Iteration

Parameters:



8
9
10
# File 'lib/trajectory/domain/iterations.rb', line 8

def initialize(*iterations)
  super(iterations)
end

Class Method Details

.from_json(project, json_attributes) ⇒ Object

Create a new collection of Trajectory::Iteration from a JSON array of attributes from trajectory API

Parameters:

  • project (Project)

    the project the iterations belongs to

  • json_attributes (Hash)

    the hash of attributes of each iteration of the collection



16
17
18
19
20
21
22
23
# File 'lib/trajectory/domain/iterations.rb', line 16

def self.from_json(project, json_attributes)
  new(*json_attributes.map do |attributes|
    attributes = attributes.symbolize_keys!.merge({project_id: project.id})
    attributes[:current] = attributes[:current?]
    attributes.delete(:current?)
    Iteration.new(attributes)
  end)
end

Instance Method Details

#currentIteration, false

Returns the current iteration of the project or false it no current iteration can be found

Returns:

  • (Iteration, false)

    the current iteration or false



37
38
39
# File 'lib/trajectory/domain/iterations.rb', line 37

def current
  iterations.find { |iteration| iteration.current? } || false
end

#find_by_id(id) ⇒ Iteration, false

Fetch the iteration with the given id in the collection. If it is not found, it returns false

Parameters:

  • id (Integer)

    the project id

Returns:

  • (Iteration, false)

    the found iteration or false



30
31
32
# File 'lib/trajectory/domain/iterations.rb', line 30

def find_by_id(id)
  iterations.find { |iteration| iteration.id == id } || false
end

#futureIterations

Returns the future iterations of the project

Returns:



44
45
46
# File 'lib/trajectory/domain/iterations.rb', line 44

def future
  iterations.select { |iteration| iteration.future? }
end

#pastIterations

Returns the past iterations of the project

Returns:



51
52
53
# File 'lib/trajectory/domain/iterations.rb', line 51

def past
  iterations.select { |iteration| iteration.past? }
end