Module: Rsssf

Defined in:
lib/rsssf/page.rb,
lib/rsssf/repo.rb,
lib/rsssf/utils.rb,
lib/rsssf/convert.rb,
lib/rsssf/version.rb,
lib/rsssf/download.rb,
lib/rsssf/schedule.rb,
lib/rsssf/reports/page.rb,
lib/rsssf/reports/schedule.rb

Defined Under Namespace

Modules: Utils Classes: Page, PageConverter, PageReport, PageStat, Repo, Schedule, ScheduleReport, ScheduleStat

Constant Summary collapse

MAJOR =
0
MINOR =
2
PATCH =
0
VERSION =
[MAJOR,MINOR,PATCH].join('.')
TABLE =

map country codes to table pages

add options about (char) encoding ??? - why? why not?
{
  'eng' => ['tablese/eng{year}',   { encoding: 'Windows-1252' } ],
  'es'  => ['tabless/span{year}',  { encoding: 'Windows-1252' } ],
  'de'  => ['tablesd/duit{year}', { encoding: 'Windows-1252' } ],
  'at'  => ['tableso/oost{year}', { encoding: 'Windows-1252' }  ],
  'br'  => [
            ->(season) {
                ## note: special slug/case for year/season 2000
                ##  see rsssf.org/tablesb/brazchamp.html
               if season == Season('2000') 
                 'tablesb/braz-joao{year}'  ## use braz-joao00 - why? why not?
               else
                 'tablesb/braz{year}'
               end
            },  { encoding: 'Windows-1252' } ],
}
BASE_URL =
"https://rsssf.org"

Class Method Summary collapse

Class Method Details



13
14
15
# File 'lib/rsssf/version.rb', line 13

def self.banner
  "rsssf/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
end

.download_page(url, encoding:) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rsssf/download.rb', line 73

def self.download_page( url, encoding: )
 
  ## note: assume plain 7-bit ascii for now
  ##  -- assume rsssf uses ISO_8859_15 (updated version of ISO_8859_1) 
  ###-- does NOT use utf-8 character encoding!!!
  response = Webget.page( url, encoding: encoding )  ## fetch (and cache) html page (via HTTP GET)

  ## note: exit on get / fetch error - do NOT continue for now - why? why not?
  exit 1   if response.status.nok?    ## e.g.  HTTP status code != 200


  puts "html:"
  html =  response.text( encoding: encoding )    
  pp html[0..400]
  html
end

.download_table(code, season:) ⇒ Object



66
67
68
69
70
# File 'lib/rsssf/download.rb', line 66

def self.download_table( code, season: )
   url, encoding = table_url_and_encoding( code, season: season )

   download_page( url, encoding: encoding )
end

.rootObject



17
18
19
# File 'lib/rsssf/version.rb', line 17

def self.root
   File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
end

.table_url(code, season:) ⇒ Object



36
37
38
39
# File 'lib/rsssf/download.rb', line 36

def self.table_url( code, season: )
   url, _ = table_url_and_encoding( code, season: season )
   url 
end

.table_url_and_encoding(code, season:) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rsssf/download.rb', line 41

def self.table_url_and_encoding( code, season: )
   season = Season( season )

   table = TABLE[ code.downcase ]
   tmpl     = table[0]
   tmpl     = tmpl.call( season )  if tmpl.is_a?(Proc)  ## check for proc
 
   opts     = table[1] || {}
   encoding = opts[:encoding]  || 'UTF-8'


   slug =  if season.end_year < 2010   ## cut off all digits (only keep last two)s
               ##  convert end_year to string with leading zero
               '%02d' % (season.end_year % 100)  ## e.g. 00 / 01 / 99 / 98 / 11 / etc.
            else
              '%4d' % season.end_year
            end

   tmpl = tmpl.sub( '{year}', slug )
   url = "#{BASE_URL}/#{tmpl}.html"

   [url, encoding]
end

.versionObject



9
10
11
# File 'lib/rsssf/version.rb', line 9

def self.version
  VERSION
end