Class: Schedsolver2::ClassCounter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#countsObject (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_sObject



38
39
40
# File 'lib/schedsolver2/ClassCounter.rb', line 38

def to_s
  @counts.to_s
end