Class: SerialScheduler::TimeTable

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/serial_scheduler/time_table.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTimeTable

Returns a new instance of TimeTable.



8
9
10
# File 'lib/serial_scheduler/time_table.rb', line 8

def initialize
  @timing = {}
end

Instance Attribute Details

#timingObject

Returns the value of attribute timing.



6
7
8
# File 'lib/serial_scheduler/time_table.rb', line 6

def timing
  @timing
end

Class Method Details

.jobs_for(*time_keys) ⇒ Object



13
14
15
16
17
# File 'lib/serial_scheduler/time_table.rb', line 13

def jobs_for(*time_keys)
  [time_keys].flatten.collect do |time_key|
    timing[time_key]
  end.flatten.compact
end

.method_missing(meth, *args, &blk) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/serial_scheduler/time_table.rb', line 19

def method_missing(meth, *args, &blk)
  if self.instance.respond_to?(meth)
    self.instance.send(meth, *args, &blk)
  else
    super
  end
end

Instance Method Details

#add(hash_with_timing_info) ⇒ Object



28
29
30
31
32
33
# File 'lib/serial_scheduler/time_table.rb', line 28

def add(hash_with_timing_info)
  hash_with_timing_info.each do |timing_key, calls|
    self.timing[timing_key] ||= []
    self.timing[timing_key] += [calls].flatten
  end
end

#clearObject



35
36
37
# File 'lib/serial_scheduler/time_table.rb', line 35

def clear
  self.timing = {}
end

#daily_timingObject



43
44
45
# File 'lib/serial_scheduler/time_table.rb', line 43

def daily_timing
  timing.reject { |time_key, call| time_key.size != 5 }
end


47
48
49
50
# File 'lib/serial_scheduler/time_table.rb', line 47

def print
  print_daily_timing
  print_weekly_timing
end


52
53
54
55
56
57
58
59
60
# File 'lib/serial_scheduler/time_table.rb', line 52

def print_daily_timing
  puts
  puts "daily timing"
  puts "-"*15
  daily_timing.keys.sort.each do |time_key|
    scheduled_calls = timing[time_key]
    puts "#{time_key} |\t#{scheduled_calls.join("\n\t")}"
  end
end


62
63
64
65
66
67
68
69
70
# File 'lib/serial_scheduler/time_table.rb', line 62

def print_weekly_timing
  puts
  puts "weekly timing"
  puts "-"*15
  weekly_timing.keys.sort.each do |time_key|
    scheduled_calls = timing[time_key]
    puts "#{Date.human_wday(time_key.first.to_i)}, #{time_key[2..-1]} |\t#{scheduled_calls.join("\n\t")}"
  end
end

#weekly_timingObject



39
40
41
# File 'lib/serial_scheduler/time_table.rb', line 39

def weekly_timing
  timing.reject { |time_key, call| time_key.size != 7 }
end