Class: Schedsolver2::Teacher
- Inherits:
-
Object
- Object
- Schedsolver2::Teacher
- Defined in:
- lib/schedsolver2/teacher.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#work_days ⇒ Object
Returns the value of attribute work_days.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, id = nil) ⇒ Teacher
constructor
A new instance of Teacher.
- #to_s ⇒ Object
- #working?(day) ⇒ Boolean
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
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/schedsolver2/teacher.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/schedsolver2/teacher.rb', line 3 def name @name end |
#work_days ⇒ Object
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_id ⇒ Object
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 |
.ids ⇒ Object
6 7 8 |
# File 'lib/schedsolver2/teacher.rb', line 6 def Teacher::ids @@ids end |
.reset_ids ⇒ Object
10 11 12 |
# File 'lib/schedsolver2/teacher.rb', line 10 def Teacher::reset_ids @@ids = [] end |
.uniq_id?(id) ⇒ 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_s ⇒ Object
26 27 28 |
# File 'lib/schedsolver2/teacher.rb', line 26 def to_s @name.to_s + "(#{self.id})" end |
#working?(day) ⇒ Boolean
44 45 46 |
# File 'lib/schedsolver2/teacher.rb', line 44 def working? day @work_days.include? day end |