Class: Ruber::World::ProjectList
- Inherits:
-
Object
- Object
- Ruber::World::ProjectList
- Includes:
- Enumerable
- Defined in:
- lib/ruber/world/project_list.rb
Overview
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)
-
- (Boolean) ==(other)
Comparison operator.
-
- (Project?) [](arg)
Element access.
-
- (ProjectList, Enumerator) each(&blk)
Iterates on the projects.
-
- (Boolean) empty?
Whether or not the list is empty.
-
- (Boolean) eql?(other)
Comparison operator used by Hash.
-
- (Integer) hash
Override of
Object#hash
. -
- (ProjectList) initialize(prjs)
constructor
A new instance of ProjectList.
-
- (Hash{String=>Project}) project_hash
protected
The internal hash used to keep trace of the projects.
-
- (Integer) size
The number of projects in the list.
Methods included from Enumerable
Constructor Details
- (ProjectList) initialize(prjs)
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
- (Boolean) ==(other)
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 |
- (Project?) [](filename) - (Project?) [](name)
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 |
- (ProjectList) each {|prj| ... } - (Enumerator) each
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 |
- (Boolean) empty?
Whether or not the list is empty
78 79 80 |
# File 'lib/ruber/world/project_list.rb', line 78 def empty? @projects.empty? end |
- (Boolean) eql?(other)
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 |
- (Integer) hash
Override of Object#hash
121 122 123 |
# File 'lib/ruber/world/project_list.rb', line 121 def hash @projects.hash end |
- (Hash{String=>Project}) project_hash (protected)
The internal hash used to keep trace of the projects
155 156 157 |
# File 'lib/ruber/world/project_list.rb', line 155 def project_hash @projects end |
- (Integer) size
The number of projects in the list
85 86 87 |
# File 'lib/ruber/world/project_list.rb', line 85 def size @projects.size end |