Class: SerialScheduler::TimeTable
- Inherits:
-
Object
- Object
- SerialScheduler::TimeTable
- Includes:
- Singleton
- Defined in:
- lib/serial_scheduler/time_table.rb
Instance Attribute Summary collapse
-
#timing ⇒ Object
readonly
Returns the value of attribute timing.
Class Method Summary collapse
Instance Method Summary collapse
- #add(hash_with_timing_info) ⇒ Object
- #clear ⇒ Object
- #daily_timing ⇒ Object
-
#initialize ⇒ TimeTable
constructor
A new instance of TimeTable.
- #print ⇒ Object
- #print_daily_timing ⇒ Object
- #print_weekly_timing ⇒ Object
- #weekly_timing ⇒ Object
Constructor Details
#initialize ⇒ TimeTable
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
#timing ⇒ Object
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 |
#clear ⇒ Object
35 36 37 |
# File 'lib/serial_scheduler/time_table.rb', line 35 def clear self.timing = {} end |
#daily_timing ⇒ Object
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 |
#print ⇒ Object
47 48 49 50 |
# File 'lib/serial_scheduler/time_table.rb', line 47 def print print_daily_timing print_weekly_timing end |
#print_daily_timing ⇒ Object
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 |
#print_weekly_timing ⇒ Object
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_timing ⇒ Object
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 |