Class: Mo2tex::DaySchedule
- Inherits:
-
Object
- Object
- Mo2tex::DaySchedule
- Includes:
- DateTimeHelper
- Defined in:
- lib/mo2tex/day_schedule.rb
Instance Attribute Summary collapse
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#dirty ⇒ Object
Returns the value of attribute dirty.
-
#dtend ⇒ Object
readonly
Returns the value of attribute dtend.
-
#dtstart ⇒ Object
readonly
Returns the value of attribute dtstart.
-
#lbdtend ⇒ Object
readonly
Returns the value of attribute lbdtend.
-
#lbdtstart ⇒ Object
readonly
Returns the value of attribute lbdtstart.
-
#lbtend ⇒ Object
readonly
Returns the value of attribute lbtend.
-
#lbtstart ⇒ Object
readonly
Returns the value of attribute lbtstart.
-
#lnumber ⇒ Object
readonly
Returns the value of attribute lnumber.
-
#slots ⇒ Object
readonly
Returns the value of attribute slots.
-
#tend ⇒ Object
readonly
Returns the value of attribute tend.
-
#tstart ⇒ Object
readonly
Returns the value of attribute tstart.
-
#wday ⇒ Object
readonly
Returns the value of attribute wday.
Instance Method Summary collapse
- #<<(event) ⇒ Object
- #calculate_free_slots ⇒ Object
- #dirty? ⇒ Boolean
- #each_slot(&block) ⇒ Object
-
#initialize(day, ln, wd, conf) ⇒ DaySchedule
constructor
A new instance of DaySchedule.
- #this_slot?(ev) ⇒ Boolean
Methods included from DateTimeHelper
Constructor Details
#initialize(day, ln, wd, conf) ⇒ DaySchedule
Returns a new instance of DaySchedule.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/mo2tex/day_schedule.rb', line 76 def initialize(day, ln, wd, conf) raise DayIsNotDateTime, "#{day}" unless day.is_a?(DateTime) raise ArgumentError, "#{conf}" unless conf.is_a?(Hash) @day = day # should be a DateTime with the d/m/y @wday = wd @tstart = conf[self.wday]['orario'][0] @tend = conf[self.wday]['orario'][1] @lbtstart = conf[self.wday]['pausa'][0] @lbtend = conf[self.wday]['pausa'][1] @dtstart = datetime_create(self.day, self.tstart) @dtend = datetime_create(self.day, self.tend) @lbdtstart = datetime_create(self.day, self.lbtstart) @lbdtend = datetime_create(self.day, self.lbtend) @lnumber = ln @slots = [] self.dirty = false calculate_free_slots end |
Instance Attribute Details
#day ⇒ Object (readonly)
Returns the value of attribute day.
72 73 74 |
# File 'lib/mo2tex/day_schedule.rb', line 72 def day @day end |
#dirty ⇒ Object
Returns the value of attribute dirty.
74 75 76 |
# File 'lib/mo2tex/day_schedule.rb', line 74 def dirty @dirty end |
#dtend ⇒ Object (readonly)
Returns the value of attribute dtend.
72 73 74 |
# File 'lib/mo2tex/day_schedule.rb', line 72 def dtend @dtend end |
#dtstart ⇒ Object (readonly)
Returns the value of attribute dtstart.
72 73 74 |
# File 'lib/mo2tex/day_schedule.rb', line 72 def dtstart @dtstart end |
#lbdtend ⇒ Object (readonly)
Returns the value of attribute lbdtend.
72 73 74 |
# File 'lib/mo2tex/day_schedule.rb', line 72 def lbdtend @lbdtend end |
#lbdtstart ⇒ Object (readonly)
Returns the value of attribute lbdtstart.
72 73 74 |
# File 'lib/mo2tex/day_schedule.rb', line 72 def lbdtstart @lbdtstart end |
#lbtend ⇒ Object (readonly)
Returns the value of attribute lbtend.
72 73 74 |
# File 'lib/mo2tex/day_schedule.rb', line 72 def lbtend @lbtend end |
#lbtstart ⇒ Object (readonly)
Returns the value of attribute lbtstart.
72 73 74 |
# File 'lib/mo2tex/day_schedule.rb', line 72 def lbtstart @lbtstart end |
#lnumber ⇒ Object (readonly)
Returns the value of attribute lnumber.
72 73 74 |
# File 'lib/mo2tex/day_schedule.rb', line 72 def lnumber @lnumber end |
#slots ⇒ Object (readonly)
Returns the value of attribute slots.
73 74 75 |
# File 'lib/mo2tex/day_schedule.rb', line 73 def slots @slots end |
#tend ⇒ Object (readonly)
Returns the value of attribute tend.
72 73 74 |
# File 'lib/mo2tex/day_schedule.rb', line 72 def tend @tend end |
#tstart ⇒ Object (readonly)
Returns the value of attribute tstart.
72 73 74 |
# File 'lib/mo2tex/day_schedule.rb', line 72 def tstart @tstart end |
#wday ⇒ Object (readonly)
Returns the value of attribute wday.
72 73 74 |
# File 'lib/mo2tex/day_schedule.rb', line 72 def wday @wday end |
Instance Method Details
#<<(event) ⇒ Object
99 100 101 102 103 |
# File 'lib/mo2tex/day_schedule.rb', line 99 def <<(event) return unless this_slot?(event) self.slots << event self.dirty = true end |
#calculate_free_slots ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/mo2tex/day_schedule.rb', line 105 def calculate_free_slots if self.slots.empty? self.slots << LunchBreak.new(self.day, self.lbdtstart, self.lbdtend) else bsorted = self.slots.sort { |a, b| a.dtstart <=> b.dtstart } tstart = self.dtstart bsorted.each do |ev| self.slots << FreeSlot.new(self.day, tstart, ev.dtstart) if (ev.dtstart.round_to_ymdhm > tstart.round_to_ymdhm) tstart = ev.dtend end self.slots << FreeSlot.new(self.day, tstart, self.dtend) if (tstart.round_to_ymdhm < self.dtend.round_to_ymdhm) end self.slots.sort! { |a, b| a.dtstart <=> b.dtstart } self.dirty = false return self.slots end |
#dirty? ⇒ Boolean
95 96 97 |
# File 'lib/mo2tex/day_schedule.rb', line 95 def dirty? return self.dirty end |
#each_slot(&block) ⇒ Object
123 124 125 126 127 |
# File 'lib/mo2tex/day_schedule.rb', line 123 def each_slot(&block) self.calculate_free_slots if self.dirty? self.slots.sort! { |a, b| a.dtstart <=> b.dtstart } self.slots.each { |slot| yield(slot) } if block_given? end |
#this_slot?(ev) ⇒ Boolean
129 130 131 |
# File 'lib/mo2tex/day_schedule.rb', line 129 def this_slot?(ev) return (ev.dtstart.day_only >= self.dtstart.day_only && ev.dtend.day_only <= self.dtend.day_only) end |