datafile 0.3.0 → 0.3.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: e02f51529c40c3573f5bf51670b8e704e518306e
4
- data.tar.gz: 309d29e81297fcf2a63b95a1c26f72003aa842b3
3
+ metadata.gz: a70f59e6054e3fae9f97e113bd1ec672b02b2cf8
4
+ data.tar.gz: fef94a40bf6e7d190ec9a2605de4c2469307710c
5
5
  SHA512:
6
- metadata.gz: 77bf2afdca97946e52e99bb6f7b2ba96e714b5890a3be11df6f4a3a3b19e43281e30ee78002125928039535b6813c4ec362e1bd8ecf184fa0935e6487d7fa0e4
7
- data.tar.gz: 41d975fe70d41f75e46031dd7ce006629375b9703dd9449199e6ee3fd3e6461b71db33618ac57720347a5c9fd99889f42caddf3c354bf72ea16aa05cad1a8180
6
+ metadata.gz: b1c96fcf41d2aa5664aff47255976638827b2b34f959f41f941d1272b567622027c3d0bb8658af71f17e5a27ce96f58b95a47b93fcfd52985b4d2f4bce0b3607
7
+ data.tar.gz: b4ed10d3b5aace8c699bcdf5a8039c9cfaeae25f88c7f80e8ef622badc84c43d0f59ad57b9c9c71be91a21864955ccc8846d3f58ed5548880e72a9ae328d17b5
@@ -19,9 +19,6 @@ class Datafile
19
19
  # Note: return datafile (of course, NOT the builder)
20
20
  # if you want a builder use Datafile::Builder ;-)
21
21
  datafile = builder.datafile
22
- ## check for auto-configure (just guessing)
23
- ## zip or file worker
24
- datafile.guess_file_or_zip_worker
25
22
  datafile
26
23
  end
27
24
 
@@ -56,18 +53,6 @@ class Datafile
56
53
  end
57
54
 
58
55
 
59
- def guess_file_or_zip_worker ## change/rename to configure_file_or_zip_worker - why? why not??
60
- ## if opts file or zip exists do NOT change (assume set manually)
61
- return if @opts[:file] || @opts[:zip]
62
-
63
- ## for now only change if single (just 1) dataset and it's present
64
- if @datasets.size == 1 && @datasets[0].file?
65
- puts " bingo!! assume (in-situ) datafile; use file workers"
66
- @worker = FileWorker.new( self )
67
- end
68
- end
69
-
70
-
71
56
  def run
72
57
  logger.info( "[datafile] begin - run" )
73
58
  download # step 1 - download zips for datasets
@@ -32,35 +32,9 @@ class Dataset
32
32
  ## convenience helpers for known opts
33
33
  def setup() @opts[:setup]; end ## note: return nil if not found/set
34
34
  def format() @opts[:format] || 'txt'; end ## note: assume default is txt (other formats incl. csv) for now - why? wh not?
35
-
36
-
37
- def file? # note: use file? (not exit? might use zip? later to check if zip exists? -why? why not?)
38
- ## hack/convenience shortcut:
39
- ## 1) check if dataset exists as local (in situ) file dataset
40
- ## e.g. working folder == name of dataset
41
- ##
42
- ## todo/fix: 2) also check
43
- ## via (file)registry - why, why not??
44
-
45
- ## split name in org/user + project (e.g. openfootball/at-austria)
46
- parts = @name.split( '/' )
47
-
48
- basename = parts[1]
49
- ## e.g.
50
- ## ./ (working folder) => at-austria
51
- ## openfootball/at-austria
52
- if File.basename( Dir.getwd ) == basename
53
- puts " bingo!! working folder >#{basename}< matches dataset"
54
- true ## return true
55
- else
56
- false ## return false
57
- end
58
- end ## file?
59
-
60
35
  end # class Dataset
61
36
 
62
37
 
63
-
64
38
  class WorldDataset < Dataset
65
39
  def initialize( name_easy, opts={} )
66
40
 
@@ -129,6 +103,11 @@ class BeerDataset < Dataset
129
103
  super( name, opts )
130
104
  end
131
105
  end # class BeerDataset
106
+ end # module Datafile
132
107
 
133
108
 
134
- end # module Datafile
109
+ ## note: add "known" dataset classes to global namespace - why? why not?
110
+ ## add "global" shortcuts for now
111
+ WorldDataset = Datafile::WorldDataset
112
+ FootballDataset = Datafile::FootballDataset
113
+ BeerDataset = Datafile::BeerDataset
@@ -4,7 +4,7 @@ module Datafile
4
4
 
5
5
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
6
  MINOR = 3
7
- PATCH = 0
7
+ PATCH = 1
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
@@ -18,18 +18,7 @@ class FileDataset
18
18
  end
19
19
 
20
20
  def repo_dir ### check: use (rename to) include dir (or local_repo_dir) - why, why not ???
21
- ## note: for easy testing allow "in situ" datasets
22
- ## e.g. ./ (e.g. mu-mauritius) is openfootball/mu-mauritius
23
- ## split name in org/user + project (e.g. openfootball/at-austria)
24
- parts = @dataset.name.split( '/' )
25
-
26
- basename = parts[1]
27
- if File.basename( Dir.getwd ) == basename
28
- puts " bingo!! working folder >#{basename}< matches dataset"
29
- return Dir.getwd ## assume working directory/folder is repo dir
30
- end
31
-
32
- registry.lookup( @dataset.name )
21
+ self.class.registry.lookup( @dataset.name )
33
22
  end
34
23
 
35
24
  def dump
@@ -48,9 +37,5 @@ class FileDataset
48
37
  logger.info( "TODO/FIX: read dataset (file) '#{@dataset.name}', '#{@dataset.setup}'; sorry" )
49
38
  end
50
39
  end
51
-
52
-
53
- private
54
- def registry() self.class.registry; end ## convenience method to access "static" shared class variable
55
40
  end # class FileDataset
56
41
  end # module Datafile
@@ -6,8 +6,7 @@ require 'minitest/autorun'
6
6
 
7
7
  ### require 'worlddb'
8
8
  require 'sportdb/models' # note: will include worlddb
9
-
9
+ require 'sportdb/readers' ## pulls in SportDb::ZipPackage or SportDb::DirPackage
10
10
 
11
11
  ## our own code
12
12
  require 'datafile'
13
-
@@ -10,7 +10,7 @@ require 'helper'
10
10
  class TestBuilder < MiniTest::Test
11
11
 
12
12
  def test_builder
13
- code =<<EOS
13
+ code =<<TXT
14
14
  ## comments
15
15
 
16
16
  world 'world.db', setup: 'countries'
@@ -24,15 +24,15 @@ class TestBuilder < MiniTest::Test
24
24
 
25
25
  ## more comments
26
26
 
27
- EOS
27
+ TXT
28
28
 
29
29
  builder = Datafile::Builder.load( code )
30
30
 
31
31
  datafile = builder.datafile
32
- datafile.run
32
+ ## datafile.run
33
33
 
34
34
  datafile.download
35
- datafile.read
35
+ ## datafile.read
36
36
  datafile.dump
37
37
 
38
38
  ## change worker (defaults to ZipWorker)
@@ -10,26 +10,33 @@ require 'helper'
10
10
  class TestFootballDataset < MiniTest::Test
11
11
 
12
12
  def test_names
13
- pp Datafile::FootballDataset.known_datasets
13
+ pp FootballDataset.known_datasets
14
14
 
15
- at = Datafile::FootballDataset.new( 'austria' )
16
- at2 = Datafile::FootballDataset.new( 'openfootball/austria' )
17
- xxx = Datafile::FootballDataset.new( 'xxx' )
18
- xxx2 = Datafile::FootballDataset.new( 'openfootball/xxx' )
15
+ at = FootballDataset.new( 'austria' )
16
+ at2 = FootballDataset.new( 'openfootball/austria' )
17
+ xxx = FootballDataset.new( 'xxx' )
18
+ xxx2 = FootballDataset.new( 'openfootball/xxx' )
19
19
 
20
20
  assert_equal 'openfootball/austria', at.name
21
21
  assert_equal 'openfootball/austria', at2.name
22
22
 
23
23
  assert_equal 'openfootball/xxx', xxx.name
24
24
  assert_equal 'openfootball/xxx', xxx2.name
25
+
26
+ ## check csv format
27
+ at = FootballDataset.new( 'austria', format: 'csv' )
28
+ at2 = FootballDataset.new( 'footballcsv/austria' )
29
+
30
+ assert_equal 'footballcsv/austria', at.name
31
+ assert_equal 'footballcsv/austria', at2.name
25
32
  end
26
33
 
27
34
  ## move to test datasets - why, why not ??
28
35
  def test_world
29
- at = Datafile::WorldDataset.new( 'austria.db' )
30
- at2 = Datafile::WorldDataset.new( 'openmundi/austria.db' )
31
- xxx = Datafile::WorldDataset.new( 'xxx' )
32
- xxx2 = Datafile::WorldDataset.new( 'openmundi/xxx' )
36
+ at = WorldDataset.new( 'austria.db' )
37
+ at2 = WorldDataset.new( 'openmundi/austria.db' )
38
+ xxx = WorldDataset.new( 'xxx' )
39
+ xxx2 = WorldDataset.new( 'openmundi/xxx' )
33
40
 
34
41
  assert_equal 'openmundi/austria.db', at.name
35
42
  assert_equal 'openmundi/austria.db', at2.name
@@ -39,10 +46,10 @@ class TestFootballDataset < MiniTest::Test
39
46
  end
40
47
 
41
48
  def test_beer
42
- at = Datafile::BeerDataset.new( 'austria' )
43
- at2 = Datafile::BeerDataset.new( 'openbeer/austria' )
44
- xxx = Datafile::BeerDataset.new( 'xxx' )
45
- xxx2 = Datafile::BeerDataset.new( 'openbeer/xxx' )
49
+ at = BeerDataset.new( 'austria' )
50
+ at2 = BeerDataset.new( 'openbeer/austria' )
51
+ xxx = BeerDataset.new( 'xxx' )
52
+ xxx2 = BeerDataset.new( 'openbeer/xxx' )
46
53
 
47
54
  assert_equal 'openbeer/austria', at.name
48
55
  assert_equal 'openbeer/austria', at2.name
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.3.0
4
+ version: 0.3.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: 2019-11-21 00:00:00.000000000 Z
11
+ date: 2019-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logutils