Module: ScheduleScraper
- Defined in:
- lib/schedule-scraper.rb,
lib/schedule-scraper/event.rb,
lib/schedule-scraper/config.rb,
lib/schedule-scraper/version.rb,
lib/schedule-scraper/schedule.rb,
lib/schedule-scraper/ezleagues/event.rb,
lib/schedule-scraper/pointstreak/event.rb,
lib/schedule-scraper/ezleagues/schedule.rb,
lib/schedule-scraper/pointstreak/schedule.rb
Defined Under Namespace
Modules: EZLeagues, Event, Pointstreak, Schedule
Classes: Config, InvalidURL, UnsupportedSchedule
Constant Summary
collapse
- VERSION =
"0.6.1"
Class Method Summary
collapse
Class Method Details
.fetch(type_or_url, url = nil) ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/schedule-scraper.rb', line 16
def self.fetch(type_or_url, url = nil)
type = url ? type_or_url : type_from_url(type_or_url)
url = url || type_or_url
raise UnsupportedSchedule unless supported_schedules.include?(type.to_sym)
raise InvalidURL unless valid_url?(url)
type_class(type).fetch(url)
end
|
.supported_schedules ⇒ Object
36
37
38
|
# File 'lib/schedule-scraper.rb', line 36
def self.supported_schedules
Config.types.keys
end
|
.type_class(type) ⇒ Object
32
33
34
|
# File 'lib/schedule-scraper.rb', line 32
def self.type_class(type)
Config.types[type]
end
|
.type_from_url(url) ⇒ Object
26
27
28
29
30
|
# File 'lib/schedule-scraper.rb', line 26
def self.type_from_url(url)
Config.types.each do |key, klass|
return key if /#{key}/ =~ url
end
end
|
.valid_url?(url) ⇒ Boolean
40
41
42
43
44
45
|
# File 'lib/schedule-scraper.rb', line 40
def self.valid_url?(url)
uri = URI.parse(url)
uri.kind_of?(URI::HTTP)
rescue URI::InvalidURIError
false
end
|