Class: Schedsolver2::Teacher

Inherits:
Object
  • Object
show all
Defined in:
lib/schedsolver2/teacher.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, id = nil) ⇒ Teacher

Returns a new instance of Teacher.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/schedsolver2/teacher.rb', line 14

def initialize name, id=nil
  @name = name.to_s
  @work_days = [:mon, :tue, :wed, :thu, :fri]
  unless id == nil then
    raise ArgumentError, "Dupicate id" unless Teacher.uniq_id?(id)
    @id = id
  else
    @id = Teacher.generate_id
  end
  @@ids << @id
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/schedsolver2/teacher.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/schedsolver2/teacher.rb', line 3

def name
  @name
end

#work_daysObject

Returns the value of attribute work_days.



3
4
5
# File 'lib/schedsolver2/teacher.rb', line 3

def work_days
  @work_days
end

Class Method Details

.generate_idObject



30
31
32
33
34
# File 'lib/schedsolver2/teacher.rb', line 30

def self.generate_id
  id = 0
  until Teacher.uniq_id?(id); id += 1; end
  return id
end

.idsObject



6
7
8
# File 'lib/schedsolver2/teacher.rb', line 6

def Teacher::ids
  @@ids
end

.reset_idsObject



10
11
12
# File 'lib/schedsolver2/teacher.rb', line 10

def Teacher::reset_ids
  @@ids = []
end

.uniq_id?(id) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
# File 'lib/schedsolver2/teacher.rb', line 36

def self.uniq_id? id
  if @@ids.include?(id) 
    return false 
  else 
    return true 
  end
end

Instance Method Details

#to_sObject



26
27
28
# File 'lib/schedsolver2/teacher.rb', line 26

def to_s
  @name.to_s + "(#{self.id})"
end

#working?(day) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/schedsolver2/teacher.rb', line 44

def working? day
  @work_days.include? day 
end