Class: PxTimetable

Inherits:
Object
  • Object
show all
Defined in:
lib/px_timetable.rb

Instance Method Summary collapse

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

#next(t = Time.now) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/px_timetable.rb', line 18

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



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/px_timetable.rb', line 37

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_sObject



49
50
51
# File 'lib/px_timetable.rb', line 49

def to_s()
  @px.to_s(header: false)
end

#today(d = Date.today) ⇒ Object



53
54
55
56
57
# File 'lib/px_timetable.rb', line 53

def today(d=Date.today)
  
  @px.find_by_day_title Date::DAYNAMES[d.wday]

end

#tomorrow(d = Date.today+1) ⇒ Object



59
60
61
62
63
# File 'lib/px_timetable.rb', line 59

def tomorrow(d=Date.today+1)
  
  @px.find_by_day_title Date::DAYNAMES[(d).wday]

end