Class: PxTimetable
- Inherits:
-
Object
- Object
- PxTimetable
- Defined in:
- lib/px_timetable.rb
Instance Method Summary collapse
- #days ⇒ Object
-
#initialize(filename_txt) ⇒ PxTimetable
constructor
A new instance of PxTimetable.
- #next(t = Time.now) ⇒ Object
- #now(t = Time.now) ⇒ Object
- #to_s ⇒ Object
- #today(d = Date.today) ⇒ Object
- #tomorrow(d = Date.today+1) ⇒ Object
Constructor Details
#initialize(filename_txt) ⇒ PxTimetable
Returns a new instance of PxTimetable.
13 14 15 16 |
# File 'lib/px_timetable.rb', line 13 def initialize(filename_txt) @px = Polyrex.new @px.import filename_txt end |
Instance Method Details
#days ⇒ Object
18 19 20 |
# File 'lib/px_timetable.rb', line 18 def days() @px.records end |
#next(t = Time.now) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/px_timetable.rb', line 22 def next(t=Time.now) classes_today = self.today() return unless classes_today classes = classes_today.records session = classes.detect do |klass| ChronicBetween.new(klass.times).within? t end i = classes.index(session) if i and i < classes.length then classes[i+1] end end |
#now(t = Time.now) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/px_timetable.rb', line 41 def now(t=Time.now) classes_today = self.today() return unless classes_today classes = classes_today.records classes.detect do |klass| ChronicBetween.new(klass.times).within? t end end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/px_timetable.rb', line 53 def to_s() @px.to_s(header: false) end |
#today(d = Date.today) ⇒ Object
57 58 59 60 61 |
# File 'lib/px_timetable.rb', line 57 def today(d=Date.today) @px.find_by_day_title Date::DAYNAMES[d.wday] end |
#tomorrow(d = Date.today+1) ⇒ Object
63 64 65 66 67 |
# File 'lib/px_timetable.rb', line 63 def tomorrow(d=Date.today+1) @px.find_by_day_title Date::DAYNAMES[(d).wday] end |