datafile 0.3.0 → 0.3.2

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
- SHA1:
3
- metadata.gz: e02f51529c40c3573f5bf51670b8e704e518306e
4
- data.tar.gz: 309d29e81297fcf2a63b95a1c26f72003aa842b3
2
+ SHA256:
3
+ metadata.gz: 54d6b53158bb55adfd268f9c79935c64bc3fb03ab6d1418cc09bffb2ce64970e
4
+ data.tar.gz: 9a47519a90bef056b1a7a4d892f88f027bb277331708418d899178a931e823fa
5
5
  SHA512:
6
- metadata.gz: 77bf2afdca97946e52e99bb6f7b2ba96e714b5890a3be11df6f4a3a3b19e43281e30ee78002125928039535b6813c4ec362e1bd8ecf184fa0935e6487d7fa0e4
7
- data.tar.gz: 41d975fe70d41f75e46031dd7ce006629375b9703dd9449199e6ee3fd3e6461b71db33618ac57720347a5c9fd99889f42caddf3c354bf72ea16aa05cad1a8180
6
+ metadata.gz: 7f87ecb6c27fc3c595dbd16281b496f92fa8174b5cbf2f710dd4c5d0778b09ca96388b85d2185db03b9a0e2279afed87be4149b6c027b4b4c6c7c8da0698b87a
7
+ data.tar.gz: 02af529638c97df49cf8bb1d6bd7cb68128a66c19c3b0c07b17d6f70ad319600cdd5f783580a4478203d1621285df52d22b5a9a1cfd1ded9da17e9c82315b046
data/CHANGELOG.md CHANGED
@@ -1,3 +1,5 @@
1
+ ### 0.3.2
2
+
1
3
  ### 0.0.1 / 2014-11-27
2
4
 
3
5
  * Everything is new. First release.
data/Manifest.txt CHANGED
@@ -13,11 +13,3 @@ lib/datafile/workers/file/registry.rb
13
13
  lib/datafile/workers/file/worker.rb
14
14
  lib/datafile/workers/zip/dataset.rb
15
15
  lib/datafile/workers/zip/worker.rb
16
- test/datafile/eurocup.rb
17
- test/datafile/stadiums.rb
18
- test/datafile/world.rb
19
- test/helper.rb
20
- test/test_builder.rb
21
- test/test_file_dataset_registry.rb
22
- test/test_file_worker.rb
23
- test/test_football_dataset.rb
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # datafile
2
2
 
3
- datafile gem - builder for downloading n reading datasets
3
+ datafile gem - builder for downloading 'n' reading datasets
4
4
 
5
- * home :: [github.com/rubylibs/datafile](https://github.com/rubylibs/datafile)
6
- * bugs :: [github.com/rubylibs/datafile/issues](https://github.com/rubylibs/datafile/issues)
5
+ * home :: [github.com/rubycocos/datasets](https://github.com/rubycocos/datasets)
6
+ * bugs :: [github.com/rubycocos/datasets/issues](https://github.com/rubycocos/datasets/issues)
7
7
  * gem :: [rubygems.org/gems/datafile](https://rubygems.org/gems/datafile)
8
8
  * rdoc :: [rubydoc.info/gems/datafile](http://rubydoc.info/gems/datafile)
9
9
 
data/Rakefile CHANGED
@@ -8,10 +8,10 @@ Hoe.spec 'datafile' do
8
8
  self.summary = 'datafile - builder for downloading n reading datasets'
9
9
  self.description = summary
10
10
 
11
- self.urls = ['https://github.com/rubylibs/datafile']
11
+ self.urls = { home: 'https://github.com/rubycocos/datasets' }
12
12
 
13
13
  self.author = 'Gerald Bauer'
14
- self.email = 'opensport@googlegroups.com'
14
+ self.email = 'gerald.bauer@gmail.com'
15
15
 
16
16
  # switch extension to .markdown for gihub formatting
17
17
  self.readme_file = 'README.md'
@@ -1,11 +1,10 @@
1
- # encoding: utf-8
2
1
 
3
2
  module Datafile
4
3
 
5
4
  class Builder ## "simple" builder (one file, one datafile)
6
5
 
7
6
  def self.load_file( path )
8
- code = File.open( path, 'r:utf-8' ).read
7
+ code = File.open( path, 'r:utf-8' ) {|f| f.read }
9
8
  self.load( code )
10
9
  end
11
10
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
 
3
2
  module Datafile
4
3
 
@@ -7,7 +6,7 @@ class Datafile
7
6
 
8
7
  ## convenience method - use like Datafile.load_file()
9
8
  def self.load_file( path='./Datafile' )
10
- code = File.open( path, 'r:utf-8' ).read
9
+ code = File.open( path, 'r:utf-8' ) { |f| f.read }
11
10
  self.load( code )
12
11
  end
13
12
 
@@ -19,9 +18,6 @@ class Datafile
19
18
  # Note: return datafile (of course, NOT the builder)
20
19
  # if you want a builder use Datafile::Builder ;-)
21
20
  datafile = builder.datafile
22
- ## check for auto-configure (just guessing)
23
- ## zip or file worker
24
- datafile.guess_file_or_zip_worker
25
21
  datafile
26
22
  end
27
23
 
@@ -56,18 +52,6 @@ class Datafile
56
52
  end
57
53
 
58
54
 
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
55
  def run
72
56
  logger.info( "[datafile] begin - run" )
73
57
  download # step 1 - download zips for datasets
@@ -1,12 +1,10 @@
1
- # encoding: utf-8
2
-
3
1
 
4
2
  ############
5
3
  # fix: move global method to ??
6
4
 
7
5
  def read_known_datasets( path )
8
6
  ary = []
9
- lines = File.open( path, 'r:utf-8' ).read
7
+ lines = File.open( path, 'r:utf-8' ) {|f| f.read }
10
8
  lines.each_line do |line|
11
9
  ## skip blank and comments lines
12
10
  next if /^\s*#/ =~ line || /^\s*$/ =~ line
@@ -32,35 +30,9 @@ class Dataset
32
30
  ## convenience helpers for known opts
33
31
  def setup() @opts[:setup]; end ## note: return nil if not found/set
34
32
  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
33
  end # class Dataset
61
34
 
62
35
 
63
-
64
36
  class WorldDataset < Dataset
65
37
  def initialize( name_easy, opts={} )
66
38
 
@@ -129,6 +101,11 @@ class BeerDataset < Dataset
129
101
  super( name, opts )
130
102
  end
131
103
  end # class BeerDataset
104
+ end # module Datafile
132
105
 
133
106
 
134
- end # module Datafile
107
+ ## note: add "known" dataset classes to global namespace - why? why not?
108
+ ## add "global" shortcuts for now
109
+ WorldDataset = Datafile::WorldDataset
110
+ FootballDataset = Datafile::FootballDataset
111
+ BeerDataset = Datafile::BeerDataset
@@ -1,10 +1,9 @@
1
- # encoding: utf-8
2
1
 
3
2
  module Datafile
4
3
 
5
4
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
5
  MINOR = 3
7
- PATCH = 0
6
+ PATCH = 2
8
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
8
 
10
9
  def self.version
@@ -12,11 +11,11 @@ module Datafile
12
11
  end
13
12
 
14
13
  def self.banner
15
- "datafile/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
14
+ "datafile/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
16
15
  end
17
16
 
18
17
  def self.root
19
- "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
18
+ File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
20
19
  end
21
20
 
22
21
  def self.data_path
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
 
3
2
  module Datafile
4
3
 
@@ -18,18 +17,7 @@ class FileDataset
18
17
  end
19
18
 
20
19
  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 )
20
+ self.class.registry.lookup( @dataset.name )
33
21
  end
34
22
 
35
23
  def dump
@@ -48,9 +36,5 @@ class FileDataset
48
36
  logger.info( "TODO/FIX: read dataset (file) '#{@dataset.name}', '#{@dataset.setup}'; sorry" )
49
37
  end
50
38
  end
51
-
52
-
53
- private
54
- def registry() self.class.registry; end ## convenience method to access "static" shared class variable
55
39
  end # class FileDataset
56
40
  end # module Datafile
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
 
3
2
  module Datafile
4
3
 
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+
2
2
 
3
3
  module Datafile
4
4
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
 
3
2
  module Datafile
4
3
 
@@ -72,7 +71,7 @@ private
72
71
 
73
72
  ## make sure dest path exists
74
73
  dest_p = File.dirname( dest )
75
- FileUtils.mkdir_p( dest_p ) unless File.exists?( dest_p ) ## use Dir.exists?? why? why not??
74
+ FileUtils.mkdir_p( dest_p ) unless File.exist?( dest_p ) ## use Dir.exist?? why? why not??
76
75
 
77
76
  worker = Fetcher::Worker.new
78
77
  worker.copy( url, dest )
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+
2
2
 
3
3
  module Datafile
4
4
 
data/lib/datafile.rb CHANGED
@@ -1,11 +1,10 @@
1
- # encoding: utf-8
2
-
3
1
  require 'logutils'
4
2
  require 'fetcher' ## add (HTTP/S) download support (of blobs/binaries/zips)
5
3
 
6
4
 
7
5
  # our own code
8
- require 'datafile/version' # let it always go first
6
+ require_relative 'datafile/version' # let it always go first
7
+
9
8
 
10
9
 
11
10
  module Datafile
@@ -31,19 +30,19 @@ module Datafile
31
30
  end # module Datafile
32
31
 
33
32
 
34
- require 'datafile/dataset'
35
- require 'datafile/builder'
33
+ require_relative 'datafile/dataset'
34
+ require_relative 'datafile/builder'
36
35
 
37
36
 
38
- require 'datafile/workers/file/registry'
39
- require 'datafile/workers/file/dataset'
40
- require 'datafile/workers/file/worker'
37
+ require_relative 'datafile/workers/file/registry'
38
+ require_relative 'datafile/workers/file/dataset'
39
+ require_relative 'datafile/workers/file/worker'
41
40
 
42
- require 'datafile/workers/zip/dataset'
43
- require 'datafile/workers/zip/worker'
41
+ require_relative 'datafile/workers/zip/dataset'
42
+ require_relative 'datafile/workers/zip/worker'
44
43
 
45
- require 'datafile/datafile'
44
+ require_relative 'datafile/datafile'
46
45
 
47
46
 
48
47
  # say hello
49
- puts Datafile.banner if defined?($RUBYCOCO_DEBUG) && $RUBYCOCO_DEBUG
48
+ puts Datafile.banner ## if defined?($RUBYCOCO_DEBUG) && $RUBYCOCO_DEBUG
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-21 00:00:00.000000000 Z
11
+ date: 2024-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logutils
@@ -42,32 +42,38 @@ dependencies:
42
42
  name: rdoc
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '4.0'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '7'
48
51
  type: :development
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
- - - "~>"
55
+ - - ">="
53
56
  - !ruby/object:Gem::Version
54
57
  version: '4.0'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '7'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: hoe
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '3.16'
67
+ version: '4.1'
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '3.16'
74
+ version: '4.1'
69
75
  description: datafile - builder for downloading n reading datasets
70
- email: opensport@googlegroups.com
76
+ email: gerald.bauer@gmail.com
71
77
  executables: []
72
78
  extensions: []
73
79
  extra_rdoc_files:
@@ -90,19 +96,11 @@ files:
90
96
  - lib/datafile/workers/file/worker.rb
91
97
  - lib/datafile/workers/zip/dataset.rb
92
98
  - lib/datafile/workers/zip/worker.rb
93
- - test/datafile/eurocup.rb
94
- - test/datafile/stadiums.rb
95
- - test/datafile/world.rb
96
- - test/helper.rb
97
- - test/test_builder.rb
98
- - test/test_file_dataset_registry.rb
99
- - test/test_file_worker.rb
100
- - test/test_football_dataset.rb
101
- homepage: https://github.com/rubylibs/datafile
99
+ homepage: https://github.com/rubycocos/datasets
102
100
  licenses:
103
101
  - Public Domain
104
102
  metadata: {}
105
- post_install_message:
103
+ post_install_message:
106
104
  rdoc_options:
107
105
  - "--main"
108
106
  - README.md
@@ -119,9 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
117
  - !ruby/object:Gem::Version
120
118
  version: '0'
121
119
  requirements: []
122
- rubyforge_project:
123
- rubygems_version: 2.5.2
124
- signing_key:
120
+ rubygems_version: 3.4.10
121
+ signing_key:
125
122
  specification_version: 4
126
123
  summary: datafile - builder for downloading n reading datasets
127
124
  test_files: []
@@ -1,6 +0,0 @@
1
- #####################
2
- # national teams
3
-
4
- football 'national-teams'
5
- football 'euro-cup'
6
-
@@ -1,3 +0,0 @@
1
-
2
- football 'stadiums' ## NOTE: default is setup: 'all'
3
-
@@ -1,3 +0,0 @@
1
-
2
- world 'world.db', setup: 'countries'
3
-
data/test/helper.rb DELETED
@@ -1,13 +0,0 @@
1
-
2
- ## minitest setup
3
- require 'minitest/autorun'
4
-
5
- ## deps
6
-
7
- ### require 'worlddb'
8
- require 'sportdb/models' # note: will include worlddb
9
-
10
-
11
- ## our own code
12
- require 'datafile'
13
-
data/test/test_builder.rb DELETED
@@ -1,45 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_builder.rb
6
-
7
-
8
- require 'helper'
9
-
10
- class TestBuilder < MiniTest::Test
11
-
12
- def test_builder
13
- code =<<EOS
14
- ## comments
15
-
16
- world 'world.db', setup: 'countries'
17
-
18
- football 'national-teams' ## NOTE: default is setup: 'all
19
-
20
- ### todo/fix: download archive only once(!!) even if included more than once
21
- ## football 'world-cup', setup: '2014_quali'
22
-
23
- football 'world-cup', setup: '2014'
24
-
25
- ## more comments
26
-
27
- EOS
28
-
29
- builder = Datafile::Builder.load( code )
30
-
31
- datafile = builder.datafile
32
- datafile.run
33
-
34
- datafile.download
35
- datafile.read
36
- datafile.dump
37
-
38
- ## change worker (defaults to ZipWorker)
39
- datafile.worker = Datafile::FileWorker
40
- datafile.dump
41
-
42
- assert true # if we get here - test success
43
- end
44
-
45
- end # class TestBuilder
@@ -1,26 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_file_dataset_registry.rb
6
-
7
-
8
- require 'helper'
9
-
10
- class TestFileDatasetRegistry < MiniTest::Test
11
-
12
- def test_lookup
13
- registry = Datafile::FileDatasetRegistry.new
14
- registry.merge( openfootball: '../../openfootball' )
15
-
16
- assert_equal '../../openfootball/austria', registry.lookup( 'openfootball/austria')
17
- assert_equal '../../openmundi/world.db', registry.lookup( 'openmundi/world.db' )
18
-
19
- assert_equal '../../openfootball/austria', registry.lookup!( 'openfootball/austria')
20
- assert_equal '../../openmundi/world.db', registry.lookup!( 'openmundi/world.db' )
21
-
22
- assert_equal '../../openfootball/national-teams', registry.lookup( 'openfootball/national-teams')
23
- assert_equal '../../openfootball/euro-cup', registry.lookup( 'openfootball/euro-cup' )
24
- end
25
-
26
- end # class TestFileDatasetRegistry
@@ -1,40 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_file_worker.rb
6
-
7
-
8
- require 'helper'
9
-
10
- class TestFileWorker < MiniTest::Test
11
-
12
- def test_eurocup
13
-
14
- world_datafile = Datafile::Datafile.load_file( "#{Datafile.root}/test/datafile/world.rb" )
15
- world_datafile.dump
16
-
17
- eurocup_datafile = Datafile::Datafile.load_file( "#{Datafile.root}/test/datafile/eurocup.rb" )
18
- eurocup_datafile.dump
19
-
20
- # database setup 'n' config
21
- ActiveRecord::Base.establish_connection( adapter: 'sqlite3',
22
- database: ':memory:' )
23
- SportDb.create_all
24
-
25
- ## change worker (defaults to ZipWorker)
26
- world_datafile.worker = Datafile::FileWorker
27
- world_datafile.dump
28
- ## world_datafile.read
29
-
30
- registry = Datafile::FileDataset.registry
31
- registry.merge( openfootball: '../../openfootball' )
32
-
33
- eurocup_datafile.worker = Datafile::FileWorker
34
- eurocup_datafile.dump
35
- ## eurocup_datafile.read
36
-
37
- assert true # if we get here - test success
38
- end
39
-
40
- end # class TestFileWorker
@@ -1,54 +0,0 @@
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( 'austria' )
16
- at2 = Datafile::FootballDataset.new( 'openfootball/austria' )
17
- xxx = Datafile::FootballDataset.new( 'xxx' )
18
- xxx2 = Datafile::FootballDataset.new( 'openfootball/xxx' )
19
-
20
- assert_equal 'openfootball/austria', at.name
21
- assert_equal 'openfootball/austria', at2.name
22
-
23
- assert_equal 'openfootball/xxx', xxx.name
24
- assert_equal 'openfootball/xxx', xxx2.name
25
- end
26
-
27
- ## move to test datasets - why, why not ??
28
- 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' )
33
-
34
- assert_equal 'openmundi/austria.db', at.name
35
- assert_equal 'openmundi/austria.db', at2.name
36
-
37
- assert_equal 'openmundi/xxx', xxx.name
38
- assert_equal 'openmundi/xxx', xxx2.name
39
- end
40
-
41
- 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' )
46
-
47
- assert_equal 'openbeer/austria', at.name
48
- assert_equal 'openbeer/austria', at2.name
49
-
50
- assert_equal 'openbeer/xxx', xxx.name
51
- assert_equal 'openbeer/xxx', xxx2.name
52
- end
53
-
54
- end # class TestFootballDataset