rsssf 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ module Rsssf
5
+
6
+ class PageReport
7
+
8
+ attr_reader :title
9
+
10
+ def initialize( stats, opts )
11
+ @stats = stats
12
+ @opts = opts
13
+
14
+ @title = opts[:title] || 'Your Title Here'
15
+ end
16
+
17
+ def save( path )
18
+ ### save report as README.md in repo
19
+ File.open( path, 'w' ) do |f|
20
+ f.write build_summary
21
+ end
22
+ end
23
+
24
+ def build_summary
25
+
26
+ stats = @stats.sort do |l,r|
27
+ r.year <=> l.year
28
+ end
29
+
30
+ header =<<EOS
31
+
32
+ # #{title}
33
+
34
+ football.db RSSSF Archive Data Summary for #{title}
35
+
36
+ _Last Update: #{Time.now}_
37
+
38
+ EOS
39
+
40
+ txt = ''
41
+ txt << header
42
+
43
+ txt << "| Season | File | Authors | Last Updated | Lines (Chars) | Sections |\n"
44
+ txt << "| :----- | :----- | :------- | :----------- | ------------: | :------- |\n"
45
+
46
+ stats.each do |stat|
47
+ txt << "| #{stat.season} "
48
+ txt << "| [#{stat.basename}.txt](#{stat.basename}.txt) "
49
+ txt << "| #{stat.authors} "
50
+ txt << "| #{stat.last_updated} "
51
+ txt << "| #{stat.line_count} (#{stat.char_count}) "
52
+ txt << "| #{stat.sections.join(', ')} "
53
+ txt << "|\n"
54
+ end
55
+
56
+ txt << "\n\n"
57
+ txt
58
+ end # method build_summary
59
+
60
+ end ## class PageReport
61
+ end ## module Rsssf
62
+
63
+ ## add (shortcut) alias
64
+ RsssfPageReport = Rsssf::PageReport
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+
3
+ module Rsssf
4
+
5
+ class ScheduleReport
6
+
7
+ attr_reader :title
8
+
9
+ def initialize( stats, opts )
10
+ @stats = stats
11
+ @opts = opts
12
+
13
+ @title = opts[:title] || 'Your Title Here'
14
+ end
15
+
16
+ def save( path )
17
+ ### save report as README.md in repo
18
+ File.open( path, 'w' ) do |f|
19
+ f.write build_summary
20
+ end
21
+ end
22
+
23
+ def build_summary
24
+ ## sort start by season (latest first) than by name (e.g. 1-bundesliga, cup, etc.)
25
+ stats = @stats.sort do |l,r|
26
+ v = r.season <=> l.season
27
+ v = l.filename <=> r.filename if v == 0 ## same season
28
+ v
29
+ end
30
+
31
+ header =<<EOS
32
+
33
+ # #{title}
34
+
35
+ football.db RSSSF (Rec.Sport.Soccer Statistics Foundation) Archive Data for
36
+ #{title}
37
+
38
+ _Last Update: #{Time.now}_
39
+
40
+ EOS
41
+
42
+
43
+ footer =<<EOS
44
+
45
+ ## Questions? Comments?
46
+
47
+ Send them along to the
48
+ [Open Sports & Friends Forum](http://groups.google.com/group/opensport).
49
+ Thanks!
50
+ EOS
51
+
52
+
53
+ txt = ''
54
+ txt << header
55
+
56
+ txt << "| Season | League, Cup | Rounds |\n"
57
+ txt << "| :----- | :---------- | -----: |\n"
58
+
59
+ stats.each do |stat|
60
+ txt << "| #{stat.season} "
61
+ txt << "| [#{stat.filename}](#{stat.path}/#{stat.filename}) "
62
+ txt << "| #{stat.rounds} "
63
+ txt << "|\n"
64
+ end
65
+
66
+ txt << "\n\n"
67
+
68
+ txt << footer
69
+ txt
70
+ end # method build_summary
71
+
72
+ end ## class ScheduleReport
73
+ end ## module Rsssf
74
+
75
+ ## add (shortcut) alias
76
+ RsssfScheduleReport = Rsssf::ScheduleReport
77
+
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ module Rsssf
4
+
5
+ class Schedule
6
+
7
+ def self.from_string( txt )
8
+ self.new( txt )
9
+ end
10
+
11
+ attr_accessor :rounds # track no of rounds
12
+
13
+ def initialize( txt )
14
+ @txt = txt
15
+
16
+ @rounds = nil # undefined
17
+ end
18
+
19
+
20
+ def save( path )
21
+ File.open( path, 'w' ) do |f|
22
+ f.write @txt
23
+ end
24
+ end
25
+
26
+ end ## class Schedule
27
+ end ## module Rsssf
28
+
29
+ ## add (shortcut) alias
30
+ RsssfSchedule = Rsssf::Schedule
31
+
@@ -0,0 +1,75 @@
1
+ # encoding: utf-8
2
+
3
+ module Rsssf
4
+ module Utils
5
+
6
+ def year_from_file( path )
7
+ extname = File.extname( path )
8
+ basename = File.basename( path, extname ) ## e.g. duit92.txt or duit92.html => duit92
9
+ year_from_name( basename )
10
+ end
11
+
12
+
13
+ def year_from_name( name )
14
+ if name =~ /(\d+)/
15
+ digits = $1.to_s
16
+ num = digits.to_i
17
+
18
+ if digits.size == 4 ## e.g. 1980 or 2011 etc.
19
+ num
20
+ elsif digits.size == 2 ## e.g. 00, 20 or 99 etc.
21
+ if num <= 16 ## assume 20xx for now from 00..16
22
+ 2000+num
23
+ else ## assume 19xx for now
24
+ 1900+num
25
+ end
26
+ else
27
+ fail( "no year found in name #{name}; expected two or four digits")
28
+ end
29
+ else
30
+ fail( "no year found in name #{name}")
31
+ end
32
+ end # method year_from_name
33
+
34
+
35
+ def year_to_season( year )
36
+
37
+ ## todo: require four digit years? why? why not??
38
+
39
+ ## e.g. 64 => 1963-64
40
+ ## 2011 => 2010-11 etc.
41
+
42
+ if year <= 16 ## assume 20xx for now from 00..16
43
+ year += 2000
44
+ elsif year <= 99
45
+ year += 1900
46
+ else
47
+ # use as is; assume four digit year
48
+ end
49
+
50
+ year_prev = year-1
51
+
52
+ "%4d-%02d" % [year_prev, year%100] ## e.g. return 1974-75
53
+ end
54
+
55
+
56
+ def archive_dir_for_year( year )
57
+ season = year_to_season( year )
58
+ if year <= 2010 # e.g. season 2009-10
59
+ ## use archive folder (w/ 1980s etc)
60
+ ## get decade folder
61
+ decade = year-1
62
+ decade -= decade % 10 ## turn 1987 into 1980 etc
63
+ "archive/#{decade}s/#{season}"
64
+ else
65
+ season
66
+ end
67
+ end
68
+
69
+
70
+ end # module Utils
71
+ end # module Rsssf
72
+
73
+ ## add (shortcut) alias
74
+ RsssfUtils = Rsssf::Utils
75
+
@@ -4,8 +4,8 @@
4
4
  module Rsssf
5
5
 
6
6
  MAJOR = 0
7
- MINOR = 0
8
- PATCH = 1
7
+ MINOR = 1
8
+ PATCH = 0
9
9
  VERSION = [MAJOR,MINOR,PATCH].join('.')
10
10
 
11
11
  def self.version
@@ -0,0 +1,12 @@
1
+
2
+ ## $:.unshift(File.dirname(__FILE__))
3
+
4
+ ## minitest setup
5
+
6
+ require 'minitest/autorun'
7
+
8
+
9
+ ## our own code
10
+
11
+ require 'rsssf'
12
+
@@ -0,0 +1,83 @@
1
+ # encoding: utf-8
2
+
3
+ require 'helper'
4
+
5
+ class TestUtils < MiniTest::Test
6
+
7
+ include RsssfUtils ## e.g. year_from_name etc.
8
+
9
+ def test_year
10
+
11
+ ###########
12
+ ## year_from_name
13
+ ## note: num <= 16 - assume 20xx for now from 00..16
14
+ ## - else 19xx
15
+ assert_equal 2000, year_from_name( 'duit00' )
16
+ assert_equal 2016, year_from_name( 'duit16' )
17
+
18
+ assert_equal 1999, year_from_name( 'duit99' )
19
+
20
+ assert_equal 2001, year_from_name( 'duit2001' )
21
+
22
+ assert_equal 1964, year_from_name( 'duit64' )
23
+ assert_equal 1965, year_from_name( 'duit1965' )
24
+ assert_equal 2011, year_from_name( 'duit2011' )
25
+
26
+
27
+ ####
28
+ # year_from_file
29
+
30
+ assert_equal 2000, year_from_file( 'duit00.txt' )
31
+ assert_equal 2000, year_from_file( 'duit00.html' )
32
+ assert_equal 2000, year_from_file( './duit00.txt' )
33
+ assert_equal 2000, year_from_file( 'xxx/1998/xxx/duit00.txt' )
34
+
35
+ assert_equal 2016, year_from_file( 'duit16.txt' )
36
+ assert_equal 2016, year_from_file( 'duit16.html' )
37
+
38
+ assert_equal 2001, year_from_file( 'duit2001.txt' )
39
+ assert_equal 2001, year_from_file( 'duit2001.html' )
40
+ assert_equal 2001, year_from_file( 'xx/1990s/1997/xxx/duit2001.txt' )
41
+
42
+ assert_equal 2000, year_from_file( 'de-deutschland/tables/duit00.txt' )
43
+ assert_equal 1964, year_from_file( 'de-deutschland/62/tables/duit64.txt' ) # check w/ numbers in path
44
+ assert_equal 1999, year_from_file( 'de-deutschland/1977/tables/duit99.txt' ) # check w/ numbers in path
45
+ assert_equal 1965, year_from_file( 'de-deutschland/tables/duit1965.txt' )
46
+ assert_equal 2011, year_from_file( 'de-deutschland/tables/duit2011.txt' )
47
+
48
+ assert_equal 2000, year_from_file( 'de-deutschland/tables/duit00.html' )
49
+ assert_equal 1964, year_from_file( 'de-deutschland/62/tables/duit64.html' ) # check w/ numbers in path
50
+ assert_equal 1999, year_from_file( 'de-deutschland/1977/tables/duit99.html' ) # check w/ numbers in path
51
+ assert_equal 1965, year_from_file( 'de-deutschland/tables/duit1965.html' )
52
+ assert_equal 2011, year_from_file( 'de-deutschland/tables/duit2011.html' )
53
+
54
+
55
+ #####
56
+ ## year_to_season
57
+
58
+ assert_equal '1998-99', year_to_season( 1999 )
59
+ assert_equal '1999-00', year_to_season( 2000 ) ## todo: use 1999-2000 - why? why not??
60
+ assert_equal '2000-01', year_to_season( 2001 )
61
+ assert_equal '2014-15', year_to_season( 2015 )
62
+
63
+ assert_equal '1999-00', year_to_season( 0 )
64
+ assert_equal '1963-64', year_to_season( 64 )
65
+ assert_equal '1998-99', year_to_season( 99 )
66
+ assert_equal '1964-65', year_to_season( 1965 )
67
+ assert_equal '2010-11', year_to_season( 2011 )
68
+
69
+
70
+ #######
71
+ ## archive_dir_for_year
72
+ ## note: year <= 2010 use season 2009-10
73
+
74
+ assert_equal 'archive/1990s/1998-99', archive_dir_for_year( 1999 )
75
+ assert_equal 'archive/2000s/2000-01', archive_dir_for_year( 2001 )
76
+ assert_equal '2014-15', archive_dir_for_year( 2015 )
77
+
78
+
79
+ assert true ## everything ok if get here
80
+ end
81
+
82
+ end # class TestUtils
83
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsssf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
@@ -90,12 +90,24 @@ extra_rdoc_files:
90
90
  - Manifest.txt
91
91
  - README.md
92
92
  files:
93
+ - ".gemtest"
93
94
  - HISTORY.md
94
95
  - Manifest.txt
95
96
  - README.md
96
97
  - Rakefile
97
98
  - lib/rsssf.rb
99
+ - lib/rsssf/fetch.rb
100
+ - lib/rsssf/html2txt.rb
101
+ - lib/rsssf/page.rb
102
+ - lib/rsssf/patch.rb
103
+ - lib/rsssf/repo.rb
104
+ - lib/rsssf/reports/page.rb
105
+ - lib/rsssf/reports/schedule.rb
106
+ - lib/rsssf/schedule.rb
107
+ - lib/rsssf/utils.rb
98
108
  - lib/rsssf/version.rb
109
+ - test/helper.rb
110
+ - test/test_utils.rb
99
111
  homepage: https://github.com/sportdb/rsssf
100
112
  licenses:
101
113
  - Public Domain