sportdb-readers 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +0 -2
- data/lib/sportdb/readers.rb +0 -5
- data/lib/sportdb/readers/package.rb +5 -3
- data/lib/sportdb/readers/version.rb +1 -1
- metadata +2 -4
- data/lib/sportdb/readers/datafile.rb +0 -173
- data/test/test_package.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46dc2a6de0074a2c9a5f007503f99d34030e4c80
|
4
|
+
data.tar.gz: e5cd5ae577346962dcb69361a11504fbe7540a22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54a9a0865d2d8af5a405f0cb9a64eea7bc2e7f6ea7cae870dded60dd51f38301c4f40b494a5833330f248b4b556daf17e81984ba8243cef3f170dd838565ef92
|
7
|
+
data.tar.gz: ee0035b74ada7e5d829f6778421e0c7be57728ac78aaa167edcebe44f93280310df9b09c7906580c9dca3a8b9d8360f9baf50959bbe0469a5bd3560187ee5837
|
data/Manifest.txt
CHANGED
@@ -6,7 +6,6 @@ lib/sportdb/readers.rb
|
|
6
6
|
lib/sportdb/readers/conf_linter.rb
|
7
7
|
lib/sportdb/readers/conf_parser_auto.rb
|
8
8
|
lib/sportdb/readers/conf_reader.rb
|
9
|
-
lib/sportdb/readers/datafile.rb
|
10
9
|
lib/sportdb/readers/league_outline_reader.rb
|
11
10
|
lib/sportdb/readers/match_linter.rb
|
12
11
|
lib/sportdb/readers/match_parser.rb
|
@@ -16,6 +15,5 @@ lib/sportdb/readers/version.rb
|
|
16
15
|
test/helper.rb
|
17
16
|
test/test_conf_parser_auto.rb
|
18
17
|
test/test_match_parser.rb
|
19
|
-
test/test_package.rb
|
20
18
|
test/test_read.rb
|
21
19
|
test/test_reader.rb
|
data/lib/sportdb/readers.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'zip' ## todo/check: if zip is alreay included in a required module
|
4
|
-
## - move into sportdb-formats and add datafile!!!
|
5
|
-
|
6
|
-
|
7
3
|
|
8
4
|
require 'sportdb/config'
|
9
5
|
require 'sportdb/models' ## add sql database support
|
@@ -20,7 +16,6 @@ require 'sportdb/readers/conf_linter'
|
|
20
16
|
require 'sportdb/readers/match_parser'
|
21
17
|
require 'sportdb/readers/match_reader'
|
22
18
|
require 'sportdb/readers/match_linter'
|
23
|
-
require 'sportdb/readers/datafile'
|
24
19
|
require 'sportdb/readers/package'
|
25
20
|
|
26
21
|
|
@@ -4,12 +4,14 @@ module SportDb
|
|
4
4
|
|
5
5
|
CONF_RE = Datafile::CONF_RE
|
6
6
|
CLUB_PROPS_RE = Datafile::CLUB_PROPS_RE
|
7
|
-
LEAGUES_RE = Datafile::
|
8
|
-
CLUBS_RE = Datafile::
|
7
|
+
LEAGUES_RE = Datafile::LEAGUES_RE
|
8
|
+
CLUBS_RE = Datafile::CLUBS_RE
|
9
9
|
|
10
10
|
|
11
11
|
## note: if pattern includes directory add here (otherwise move to more "generic" datafile) - why? why not?
|
12
|
-
MATCH_RE = %r{
|
12
|
+
MATCH_RE = %r{ /(?: \d{4}-\d{2} ## season folder e.g. /2019-20
|
13
|
+
| \d{4} ## season year-only folder e.g. /2019
|
14
|
+
)
|
13
15
|
/[a-z0-9_-]+\.txt$ ## txt e.g /1-premierleague.txt
|
14
16
|
}x
|
15
17
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb-readers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sportdb-config
|
@@ -98,7 +98,6 @@ files:
|
|
98
98
|
- lib/sportdb/readers/conf_linter.rb
|
99
99
|
- lib/sportdb/readers/conf_parser_auto.rb
|
100
100
|
- lib/sportdb/readers/conf_reader.rb
|
101
|
-
- lib/sportdb/readers/datafile.rb
|
102
101
|
- lib/sportdb/readers/league_outline_reader.rb
|
103
102
|
- lib/sportdb/readers/match_linter.rb
|
104
103
|
- lib/sportdb/readers/match_parser.rb
|
@@ -108,7 +107,6 @@ files:
|
|
108
107
|
- test/helper.rb
|
109
108
|
- test/test_conf_parser_auto.rb
|
110
109
|
- test/test_match_parser.rb
|
111
|
-
- test/test_package.rb
|
112
110
|
- test/test_read.rb
|
113
111
|
- test/test_reader.rb
|
114
112
|
homepage: https://github.com/sportdb/sport.db
|
@@ -1,173 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Datafile
|
4
|
-
|
5
|
-
|
6
|
-
## todo/fix: move regex patterns upstream to datafile in sportdb-formats!!
|
7
|
-
|
8
|
-
CONF_RE = %r{ /\.conf\.txt$
|
9
|
-
}x
|
10
|
-
|
11
|
-
|
12
|
-
CLUB_PROPS_RE = %r{ (?:^|/) # beginning (^) or beginning of path (/)
|
13
|
-
(?:[a-z]{1,4}\.)? # optional country code/key e.g. eng.clubs.props.txt
|
14
|
-
clubs\.props\.txt$
|
15
|
-
}x
|
16
|
-
def self.match_club_props( path, pattern: CLUB_PROPS_RE ) pattern.match( path ); end
|
17
|
-
|
18
|
-
|
19
|
-
ZIP_RE = %r{ \.zip$
|
20
|
-
}x
|
21
|
-
def self.match_zip( path, pattern: ZIP_RE ) pattern.match( path ); end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
## exclude pattern
|
26
|
-
## for now exclude all files in directories starting with a dot (e.g. .git/ or .github/ or .build/ etc.)
|
27
|
-
## todo/check: rename to EXCLUDE_DOT_DIRS_RE - why? why not?
|
28
|
-
EXCLUDE_RE = %r{ (?:^|/) # beginning (^) or beginning of path (/)
|
29
|
-
\.[a-zA-Z0-9_-]+ ## (almost) any name BUT must start with dot e.g. .git, .build, etc.
|
30
|
-
/
|
31
|
-
}x
|
32
|
-
def self.match_exclude( path, pattern: EXCLUDE_RE ) pattern.match( path ); end
|
33
|
-
|
34
|
-
|
35
|
-
class Package; end ## use a shared base class for DirPackage, ZipPackage, etc.
|
36
|
-
|
37
|
-
class DirPackage < Package ## todo/check: find a better name e.g. UnzippedPackage, FilesystemPackage, etc. - why? why not?
|
38
|
-
class Entry
|
39
|
-
def initialize( pack, path )
|
40
|
-
@pack = pack ## parent package
|
41
|
-
@path = path
|
42
|
-
## todo/fix!!!!: calculate @name (cut-off pack.path!!!)
|
43
|
-
@name = path
|
44
|
-
end
|
45
|
-
def name() @name; end
|
46
|
-
def read() File.open( @path, 'r:utf-8' ).read; end
|
47
|
-
end # class DirPackage::Entry
|
48
|
-
|
49
|
-
|
50
|
-
attr_reader :name, :path
|
51
|
-
|
52
|
-
def initialize( path )
|
53
|
-
## todo/fix: expand_path ?! - why? why not? if you pass in ./ basename will be . and NOT directory name, for example!!!
|
54
|
-
@path = path ## rename to root_path or base_path or somehting - why? why not?
|
55
|
-
|
56
|
-
basename = File.basename( path ) ## note: ALWAYS keeps "extension"-like name if present (e.g. ./austria.zip => austria.zip)
|
57
|
-
@name = basename
|
58
|
-
end
|
59
|
-
|
60
|
-
def each( pattern:, extension: 'txt' ) ## todo/check: rename to glob or something - why? why not?
|
61
|
-
## use just .* for extension or remove and check if File.file? and skip File.directory? - why? why not?
|
62
|
-
## note: incl. files starting with dot (.)) as candidates (normally excluded with just *)
|
63
|
-
Dir.glob( "#{@path}/**/{*,.*}.#{extension}" ).each do |path|
|
64
|
-
## todo/fix: (auto) skip and check for directories
|
65
|
-
if EXCLUDE_RE.match( path )
|
66
|
-
## note: skip dot dirs (e.g. .build/, .git/, etc.)
|
67
|
-
elsif pattern.match( path )
|
68
|
-
yield( Entry.new( self, path ))
|
69
|
-
else
|
70
|
-
## puts " skipping >#{path}<"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def find( name )
|
76
|
-
Entry.new( self, "#{@path}/#{name}" )
|
77
|
-
end
|
78
|
-
end # class DirPackage
|
79
|
-
|
80
|
-
|
81
|
-
## helper wrapper for datafiles in zips
|
82
|
-
class ZipPackage < Package
|
83
|
-
class Entry
|
84
|
-
def initialize( pack, entry )
|
85
|
-
@pack = pack
|
86
|
-
@entry = entry
|
87
|
-
end
|
88
|
-
|
89
|
-
def name() @entry.name; end
|
90
|
-
def read
|
91
|
-
txt = @entry.get_input_stream.read
|
92
|
-
## puts "** encoding: #{txt.encoding}" #=> encoding: ASCII-8BIT
|
93
|
-
txt = txt.force_encoding( Encoding::UTF_8 )
|
94
|
-
txt
|
95
|
-
end
|
96
|
-
end # class ZipPackage::Entry
|
97
|
-
|
98
|
-
attr_reader :name, :path
|
99
|
-
|
100
|
-
def initialize( path )
|
101
|
-
@path = path
|
102
|
-
|
103
|
-
extname = File.extname( path ) ## todo/check: double check if extension is .zip - why? why not?
|
104
|
-
basename = File.basename( path, extname )
|
105
|
-
@name = basename
|
106
|
-
end
|
107
|
-
|
108
|
-
def each( pattern: )
|
109
|
-
Zip::File.open( @path ) do |zipfile|
|
110
|
-
zipfile.each do |entry|
|
111
|
-
if entry.directory?
|
112
|
-
next ## skip
|
113
|
-
elsif entry.file?
|
114
|
-
if EXCLUDE_RE.match( entry.name )
|
115
|
-
## note: skip dot dirs (e.g. .build/, .git/, etc.)
|
116
|
-
elsif pattern.match( entry.name )
|
117
|
-
yield( Entry.new( self, entry ) ) # wrap entry in uniform access interface / api
|
118
|
-
else
|
119
|
-
## puts " skipping >#{entry.name}<"
|
120
|
-
end
|
121
|
-
else
|
122
|
-
puts "** !!! ERROR !!! #{entry.name} is unknown zip file type in >#{@path}<, sorry"
|
123
|
-
exit 1
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
def find( name )
|
130
|
-
entries = match_entry( name )
|
131
|
-
if entries.empty?
|
132
|
-
puts "** !!! ERROR !!! zip entry >#{name}< not found in >#{@path}<; sorry"
|
133
|
-
exit 1
|
134
|
-
elsif entries.size > 1
|
135
|
-
puts "** !!! ERROR !!! ambigious zip entry >#{name}<; found #{entries.size} entries in >#{@path}<:"
|
136
|
-
pp entries
|
137
|
-
exit 1
|
138
|
-
else
|
139
|
-
Entry.new( self, entries[0] ) # wrap entry in uniform access interface / api
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
private
|
144
|
-
def match_entry( name )
|
145
|
-
## todo/fix: use Zip::File.glob or find_entry or something better/faster? why? why not?
|
146
|
-
|
147
|
-
pattern = %r{ #{Regexp.escape( name )} ## match string if ends with name
|
148
|
-
$
|
149
|
-
}x
|
150
|
-
|
151
|
-
entries = []
|
152
|
-
Zip::File.open( @path ) do |zipfile|
|
153
|
-
zipfile.each do |entry|
|
154
|
-
if entry.directory?
|
155
|
-
next ## skip
|
156
|
-
elsif entry.file?
|
157
|
-
if EXCLUDE_RE.match( entry.name )
|
158
|
-
## note: skip dot dirs (e.g. .build/, .git/, etc.)
|
159
|
-
elsif pattern.match( entry.name )
|
160
|
-
entries << entry
|
161
|
-
else
|
162
|
-
## no match; skip too
|
163
|
-
end
|
164
|
-
else
|
165
|
-
puts "** !!! ERROR !!! #{entry.name} is unknown zip file type in >#{@path}<, sorry"
|
166
|
-
exit 1
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
entries
|
171
|
-
end
|
172
|
-
end # class ZipPackage
|
173
|
-
end # module Datafile
|
data/test/test_package.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_package.rb
|
6
|
-
|
7
|
-
|
8
|
-
require 'helper'
|
9
|
-
|
10
|
-
|
11
|
-
class TestPackage < MiniTest::Test
|
12
|
-
|
13
|
-
def test_exclude
|
14
|
-
assert Datafile.match_exclude( '.build/' )
|
15
|
-
assert Datafile.match_exclude( '.git/' )
|
16
|
-
|
17
|
-
assert Datafile.match_exclude( '/.build/' )
|
18
|
-
assert Datafile.match_exclude( '/.git/' )
|
19
|
-
|
20
|
-
assert Datafile.match_exclude( '.build/leagues.txt' )
|
21
|
-
assert Datafile.match_exclude( '.git/leagues.txt' )
|
22
|
-
|
23
|
-
assert Datafile.match_exclude( '/.build/leagues.txt' )
|
24
|
-
assert Datafile.match_exclude( '/.git/leagues.txt' )
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_read
|
28
|
-
[Datafile::DirPackage.new( '../../../openfootball/england' ),
|
29
|
-
Datafile::ZipPackage.new( 'tmp/england-master.zip' )].each do |eng|
|
30
|
-
assert eng.find( '2015-16/.conf.txt' ).read.start_with?( '= English Premier League 2015/16' )
|
31
|
-
assert eng.find( '2017-18/.conf.txt' ).read.start_with?( '= English Premier League 2017/18' )
|
32
|
-
assert eng.find( '2015-16/1-premierleague-i.txt' ).read.start_with?( '= English Premier League 2015/16' )
|
33
|
-
end
|
34
|
-
|
35
|
-
[Datafile::DirPackage.new( '../../../openfootball/austria' ),
|
36
|
-
Datafile::ZipPackage.new( 'tmp/austria-master.zip' )].each do |at|
|
37
|
-
assert at.find( '2018-19/.conf.txt' ).read.start_with?( '= Österr. Bundesliga 2018/19' )
|
38
|
-
end
|
39
|
-
end # method test_read
|
40
|
-
|
41
|
-
end # class TestPackage
|