Class: Trajectory::Iterations
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Trajectory::Iterations
- Defined in:
- lib/trajectory/domain/iterations.rb
Class Method Summary collapse
-
.from_json(project, json_attributes) ⇒ Object
Create a new collection of Iteration from a JSON array of attributes from trajectory API.
Instance Method Summary collapse
-
#current ⇒ Iteration, false
Returns the current iteration of the project or false it no current iteration can be found.
-
#find_by_id(id) ⇒ Iteration, false
Fetch the iteration with the given id in the collection.
-
#future ⇒ Iterations
Returns the future iterations of the project.
-
#initialize(*iterations) ⇒ Iterations
constructor
Creates a new collection of Iteration.
-
#past ⇒ Iterations
Returns the past iterations of the project.
Constructor Details
#initialize(*iterations) ⇒ Iterations
Creates a new collection of Trajectory::Iteration
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
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
#current ⇒ Iteration, false
Returns the current iteration of the project or false it no current iteration can be found
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
30 31 32 |
# File 'lib/trajectory/domain/iterations.rb', line 30 def find_by_id(id) iterations.find { |iteration| iteration.id == id } || false end |
#future ⇒ Iterations
Returns the future iterations of the project
44 45 46 |
# File 'lib/trajectory/domain/iterations.rb', line 44 def future iterations.select { |iteration| iteration.future? } end |
#past ⇒ Iterations
Returns the past iterations of the project
51 52 53 |
# File 'lib/trajectory/domain/iterations.rb', line 51 def past iterations.select { |iteration| iteration.past? } end |