Class: Trajectory::Projects
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Trajectory::Projects
- Defined in:
- lib/trajectory/domain/projects.rb
Class Method Summary collapse
-
.from_json(json_attributes) ⇒ Object
Create a new collection of Project from a JSON array of attributes from trajectory API.
Instance Method Summary collapse
-
#active ⇒ Projects
Returns the active projects of the collection.
-
#archived ⇒ Projects
Returns the archived projects of the collection.
-
#find_by_id(id) ⇒ Project, false
Fetch the project with the given id in the collection.
-
#find_by_keyword(keyword) ⇒ Project, false
Fetch the project with the given keyword in the collection.
-
#initialize(*projects) ⇒ Projects
constructor
Creates a new collection of Projects.
Constructor Details
#initialize(*projects) ⇒ Projects
Creates a new collection of Trajectory::Projects
10 11 12 |
# File 'lib/trajectory/domain/projects.rb', line 10 def initialize(*projects) super(projects) end |
Class Method Details
.from_json(json_attributes) ⇒ Object
Create a new collection of Trajectory::Project from a JSON array of attributes from trajectory API
17 18 19 20 21 |
# File 'lib/trajectory/domain/projects.rb', line 17 def self.from_json(json_attributes) new(*json_attributes.map do |attributes| Project.new(attributes.symbolize_keys!) end) end |
Instance Method Details
#active ⇒ Projects
Returns the active projects of the collection
51 52 53 |
# File 'lib/trajectory/domain/projects.rb', line 51 def active projects.select { |project| !project.archived? } end |
#archived ⇒ Projects
Returns the archived projects of the collection
44 45 46 |
# File 'lib/trajectory/domain/projects.rb', line 44 def archived projects.select { |project| project.archived? } end |
#find_by_id(id) ⇒ Project, false
Fetch the project with the given id in the collection. If it is not found, it returns false
28 29 30 |
# File 'lib/trajectory/domain/projects.rb', line 28 def find_by_id(id) projects.find { |project| project.id == id } || false end |
#find_by_keyword(keyword) ⇒ Project, false
Fetch the project with the given keyword in the collection. If it is not found, it returns false
37 38 39 |
# File 'lib/trajectory/domain/projects.rb', line 37 def find_by_keyword(keyword) projects.find { |project| project.keyword == keyword } || false end |