Class: Foscam::Schedule::Week
- Inherits:
-
Object
- Object
- Foscam::Schedule::Week
- Defined in:
- lib/foscam/schedule/week.rb
Instance Attribute Summary collapse
-
#days ⇒ Object
attr_accessor :sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday.
Instance Method Summary collapse
-
#busy_at?(time) ⇒ FalseClass, TrueClass
Determine if the the schedule is true at the given date time.
-
#initialize(params = {}) ⇒ Week
constructor
A new instance of Week.
-
#to_hash ⇒ Hash
Convert the Week to a nested hash with the day of the week as the key and and time as the second key.
-
#to_param ⇒ Hash
Convert the Week to the form of the input hash.
Constructor Details
#initialize(params = {}) ⇒ Week
Returns a new instance of Week.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/foscam/schedule/week.rb', line 30 def initialize(params = {}) self.days = {} [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday].each do |day| abbrev = day.to_s[0..2] bit0 = params.has_key?("#{abbrev}_0".to_sym) ? params["#{abbrev}_0".to_sym] : 0 bit1 = params.has_key?("#{abbrev}_1".to_sym) ? params["#{abbrev}_1".to_sym] : 0 bit2 = params.has_key?("#{abbrev}_2".to_sym) ? params["#{abbrev}_2".to_sym] : 0 self.days.merge!( day => Day.new(bit0,bit1,bit2)) end end |
Instance Attribute Details
#days ⇒ Object
attr_accessor :sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday
5 6 7 |
# File 'lib/foscam/schedule/week.rb', line 5 def days @days end |
Instance Method Details
#busy_at?(time) ⇒ FalseClass, TrueClass
Determine if the the schedule is true at the given date time
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/foscam/schedule/week.rb', line 45 def busy_at?(time) time = time.to_time if time.is_a?(DateTime) if time.sunday? days[:sunday].busy_at?(time) elsif time.monday? days[:monday].busy_at?(time) elsif time.tuesday? days[:tuesday].busy_at?(time) elsif time.wednesday? days[:wednesday].busy_at?(time) elsif time.thursday? days[:thursday].busy_at?(time) elsif time.friday? days[:friday].busy_at?(time) elsif time.saturday? days[:saturday].busy_at?(time) end end |
#to_hash ⇒ Hash
Convert the Week to a nested hash with the day of the week as the key and and time as the second key
67 68 69 70 71 72 73 |
# File 'lib/foscam/schedule/week.rb', line 67 def to_hash h = {} self.days.each do |name, day| h.merge!(name => day.to_hash) end h end |
#to_param ⇒ Hash
Convert the Week to the form of the input hash
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/foscam/schedule/week.rb', line 77 def to_param params = {} self.days.each do |name, day| abbrev = name.to_s[0..2] day.bits.each_index do |i| params.merge!("#{abbrev}_#{i}".to_sym => day.bits[i].bit) end end params end |