Class: ProjectCatalog

Inherits:
Object
  • Object
show all
Defined in:
lib/project_catalog.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProjectCatalog

Returns a new instance of ProjectCatalog.



3
4
5
# File 'lib/project_catalog.rb', line 3

def initialize
  @projects = []
end

Class Method Details

.loadObject



31
32
33
# File 'lib/project_catalog.rb', line 31

def self.load
  self.new.load
end

Instance Method Details

#add_project(project) ⇒ Object



16
17
18
19
# File 'lib/project_catalog.rb', line 16

def add_project project
  @projects << project
  self
end

#loadObject



26
27
28
29
# File 'lib/project_catalog.rb', line 26

def load
  @projects = Project.all
  self
end

#projects(criteria = nil) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/project_catalog.rb', line 7

def projects criteria = nil
  result = @projects.sort_by(&:name)

  return result if criteria.blank?
  result.find_all { |project|
    project.instance_eval criteria
  }
end

#saveObject



21
22
23
24
# File 'lib/project_catalog.rb', line 21

def save
  @projects.all? &:save
  self
end