Class: Ruber::World::MutableProjectList
- Inherits:
-
ProjectList
- Object
- ProjectList
- Ruber::World::MutableProjectList
- Defined in:
- lib/ruber/world/project_list.rb
Overview
A ProjectList which allows to change the contents of the list.
Instance Method Summary collapse
-
#add(*projects) ⇒ MutableProjectList
Adds projects to the list.
-
#clear ⇒ MutableProjectList
Removes all the elements from the list.
-
#clone ⇒ MutableProjectList
Override of @Object#clone@.
-
#delete_if {|prj| ... } ⇒ MutableProjectList
Removes from the list all the projects for which the block returns true.
-
#dup ⇒ MutableProjectList
Override of @Object#dup@.
-
#initialize(prjs = []) ⇒ MutableProjectList
constructor
A new instance of MutableProjectList.
-
#merge!(prjs) ⇒ MutableProjectList
Adds the projects contained in another list to this list.
-
#remove(prj) ⇒ Project?
Removes a project from the list.
Methods inherited from ProjectList
#==, #[], #each, #empty?, #eql?, #hash, #size
Methods included from Enumerable
Constructor Details
#initialize(prjs = []) ⇒ MutableProjectList
Returns a new instance of MutableProjectList.
171 172 173 |
# File 'lib/ruber/world/project_list.rb', line 171 def initialize prjs = [] @projects = Hash[prjs.map{|prj| [prj.project_name, prj]}] end |
Instance Method Details
#add(*projects) ⇒ MutableProjectList
Adds projects to the list
205 206 207 208 209 |
# File 'lib/ruber/world/project_list.rb', line 205 def add *projects projects.flatten.each do |prj| @projects[prj.project_file] = prj end end |
#clear ⇒ MutableProjectList
Removes all the elements from the list
243 244 245 246 |
# File 'lib/ruber/world/project_list.rb', line 243 def clear @projects.clear self end |
#clone ⇒ MutableProjectList
Override of @Object#clone@
187 188 189 190 191 192 193 194 |
# File 'lib/ruber/world/project_list.rb', line 187 def clone res = self.class.new self if frozen? res.freeze res.project_hash.freeze end res end |
#delete_if {|prj| ... } ⇒ MutableProjectList
Removes from the list all the projects for which the block returns true
256 257 258 259 |
# File 'lib/ruber/world/project_list.rb', line 256 def delete_if &blk @projects.delete_if{|_, prj| blk.call prj} self end |
#dup ⇒ MutableProjectList
Override of @Object#dup@
179 180 181 |
# File 'lib/ruber/world/project_list.rb', line 179 def dup self.class.new self end |
#merge!(prjs) ⇒ MutableProjectList
Adds the projects contained in another list to this list
218 219 220 221 222 223 224 |
# File 'lib/ruber/world/project_list.rb', line 218 def merge! prjs if prjs.is_a? ProjectList then @projects.merge! prjs.project_hash else @projects.merge! Hash[prjs.map{|prj| [prj.project_file, prj]}] end self end |
#remove(prj) ⇒ Project?
Removes a project from the list
If the given project isn’t in the list, nothing is done
234 235 236 |
# File 'lib/ruber/world/project_list.rb', line 234 def remove prj @projects.delete prj.project_file end |