sportdb-formats 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9dfb4b397ab313f54b1a8c6943d7707777737af9
4
- data.tar.gz: d1d8413b546a02575adce273ba2fe95db93893f3
3
+ metadata.gz: 6f298701705843da74864b5b202122696b0c315f
4
+ data.tar.gz: 776194a60adc13e2397ff8d63ec640cb519f6022
5
5
  SHA512:
6
- metadata.gz: 65403f493c15c5ca2113416570567bf0d5f7b68655cd85462ae609480119bfab417f5e318cbf7b5e97d02b09022845ab886ca675392b5f1358610c7c00eb5d4f
7
- data.tar.gz: c941e27074b31c830c3cf9ac3e8c5581852aec1ee8490b732fc56f8afc69862a0ae2f91f1a28d061da3e55f1f9d235c140c438ff198fa8dcd53af192e863b95e
6
+ metadata.gz: 8d77c3ecceedd959a21d129eebb5c456aaa203c885813a97520920bd8273859723f3c74091bfe1ecfcc6e5f678b33db9c4a70fd8afcfb6c48e11e4420ed307c3
7
+ data.tar.gz: f36282877eea8646e123a0ba9b5bde25e55dc428a50c69bfc3884c9e2b437fc3e95f635a85b44fa95a47013d3027bc21ff1c8de7bf9ba35b0aae4cbdaf3ec3ed
data/Manifest.txt CHANGED
@@ -3,8 +3,10 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  lib/sportdb/formats.rb
6
+ lib/sportdb/formats/datafile.rb
6
7
  lib/sportdb/formats/outline_reader.rb
7
8
  lib/sportdb/formats/version.rb
8
9
  test/helper.rb
9
10
  test/test_csv_reader.rb
11
+ test/test_datafile.rb
10
12
  test/test_outline_reader.rb
@@ -22,6 +22,7 @@ end
22
22
  # our own code
23
23
  require 'sportdb/formats/version' # let version always go first
24
24
  require 'sportdb/formats/outline_reader'
25
+ require 'sportdb/formats/datafile'
25
26
 
26
27
 
27
28
 
@@ -0,0 +1,68 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ module Datafile # note: keep Datafile in its own top-level module/namespace for now - why? why not?
5
+
6
+ def self.find( path, pattern )
7
+ datafiles = []
8
+
9
+ ## check all txt files (incl. starting with dot (.)) as candidates
10
+ candidates = Dir.glob( "#{path}/**/{*,.*}.txt" )
11
+ pp candidates
12
+ candidates.each do |candidate|
13
+ datafiles << candidate if pattern.match( candidate )
14
+ end
15
+
16
+ pp datafiles
17
+ datafiles
18
+ end
19
+
20
+
21
+
22
+ CLUBS_REGEX = %r{ (?:^|/) # beginning (^) or beginning of path (/)
23
+ (?:[a-z]{1,4}\.)? # optional country code/key e.g. eng.clubs.txt
24
+ clubs\.txt$
25
+ }x
26
+
27
+ CLUBS_WIKI_REGEX = %r{ (?:^|/) # beginning (^) or beginning of path (/)
28
+ (?:[a-z]{1,4}\.)? # optional country code/key e.g. eng.clubs.wiki.txt
29
+ clubs\.wiki\.txt$
30
+ }x
31
+
32
+ def self.find_clubs( path, pattern: CLUBS_REGEX ) find( path, pattern ); end
33
+ def self.find_clubs_wiki( path, pattern: CLUBS_WIKI_REGEX ) find( path, pattern ); end
34
+
35
+
36
+ LEAGUES_REGEX = %r{ (?:^|/) # beginning (^) or beginning of path (/)
37
+ leagues\.txt$
38
+ }x
39
+
40
+ def self.find_leagues( path, pattern: LEAGUES_REGEX ) find( path, pattern ); end
41
+
42
+
43
+ CONF_REGEX = %r{ (?:^|/) # beginning (^) or beginning of path (/)
44
+ \.conf\.txt$
45
+ }x
46
+
47
+ def self.find_conf( path, pattern: CONF_REGEX ) find( path, pattern ); end
48
+
49
+
50
+
51
+
52
+ def self.write_bundle( path, datafiles:, header: nil )
53
+ File.open( path, 'w:utf-8') do |fout|
54
+ if header
55
+ fout.write( header )
56
+ fout.write( "\n\n" )
57
+ end
58
+ datafiles.each do |datafile|
59
+ File.open( datafile, 'r:utf-8') do |fin|
60
+ text = fin.read
61
+ text = text.sub( /__END__.*/m, '' ) ## note: add/allow support for __END__; use m-multiline flag
62
+ fout.write( text )
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ end # module Datafile
@@ -5,8 +5,8 @@ module SportDb
5
5
  module Formats
6
6
 
7
7
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
8
- MINOR = 0
9
- PATCH = 1
8
+ MINOR = 1
9
+ PATCH = 0
10
10
  VERSION = [MAJOR,MINOR,PATCH].join('.')
11
11
 
12
12
  def self.version
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_datafile.rb
6
+
7
+
8
+
9
+ require 'helper'
10
+
11
+ class TestDatafile < MiniTest::Test
12
+
13
+ CLUBS_DIR = '../../../openfootball/clubs' ## source repo directory path
14
+ LEAGUES_DIR = '../../../openfootball/leagues'
15
+ AUSTRIA_DIR = '../../../openfootball/austria'
16
+
17
+
18
+ def test_find
19
+ datafiles = Datafile.find_clubs( CLUBS_DIR )
20
+ pp datafiles
21
+
22
+ datafiles = Datafile.find_clubs_wiki( CLUBS_DIR )
23
+ pp datafiles
24
+
25
+ datafiles = Datafile.find_leagues( LEAGUES_DIR )
26
+ pp datafiles
27
+
28
+ datafiles = Datafile.find_conf( AUSTRIA_DIR )
29
+ pp datafiles
30
+ end
31
+
32
+ def test_bundle
33
+ datafiles = Datafile.find_clubs( CLUBS_DIR )
34
+ pp datafiles
35
+
36
+ Datafile.write_bundle( './tmp/clubs.txt',
37
+ datafiles: datafiles,
38
+ header: <<TXT )
39
+ ##########################################
40
+ # auto-generated all-in-one single datafile clubs.txt bundle
41
+ # on #{Time.now} from #{datafiles.size} datafile(s)
42
+ TXT
43
+
44
+ datafiles = Datafile.find_leagues( LEAGUES_DIR )
45
+ pp datafiles
46
+
47
+ Datafile.write_bundle( './tmp/leagues.txt',
48
+ datafiles: datafiles,
49
+ header: <<TXT )
50
+ ##########################################
51
+ # auto-generated all-in-one single datafile leagues.txt bundle
52
+ # on #{Time.now} from #{datafiles.size} datafile(s)
53
+ TXT
54
+ end
55
+ end # class TestDatafile
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-formats
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
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-28 00:00:00.000000000 Z
11
+ date: 2019-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alphabets
@@ -80,10 +80,12 @@ files:
80
80
  - README.md
81
81
  - Rakefile
82
82
  - lib/sportdb/formats.rb
83
+ - lib/sportdb/formats/datafile.rb
83
84
  - lib/sportdb/formats/outline_reader.rb
84
85
  - lib/sportdb/formats/version.rb
85
86
  - test/helper.rb
86
87
  - test/test_csv_reader.rb
88
+ - test/test_datafile.rb
87
89
  - test/test_outline_reader.rb
88
90
  homepage: https://github.com/sportdb/sport.db
89
91
  licenses: