sportdb-readers 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46454d349dc5a94aea1f56de0b900244df2607bd
4
- data.tar.gz: b51de78a375e0a63838e845512c794b2abfdee62
3
+ metadata.gz: 7a80a58bb3ddb33bdba8040a926546b548ba5436
4
+ data.tar.gz: 608847551d5a437ab847e91aa79ea82626d010cf
5
5
  SHA512:
6
- metadata.gz: 6fde9823e1e243e8f3be5824b1ff8846e7ad2f531551cc49a9e17165927b96305320d497a7385f45d9e56362c3d30fcc271f9d88b288a12df2ef4aab7ebba74b
7
- data.tar.gz: 06b38e7dbce194808a843fd1b735002c31e5cd574a4c2b2b1c9bbe8d7b29c1c96c2c6690306b9514159f3d797d291d0dd09f7bd11405abae8e19f00be06b2d76
6
+ metadata.gz: fc388f76b6b1ec3ca85ea4bea73ace80f13af88ef05eb7601b04176aeca742c35e828ee1fa6d5ca674d6a71789007f5b785185e8b241db4ee14e89218ff624ca
7
+ data.tar.gz: aa7ed9979898a56656f16d9093687b3d4c7a1590add76d4d5a866966e5bd2169e545fabcbc0fdc11f7c79b2ac8677667c9ca52d7a57e0dfb23963becbaa2d71f
@@ -22,20 +22,22 @@ require 'sportdb/readers/match_linter'
22
22
  ## add convenience shortcut helpers
23
23
  module SportDb
24
24
 
25
- def self.read_conf( path, sync: true ) ## note: sync is dry run (for lint checking)
26
- sync ? ConfReaderV2.read( path ) : ConfLinter.read( path )
25
+ def self.read_conf( path, sync: true, season: nil ) ## note: sync is dry run (for lint checking)
26
+ sync ? ConfReaderV2.read( path, season: season )
27
+ : ConfLinter.read( path, season: season )
27
28
  end
28
29
 
29
30
  ### todo: add alias read_matches - why? why not?
30
- def self.read_match( path, sync: true ) ## note: sync is dry run (for lint checking)
31
- sync ? MatchReaderV2.read( path ) : MatchLinter.read( path )
31
+ def self.read_match( path, sync: true, season: nil ) ## note: sync is dry run (for lint checking)
32
+ sync ? MatchReaderV2.read( path, season: season )
33
+ : MatchLinter.read( path, season: season )
32
34
  end
33
35
 
34
- def self.lint_conf( path ) read_conf( path, sync: false ); end
35
- def self.lint_match( path ) read_match( path, sync: false ); end
36
+ def self.lint_conf( path, season: nil ) read_conf( path, sync: false, season: season ); end
37
+ def self.lint_match( path, season: nil ) read_match( path, sync: false, season: season ); end
36
38
 
37
39
 
38
- def self.read( path, sync: true )
40
+ def self.read( path, sync: true, season: nil )
39
41
  ## step 1: collect all datafiles
40
42
  if File.directory?( path ) ## if directory read complete package
41
43
  datafiles_conf = Datafile.find_conf( path )
@@ -43,19 +45,19 @@ module SportDb
43
45
  /[a-z0-9_-]+\.txt$ ## txt e.g /1-premierleague.txt
44
46
  }x )
45
47
 
46
- datafiles_conf.each { |datafile| read_conf( datafile, sync: sync ) }
47
- datafiles.each { |datafile| read_match( datafile, sync: sync ) }
48
+ datafiles_conf.each { |datafile| read_conf( datafile, sync: sync, season: season ) }
49
+ datafiles.each { |datafile| read_match( datafile, sync: sync, season: season ) }
48
50
  else
49
51
  ## check if datafile matches conf(iguration) naming (e.g. .conf.txt)
50
52
  if Datafile.match_conf( path )
51
- read_conf( path, sync: sync )
53
+ read_conf( path, sync: sync, season: season )
52
54
  else ## assume "regular" match datafile
53
- read_match( path, sync: sync )
55
+ read_match( path, sync: sync, season: season )
54
56
  end
55
57
  end
56
58
  end # method read
57
59
 
58
- def self.lint( path ) read( path, sync: false ); end
60
+ def self.lint( path, season: nil ) read( path, sync: false, season: season ); end
59
61
 
60
62
  end # module SportDb
61
63
 
@@ -8,16 +8,16 @@ class ConfLinter
8
8
  def self.config() Import.config; end ## shortcut convenience helper
9
9
 
10
10
 
11
- def self.read( path ) ## use - rename to read_file or from_file etc. - why? why not?
11
+ def self.read( path, season: nil ) ## use - rename to read_file or from_file etc. - why? why not?
12
12
  puts "reading conf(iguration) datafile >#{path}<..."
13
13
  txt = File.open( path, 'r:utf-8' ).read
14
- parse( txt )
14
+ parse( txt, season: season )
15
15
  end
16
16
 
17
- def self.parse( txt )
18
- recs = LeagueOutlineReader.parse( txt )
17
+ def self.parse( txt, season: nil )
18
+ recs = LeagueOutlineReader.parse( txt, season: season )
19
19
 
20
- if recs.empty?
20
+ if recs.empty? ## todo: check for season filter - why? why not?
21
21
  puts " ** !!! WARN !!! - no league headings found"
22
22
  else
23
23
  puts " found #{recs.size} league (+season+stage) headings"
@@ -59,7 +59,7 @@ class ConfLinter
59
59
  name = line
60
60
  end
61
61
 
62
- clubs << find_club( name, league.country )
62
+ clubs << config.clubs.find_by!( name: name, country: league.country )
63
63
  end
64
64
 
65
65
  rec[:clubs] = clubs
@@ -69,35 +69,5 @@ class ConfLinter
69
69
  recs
70
70
  end # method read
71
71
 
72
-
73
- ### todo/fix: move to clubs for sharing!!!!!!! use clubs.find_by!( name:, country: )
74
- def self.find_club( name, country ) ## todo/fix: add international or league flag?
75
- club = nil
76
- m = config.clubs.match_by( name: name, country: country )
77
-
78
- if m.nil?
79
- ## (re)try with second country - quick hacks for known leagues
80
- ## todo/fix: add league flag to activate!!!
81
- m = config.clubs.match_by( name: name, country: config.countries['wal']) if country.key == 'eng'
82
- m = config.clubs.match_by( name: name, country: config.countries['nir']) if country.key == 'ie'
83
- m = config.clubs.match_by( name: name, country: config.countries['mc']) if country.key == 'fr'
84
- m = config.clubs.match_by( name: name, country: config.countries['li']) if country.key == 'ch'
85
- m = config.clubs.match_by( name: name, country: config.countries['ca']) if country.key == 'us'
86
- end
87
-
88
- if m.nil?
89
- puts "** !!! ERROR !!! no match for club >#{name}<"
90
- exit 1
91
- elsif m.size > 1
92
- puts "** !!! ERROR !!! too many matches (#{m.size}) for club >#{name}<:"
93
- pp m
94
- exit 1
95
- else # bingo; match - assume size == 1
96
- club = m[0]
97
- end
98
-
99
- club
100
- end
101
-
102
72
  end # class ConfLinter
103
73
  end # module SportDb
@@ -8,13 +8,13 @@ class ConfReaderV2 ## todo/check: rename to EventsReaderV2 (use plural?) why?
8
8
  def self.config() Import.config; end ## shortcut convenience helper
9
9
 
10
10
 
11
- def self.read( path ) ## use - rename to read_file or from_file etc. - why? why not?
11
+ def self.read( path, season: nil ) ## use - rename to read_file or from_file etc. - why? why not?
12
12
  txt = File.open( path, 'r:utf-8' ).read
13
- parse( txt )
13
+ parse( txt, season: season )
14
14
  end
15
15
 
16
- def self.parse( txt )
17
- recs = LeagueOutlineReader.parse( txt )
16
+ def self.parse( txt, season: nil )
17
+ recs = LeagueOutlineReader.parse( txt, season: season )
18
18
  pp recs
19
19
 
20
20
  ## pass 2 - check & map; replace inline (string with record)
@@ -47,7 +47,7 @@ class ConfReaderV2 ## todo/check: rename to EventsReaderV2 (use plural?) why?
47
47
  name = line
48
48
  end
49
49
 
50
- clubs << find_club( name, league.country )
50
+ clubs << config.clubs.find_by( name: name, country: league.country )
51
51
  end
52
52
 
53
53
  rec[:clubs] = clubs
@@ -84,35 +84,5 @@ class ConfReaderV2 ## todo/check: rename to EventsReaderV2 (use plural?) why?
84
84
  recs
85
85
  end # method read
86
86
 
87
-
88
-
89
- def self.find_club( name, country ) ## todo/fix: add international or league flag?
90
- club = nil
91
- m = config.clubs.match_by( name: name, country: country )
92
-
93
- if m.nil?
94
- ## (re)try with second country - quick hacks for known leagues
95
- ## todo/fix: add league flag to activate!!!
96
- m = config.clubs.match_by( name: name, country: config.countries['wal']) if country.key == 'eng'
97
- m = config.clubs.match_by( name: name, country: config.countries['nir']) if country.key == 'ie'
98
- m = config.clubs.match_by( name: name, country: config.countries['mc']) if country.key == 'fr'
99
- m = config.clubs.match_by( name: name, country: config.countries['li']) if country.key == 'ch'
100
- m = config.clubs.match_by( name: name, country: config.countries['ca']) if country.key == 'us'
101
- end
102
-
103
- if m.nil?
104
- puts "** !!! ERROR !!! no match for club >#{name}<"
105
- exit 1
106
- elsif m.size > 1
107
- puts "** !!! ERROR !!! too many matches (#{m.size}) for club >#{name}<:"
108
- pp m
109
- exit 1
110
- else # bingo; match - assume size == 1
111
- club = m[0]
112
- end
113
-
114
- club
115
- end
116
-
117
87
  end # class ConfReaderV2
118
88
  end # module SportDb
@@ -21,7 +21,8 @@ class LeagueOutlineReader
21
21
  )
22
22
  $/x
23
23
 
24
- def self.parse( txt )
24
+
25
+ def self.parse( txt, season: nil )
25
26
  recs=[]
26
27
  OutlineReader.parse( txt ).each do |node|
27
28
  if node[0] == :h1
@@ -56,7 +57,22 @@ class LeagueOutlineReader
56
57
  end
57
58
  end
58
59
 
59
- ## pass 2 - check & map; replace inline (string with data record)
60
+
61
+ ## pass 2 - filter seasons if filter present
62
+ if season
63
+ filtered_recs = []
64
+ filter = normalize_seasons( season )
65
+ recs.each do |rec|
66
+ if filter.include?( SeasonUtils.key( rec[:season] ))
67
+ filtered_recs << rec
68
+ else
69
+ puts " skipping season >#{rec[:season]}< NOT matched by filter"
70
+ end
71
+ end
72
+ recs = filtered_recs
73
+ end
74
+
75
+ ## pass 3 - check & map; replace inline (string with data record)
60
76
  recs.each do |rec|
61
77
  league = find_league( rec[:league] )
62
78
  rec[:league] = league
@@ -68,6 +84,18 @@ class LeagueOutlineReader
68
84
  end # method parse
69
85
 
70
86
 
87
+
88
+ def self.normalize_seasons( season_or_seasons ) ## todo/check: add alias norm_seasons - why? why not?
89
+ seasons = if season_or_seasons.is_a? String ## wrap in array
90
+ [season_or_seasons]
91
+ else ## assume it's an array already
92
+ season_or_seasons
93
+ end
94
+
95
+ seasons.map { |season| SeasonUtils.key( season ) }
96
+ end
97
+
98
+
71
99
  def self.split_league( str ) ## todo/check: rename to parse_league(s) - why? why not?
72
100
  ## split into league / stage / ... e.g.
73
101
  ## => Österr. Bundesliga 2018/19, Regular Season
@@ -94,6 +122,7 @@ class LeagueOutlineReader
94
122
  end
95
123
 
96
124
 
125
+ ### fix/todo: move find_league to sportdb-league index use find_by! and find_by !!!!
97
126
  def self.find_league( name )
98
127
  league = nil
99
128
  m = config.leagues.match( name )
@@ -4,16 +4,16 @@ module SportDb
4
4
 
5
5
  class MatchLinter
6
6
 
7
- def self.read( path ) ## use - rename to read_file or from_file etc. - why? why not?
7
+ def self.read( path, season: nil ) ## use - rename to read_file or from_file etc. - why? why not?
8
8
  puts "reading match datafile >#{path}<..."
9
9
  txt = File.open( path, 'r:utf-8' ).read
10
- parse( txt )
10
+ parse( txt, season: season )
11
11
  end
12
12
 
13
- def self.parse( txt )
14
- recs = LeagueOutlineReader.parse( txt )
13
+ def self.parse( txt, season: nil )
14
+ recs = LeagueOutlineReader.parse( txt, season: season )
15
15
 
16
- if recs.empty?
16
+ if recs.empty? ## todo - check for filter - why? why not?
17
17
  puts " ** !!! WARN !!! - no league headings found"
18
18
  else
19
19
  puts " found #{recs.size} league (+season+stage) headings"
@@ -4,13 +4,13 @@ module SportDb
4
4
 
5
5
  class MatchReaderV2 ## todo/check: rename to MatchReaderV2 (use plural?) why? why not?
6
6
 
7
- def self.read( path ) ## use - rename to read_file or from_file etc. - why? why not?
7
+ def self.read( path, season: nil ) ## use - rename to read_file or from_file etc. - why? why not?
8
8
  txt = File.open( path, 'r:utf-8' ).read
9
- parse( txt )
9
+ parse( txt, season: season )
10
10
  end
11
11
 
12
- def self.parse( txt )
13
- recs = LeagueOutlineReader.parse( txt )
12
+ def self.parse( txt, season: nil )
13
+ recs = LeagueOutlineReader.parse( txt, season: season )
14
14
  pp recs
15
15
 
16
16
  recs.each do |rec|
@@ -6,7 +6,7 @@ module Readers
6
6
 
7
7
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
8
8
  MINOR = 2
9
- PATCH = 2
9
+ PATCH = 3
10
10
  VERSION = [MAJOR,MINOR,PATCH].join('.')
11
11
 
12
12
  def self.version
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.2.2
4
+ version: 0.2.3
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-11-13 00:00:00.000000000 Z
11
+ date: 2019-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-config