datafile 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/datafile/datafile.rb +0 -15
- data/lib/datafile/dataset.rb +6 -27
- data/lib/datafile/version.rb +1 -1
- data/lib/datafile/workers/file/dataset.rb +1 -16
- data/test/helper.rb +1 -2
- data/test/test_builder.rb +4 -4
- data/test/test_football_dataset.rb +20 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a70f59e6054e3fae9f97e113bd1ec672b02b2cf8
|
4
|
+
data.tar.gz: fef94a40bf6e7d190ec9a2605de4c2469307710c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1c96fcf41d2aa5664aff47255976638827b2b34f959f41f941d1272b567622027c3d0bb8658af71f17e5a27ce96f58b95a47b93fcfd52985b4d2f4bce0b3607
|
7
|
+
data.tar.gz: b4ed10d3b5aace8c699bcdf5a8039c9cfaeae25f88c7f80e8ef622badc84c43d0f59ad57b9c9c71be91a21864955ccc8846d3f58ed5548880e72a9ae328d17b5
|
data/lib/datafile/datafile.rb
CHANGED
@@ -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
|
data/lib/datafile/dataset.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/datafile/version.rb
CHANGED
@@ -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
|
-
|
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
|
data/test/helper.rb
CHANGED
data/test/test_builder.rb
CHANGED
@@ -10,7 +10,7 @@ require 'helper'
|
|
10
10
|
class TestBuilder < MiniTest::Test
|
11
11
|
|
12
12
|
def test_builder
|
13
|
-
code =<<
|
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
|
-
|
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
|
13
|
+
pp FootballDataset.known_datasets
|
14
14
|
|
15
|
-
at =
|
16
|
-
at2 =
|
17
|
-
xxx =
|
18
|
-
xxx2 =
|
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 =
|
30
|
-
at2 =
|
31
|
-
xxx =
|
32
|
-
xxx2 =
|
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 =
|
43
|
-
at2 =
|
44
|
-
xxx =
|
45
|
-
xxx2 =
|
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.
|
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-
|
11
|
+
date: 2019-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logutils
|