class DTVTournaments::Tournament
Attributes
city[RW]
date[RW]
datetime[RW]
kind[RW]
notes[RW]
number[RW]
page[RW]
street[RW]
time[RW]
zip[RW]
Public Class Methods
deserialize(a)
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 103 def self.deserialize(a) t = Tournament.new(a[0].to_i, false) t.notes = a[1] t.timeFromString(a[2]) t.street = a[3] t.zip = a[4] t.city = a[5] t.kind = a[6] t end
new(number, shouldCall=true)
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 7 def initialize number, shouldCall=true @number = number call if shouldCall end
Public Instance Methods
call()
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 12 def call get_result_page extract_results save_to_cache end
extract_date()
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 66 def extract_date page.search(".kategorie").text.scan(/^\d{1,2}.\d{1,2}.\d{4}/).first end
extract_kind()
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 43 def extract_kind @kind = DTVTournaments::convertToText(page.search(".markierung .turnier")) end
extract_location()
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 51 def extract_location @zip = @page.search('.ort strong').text.gsub!(/\D|\s/, "").to_i @city = @page.search('.ort strong').text.gsub!(/\d|\s/, "") @street = @page.search('.ort').to_html.split('<br>')[1].strip end
extract_notes()
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 47 def extract_notes @notes = page.search(".turniere tr .bemerkung").to_a.collect(&:text).reject{|x| x.nil? || x.empty?}.join("\n") end
extract_results()
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 36 def extract_results extract_kind extract_notes extract_location parse_time(extract_date, extract_time) end
extract_time()
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 57 def extract_time if page.search(".markierung .uhrzeit").first.text.empty? # This tournament is a big one get_time_from_big_tournament(page.search(".turniere tr")) else page.search(".markierung .uhrzeit").text.scan(/\d{1,2}:\d{2}/).first end end
get_first_time_until(times, index)
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 82 def get_first_time_until times, index for i in (0..index).to_a.reverse return times[i] unless times[i].nil? || times[i].empty? end end
get_index_of_marked_tournament(tournaments)
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 76 def get_index_of_marked_tournament tournaments tournaments.each_with_index do |single_tournament, index| return index if single_tournament.attributes().has_key?('class') end end
get_result_page()
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 22 def get_result_page mechanize = Mechanize.new { |agent| agent.read_timeout = 3 } mechanize.get(DTVTournaments::FETCHINGURL) search_form = mechanize.page.forms.last search_form.nr = @number search_form.submit @page = mechanize.page end
get_time_from_big_tournament(tournaments)
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 88 def get_time_from_big_tournament tournaments times = tournaments.map do |single_tournament| next_time = DTVTournaments::get_subelement_if_available(single_tournament, ".uhrzeit") if next_time.nil? || next_time.empty? nil else next_time.scan(/\d{1,2}:\d{2}/).first end end index = get_index_of_marked_tournament tournaments get_first_time_until(times, index) end
parse_time(date, time)
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 70 def parse_time date, time @datetime = DateTime.parse("#{date} #{time}") @date = Date.parse(date) @time = Time.parse("#{date} #{time}") end
save_to_cache()
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 18 def save_to_cache DTVTournaments.get_cache.set(self) end
serialize()
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 120 def serialize "#{@number}|#{@notes}|#{@datetime.to_s}|#{@street}|#{@zip}|#{@city}|#{@kind}" end
timeFromString(datetime)
click to toggle source
# File lib/dtv_tournaments/tournament.rb, line 114 def timeFromString(datetime) self.datetime = DateTime.parse(datetime) self.time = Time.parse(datetime) - Time.zone_offset(Time.parse(datetime).zone) self.date = Date.parse(datetime) end