Class: Trajectory::Projects

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*projects) ⇒ Projects

Creates a new collection of Trajectory::Projects

Parameters:



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

Parameters:

  • json_attributes (Hash)

    the hash of attributes of each project of the collection



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

#activeProjects

Returns the active projects of the collection

Returns:

  • (Projects)

    the filtered collection



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

def active
  projects.select { |project| !project.archived? }
end

#archivedProjects

Returns the archived projects of the collection

Returns:

  • (Projects)

    the filtered 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

Parameters:

  • id (Integer)

    the project id

Returns:

  • (Project, false)

    the found project or 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

Parameters:

  • keyword (String)

    the project keyword

Returns:

  • (Project, false)

    the found project or 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