datafile 0.2.0 → 0.2.1

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: 62443719632bb6ef1b75ce5b79ef146e1ddca9b1
4
- data.tar.gz: 5d39b5537c4f280cb395d2be2e9abec702d910b4
3
+ metadata.gz: 8afa4e20859ba348f32a1d45f7d385623146099d
4
+ data.tar.gz: 276cbc2838cd98a227af23ae3bced081b584ed05
5
5
  SHA512:
6
- metadata.gz: 04882e94add84a5c478025535375760c21ea006714a1f6e3d8b92660d98477d460065306082ac4ebf321621c7782d99beac8ae0ab7f75f28c3d430ef80658e84
7
- data.tar.gz: 1ece9f87e091abf9fb494777aaf626a647188a788b4ede359bfb0a940eb53dffb50db90e6354d59cb128b383a980968928ccbfdfcc86eacd8fef766f11bf55b7
6
+ metadata.gz: 6c59a27aa7fc14e30cc48cc0a16252eac83d08ccbea25e2008aa4f8bcf9c06fcff3a918ca3f831334532e55cda699466acb8e3d513ef5d41b2a973d9d001f2cb
7
+ data.tar.gz: a7ab8bf94cc1e1feb28ecdb3d2bb9e6a9de90c948a092501650726f18b08e8eaa1874e920fc966a6ea298c9b2bb4470110400f4b22e7f521f2d713497041e42b
@@ -2,6 +2,7 @@ HISTORY.md
2
2
  Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
+ data/football.txt
5
6
  lib/datafile.rb
6
7
  lib/datafile/builder.rb
7
8
  lib/datafile/builder2.rb
@@ -26,3 +27,4 @@ test/test_builder.rb
26
27
  test/test_builder2.rb
27
28
  test/test_file_dataset_registry.rb
28
29
  test/test_file_worker.rb
30
+ test/test_football_dataset.rb
@@ -0,0 +1,45 @@
1
+ ##########################################################
2
+ # known football.db (openfootball) datasets (repos)
3
+
4
+ #####################
5
+ # -- Basics
6
+
7
+ openfootball/stadiums
8
+ openfootball/players
9
+ openfootball/assocs
10
+
11
+ ##########################
12
+ # -- National Teams
13
+
14
+ openfootball/national-teams
15
+
16
+ openfootball/world-cup
17
+ openfootball/euro-cup
18
+ openfootball/africa-cup
19
+ openfootball/north-america-gold-cup
20
+ openfootball/copa-america
21
+ openfootball/confed-cup
22
+
23
+ #########################
24
+ # -- Clubs
25
+
26
+ openfootball/clubs
27
+
28
+ openfootball/eng-england
29
+ openfootball/at-austria
30
+ openfootball/de-deutschland
31
+ openfootball/es-espana
32
+ openfootball/it-italy
33
+ openfootball/fr-france
34
+ openfootball/ch-confoederatio-helvetica
35
+ openfootball/europe-champions-league
36
+
37
+ openfootball/major-league-soccer
38
+ openfootball/mx-mexico
39
+ openfootball/north-america-champions-league
40
+
41
+ openfootball/br-brazil
42
+ openfootball/copa-sudamericana
43
+ openfootball/copa-libertadores
44
+
45
+ openfootball/club-world-cup
@@ -26,6 +26,14 @@ require 'datafile/builder'
26
26
  require 'datafile/builder2'
27
27
 
28
28
 
29
+ module Datafile
30
+ def self.data_path
31
+ "#{root}/data"
32
+ end
33
+ end # module Datafile
34
+
35
+
36
+
29
37
  # say hello
30
38
  puts Datafile.banner if defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG
31
39
 
@@ -1,5 +1,22 @@
1
1
  # encoding: utf-8
2
2
 
3
+
4
+ ############
5
+ # fix: move global method to ??
6
+
7
+ def read_known_datasets( path )
8
+ ary = []
9
+ lines = File.read( path ) ### fix: use File.read_utf8 ??
10
+ lines.each_line do |line|
11
+ ## skip blank and comments lines
12
+ next if /^\s*#/ =~ line || /^\s*$/ =~ line
13
+
14
+ ary << line.strip
15
+ end
16
+ ary
17
+ end
18
+
19
+
3
20
  module Datafile
4
21
 
5
22
  class Dataset
@@ -29,15 +46,46 @@ class WorldDataset < Dataset
29
46
  def file_worker() WorldFileDataset.new( self ); end
30
47
  end # class WorldDataset
31
48
 
49
+
50
+
32
51
  class FootballDataset < Dataset
33
- def initialize( name, opts={} )
52
+
53
+ @@known_football_datasets = nil
54
+
55
+ def self.known_datasets
56
+ ## return array of known datasets
57
+ ### todo/fix - use \\= idiom - why, why not??
58
+ if @@known_football_datasets.nil?
59
+ @@known_football_datasets = read_known_datasets( "#{::Datafile.data_path}/football.txt" )
60
+ end
61
+ @@known_football_datasets
62
+ end
63
+
64
+
65
+ def initialize( name_easy, opts={} )
66
+
67
+ ## check if name include slash (e.g. /)
68
+ ## - if not auto-add openfootball/ (default)
69
+ if name_easy.index( '/' ).nil?
70
+ name = "openfootball/#{name_easy}"
71
+ else
72
+ name = name_easy ## just pass through for now
73
+ end
74
+
34
75
  super( name, opts )
76
+
77
+ ### check for known datasets; warn: if not known (might be a typo)
78
+ unless FootballDataset.known_datasets.include?( name )
79
+ ## todo: use logger - why, why not??
80
+ puts "*** warn: unknown football dataset '#{name}', typo ???"
81
+ end
35
82
  end
36
83
 
37
84
  def zip_worker() FootballZipDataset.new( self ); end
38
85
  def file_worker() FootballFileDataset.new( self ); end
39
86
  end # class FootballDataset
40
87
 
88
+
41
89
  class BeerDataset < Dataset
42
90
  def initialize( name, opts={} )
43
91
  super( name, opts )
@@ -4,7 +4,7 @@ module Datafile
4
4
 
5
5
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
6
  MINOR = 2
7
- PATCH = 0
7
+ PATCH = 1
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
@@ -3,12 +3,12 @@ puts "[eval] self in top = #{self.class.name}"
3
3
 
4
4
  task :at => :importbuiltin do
5
5
  puts "[eval] self in data (enter) = #{self.class.name}"
6
- football 'openfootball/at-austria'
6
+ football 'at-austria'
7
7
  puts "[eval] self in data (leave) = #{self.class.name}"
8
8
  end
9
9
 
10
10
  task :at_2014_15 => :importbuiltin do
11
- football 'openfootball/at-austria', setup: '2014-15'
11
+ football 'at-austria', setup: '2014-15'
12
12
  end
13
13
 
14
14
 
@@ -15,12 +15,12 @@ class TestBuilder < MiniTest::Test
15
15
 
16
16
  world 'openmundi/world.db', setup: 'countries'
17
17
 
18
- football 'openfootball/national-teams' ## NOTE: default is setup: 'all'
18
+ football 'national-teams' ## NOTE: default is setup: 'all'
19
19
 
20
20
  ### todo/fix: download archive only once(!!) even if included more than once
21
- ## football 'openfootball/world-cup', setup: '2014_quali'
21
+ ## football 'world-cup', setup: '2014_quali'
22
22
 
23
- football 'openfootball/world-cup', setup: '2014'
23
+ football 'world-cup', setup: '2014'
24
24
 
25
25
  ## more comments
26
26
 
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_football_dataset.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestFootballDataset < MiniTest::Test
11
+
12
+ def test_names
13
+ pp Datafile::FootballDataset.known_datasets
14
+
15
+ at = Datafile::FootballDataset.new( 'at-austria' )
16
+ at2 = Datafile::FootballDataset.new( 'openfootball/at-austria' )
17
+ xxx = Datafile::FootballDataset.new( 'xxx' )
18
+ xxx2 = Datafile::FootballDataset.new( 'openfootball/xxx' )
19
+
20
+ assert_equal 'openfootball/at-austria', at.name
21
+ assert_equal 'openfootball/at-austria', at2.name
22
+
23
+ assert_equal 'openfootball/xxx', xxx.name
24
+ assert_equal 'openfootball/xxx', xxx2.name
25
+ end
26
+
27
+ end # class TestFootballDataset
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datafile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-12 00:00:00.000000000 Z
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logutils
@@ -94,6 +94,7 @@ files:
94
94
  - Manifest.txt
95
95
  - README.md
96
96
  - Rakefile
97
+ - data/football.txt
97
98
  - lib/datafile.rb
98
99
  - lib/datafile/builder.rb
99
100
  - lib/datafile/builder2.rb
@@ -118,6 +119,7 @@ files:
118
119
  - test/test_builder2.rb
119
120
  - test/test_file_dataset_registry.rb
120
121
  - test/test_file_worker.rb
122
+ - test/test_football_dataset.rb
121
123
  homepage: https://github.com/rubylibs/datafile
122
124
  licenses:
123
125
  - Public Domain
@@ -148,4 +150,5 @@ test_files:
148
150
  - test/test_builder2.rb
149
151
  - test/test_builder.rb
150
152
  - test/test_file_dataset_registry.rb
153
+ - test/test_football_dataset.rb
151
154
  - test/test_file_worker.rb