Class: Ruber::World::ProjectList
- Includes:
- Enumerable
- Defined in:
- lib/ruber/world/project_list.rb
Overview
Note:
This list can’t contain more than one project with the same project file.
A list of projects
It’s an immutable @Enumerable@ class with some convenience methods for dealing with projects.
The projects in the list are set in the constructor and can’t be changed later.
The order of projects won’t be kept.
Direct Known Subclasses
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Comparison operator.
-
#[](arg) ⇒ Project?
Element access.
-
#each(&blk) ⇒ ProjectList, Enumerator
Iterates on the projects.
-
#empty? ⇒ Boolean
Whether or not the list is empty.
-
#eql?(other) ⇒ Boolean
Comparison operator used by Hash.
-
#hash ⇒ Integer
Override of @Object#hash@.
-
#initialize(prjs) ⇒ ProjectList
constructor
A new instance of ProjectList.
-
#size ⇒ Integer
The number of projects in the list.
Methods included from Enumerable
Constructor Details
#initialize(prjs) ⇒ ProjectList
Returns a new instance of ProjectList.
49 50 51 52 53 |
# File 'lib/ruber/world/project_list.rb', line 49 def initialize prjs if prjs.is_a? ProjectList then @projects = prjs.project_hash else @projects = Hash[prjs.map{|prj| [prj.project_file, prj]}] end end |
Instance Method Details
#==(other) ⇒ Boolean
Comparison operator
96 97 98 99 100 101 102 103 |
# File 'lib/ruber/world/project_list.rb', line 96 def == other case other when ProjectList then @projects == other.project_hash when Array @projects.values.sort_by(&:object_id) == other.sort_by(&:object_id) else false end end |
#[](filename) ⇒ Project? #[](name) ⇒ Project?
Element access
142 143 144 145 146 147 148 |
# File 'lib/ruber/world/project_list.rb', line 142 def [] arg if arg.start_with? '/' then @projects[arg] else prj = @projects.find{|i| i[1].project_name == arg} prj ? prj[1] : nil end end |
#each {|prj| ... } ⇒ ProjectList #each ⇒ Enumerator
Iterates on the projects
66 67 68 69 70 71 72 |
# File 'lib/ruber/world/project_list.rb', line 66 def each &blk if block_given? @projects.each_value &blk self else to_enum end end |
#empty? ⇒ Boolean
Whether or not the list is empty
78 79 80 |
# File 'lib/ruber/world/project_list.rb', line 78 def empty? @projects.empty? end |
#eql?(other) ⇒ Boolean
Comparison operator used by Hash
112 113 114 |
# File 'lib/ruber/world/project_list.rb', line 112 def eql? other other.is_a?(ProjectList) ? @projects.eql?(other.project_hash) : false end |
#hash ⇒ Integer
Override of @Object#hash@
121 122 123 |
# File 'lib/ruber/world/project_list.rb', line 121 def hash @projects.hash end |
#size ⇒ Integer
Returns the number of projects in the list.
85 86 87 |
# File 'lib/ruber/world/project_list.rb', line 85 def size @projects.size end |