Class: Ruber::World::ProjectList

Inherits:
Object
  • Object
show all
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

MutableProjectList

Instance Method Summary collapse

Methods included from Enumerable

#find!

Constructor Details

#initialize(prjs) ⇒ 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

Overloads:

  • #[](filename) ⇒ Project?

    Retrieves the project for the given project file

  • #[](name) ⇒ Project?

    Retrieves the project having the given project name



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 #eachEnumerator

Iterates on the projects

Overloads:

  • #each {|prj| ... } ⇒ ProjectList

    Calls the block once for each project in the list (the order is arbitrary)

    Yield Parameters:

    • prj (Project)

      the projects in the list



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

#hashInteger

Override of @Object#hash@



121
122
123
# File 'lib/ruber/world/project_list.rb', line 121

def hash
  @projects.hash
end

#sizeInteger



85
86
87
# File 'lib/ruber/world/project_list.rb', line 85

def size
  @projects.size
end