Class: ProjectCatalog
- Inherits:
-
Object
- Object
- ProjectCatalog
- Defined in:
- lib/project_catalog.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_project(project) ⇒ Object
-
#initialize ⇒ ProjectCatalog
constructor
A new instance of ProjectCatalog.
- #load ⇒ Object
- #projects(criteria = nil) ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize ⇒ ProjectCatalog
Returns a new instance of ProjectCatalog.
3 4 5 |
# File 'lib/project_catalog.rb', line 3 def initialize @projects = [] end |
Class Method Details
.load ⇒ Object
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 |
#load ⇒ Object
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 |
#save ⇒ Object
21 22 23 24 |
# File 'lib/project_catalog.rb', line 21 def save @projects.all? &:save self end |