Class: Schedsolver2::ClassCounter
- Inherits:
-
Object
- Object
- Schedsolver2::ClassCounter
- Defined in:
- lib/schedsolver2/ClassCounter.rb
Instance Attribute Summary collapse
-
#counts ⇒ Object
readonly
Returns the value of attribute counts.
Instance Method Summary collapse
- #[](arg1, arg2) ⇒ Object
- #[]=(arg1, arg2, val) ⇒ Object
- #by_day(day) ⇒ Object
- #by_et_id(id) ⇒ Object
-
#initialize(et_ids) ⇒ ClassCounter
constructor
A new instance of ClassCounter.
- #to_s ⇒ Object
Constructor Details
#initialize(et_ids) ⇒ ClassCounter
Returns a new instance of ClassCounter.
6 7 8 9 10 11 12 13 14 |
# File 'lib/schedsolver2/ClassCounter.rb', line 6 def initialize et_ids @counts = {} [:mon, :tue, :wed, :thu, :fri].each do |day| @counts[day] = Hash.new et_ids.each do |et_id| @counts[day][et_id] = 0 end end end |
Instance Attribute Details
#counts ⇒ Object (readonly)
Returns the value of attribute counts.
4 5 6 |
# File 'lib/schedsolver2/ClassCounter.rb', line 4 def counts @counts end |
Instance Method Details
#[](arg1, arg2) ⇒ Object
16 17 18 |
# File 'lib/schedsolver2/ClassCounter.rb', line 16 def [](arg1, arg2) @counts[arg1][arg2] end |
#[]=(arg1, arg2, val) ⇒ Object
20 21 22 |
# File 'lib/schedsolver2/ClassCounter.rb', line 20 def []=(arg1, arg2, val) @counts[arg1][arg2] = val end |
#by_day(day) ⇒ Object
32 33 34 35 36 |
# File 'lib/schedsolver2/ClassCounter.rb', line 32 def by_day day count = 0 @counts[day].each_value { |v| count += v } return count end |
#by_et_id(id) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/schedsolver2/ClassCounter.rb', line 24 def by_et_id id count = 0 @counts.each_key do |day| count += @counts[day][id] end return count end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/schedsolver2/ClassCounter.rb', line 38 def to_s @counts.to_s end |