class Timetable
Constants
- URL_CANDIDATES
- Workout
Attributes
club[R]
Public Class Methods
new(club)
click to toggle source
# File lib/va_timetable/timetable.rb, line 12 def initialize(club) @club = club.to_s end
Public Instance Methods
classes()
click to toggle source
# File lib/va_timetable/timetable.rb, line 16 def classes @workouts ||= fetch_classes end
Private Instance Methods
compose_time(date, hour, min)
click to toggle source
# File lib/va_timetable/timetable.rb, line 50 def compose_time(date, hour, min) current = Time.now year = current.year month = current.month day = current.day if date < day month += 1 if month > 12 year += 1 month = 1 end end Time.new(year, month, date, hour, min, 0) end
fetch_classes()
click to toggle source
# File lib/va_timetable/timetable.rb, line 22 def fetch_classes workouts = [] page = Nokogiri::HTML(first_responsive_url) page.css('div[id^=timetable_]').each do |t| date = t.css('.date')[0].text.to_i t.css('table .classname').each do |c| name = c.text cells = c.parent.parent.css('td') start = compose_time(date, *cells[0].text.split(':')) finish = compose_time(date, *cells[1].text.split(':')) booking = cells[5].text != '-' workouts << Workout.new(club.capitalize, name, start, finish, booking) end end workouts end
first_responsive_url()
click to toggle source
# File lib/va_timetable/timetable.rb, line 39 def first_responsive_url url_list = URL_CANDIDATES.map {|c| c % {club: club}} url_list.detect do |url| begin break open(url) rescue false end end end