sportdb-formats 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9dfb4b397ab313f54b1a8c6943d7707777737af9
4
+ data.tar.gz: d1d8413b546a02575adce273ba2fe95db93893f3
5
+ SHA512:
6
+ metadata.gz: 65403f493c15c5ca2113416570567bf0d5f7b68655cd85462ae609480119bfab417f5e318cbf7b5e97d02b09022845ab886ca675392b5f1358610c7c00eb5d4f
7
+ data.tar.gz: c941e27074b31c830c3cf9ac3e8c5581852aec1ee8490b732fc56f8afc69862a0ae2f91f1a28d061da3e55f1f9d235c140c438ff198fa8dcd53af192e863b95e
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ### 0.0.1 / 2019-10-28
2
+
3
+ * Everything is new. First release.
data/Manifest.txt ADDED
@@ -0,0 +1,10 @@
1
+ CHANGELOG.md
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ lib/sportdb/formats.rb
6
+ lib/sportdb/formats/outline_reader.rb
7
+ lib/sportdb/formats/version.rb
8
+ test/helper.rb
9
+ test/test_csv_reader.rb
10
+ test/test_outline_reader.rb
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # sportdb-formats - sport.db format and text utilities
2
+
3
+
4
+ * home :: [github.com/sportdb/sport.db](https://github.com/sportdb/sport.db)
5
+ * bugs :: [github.com/sportdb/sport.db/issues](https://github.com/sportdb/sport.db/issues)
6
+ * gem :: [rubygems.org/gems/sportdb-formats](https://rubygems.org/gems/sportdb-formats)
7
+ * rdoc :: [rubydoc.info/gems/sportdb-formats](http://rubydoc.info/gems/sportdb-formats)
8
+ * forum :: [opensport](http://groups.google.com/group/opensport)
9
+
10
+
11
+
12
+ ## Usage
13
+
14
+ To be done
15
+
16
+ ## License
17
+
18
+ The `sportdb-formats` scripts are dedicated to the public domain.
19
+ Use it as you please with no restrictions whatsoever.
20
+
21
+
22
+ ## Questions? Comments?
23
+
24
+ Send them along to the
25
+ [Open Sports & Friends Forum/Mailing List](http://groups.google.com/group/opensport).
26
+ Thanks!
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require 'hoe'
2
+ require './lib/sportdb/formats/version.rb'
3
+
4
+ Hoe.spec 'sportdb-formats' do
5
+
6
+ self.version = SportDb::Formats::VERSION
7
+
8
+ self.summary = "sportdb-formats - sport.db format and text utilities"
9
+ self.description = summary
10
+
11
+ self.urls = ['https://github.com/sportdb/sport.db']
12
+
13
+ self.author = 'Gerald Bauer'
14
+ self.email = 'opensport@googlegroups.com'
15
+
16
+ # switch extension to .markdown for gihub formatting
17
+ self.readme_file = 'README.md'
18
+ self.history_file = 'CHANGELOG.md'
19
+
20
+ self.licenses = ['Public Domain']
21
+
22
+ self.extra_deps = [
23
+ ['alphabets', '>= 0.1.0'],
24
+ ['csvreader', '>= 1.2.4'],
25
+ ]
26
+
27
+ self.spec_extras = {
28
+ required_ruby_version: '>= 2.2.2'
29
+ }
30
+
31
+ end
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+
3
+ require 'pp'
4
+ require 'date'
5
+ require 'fileutils'
6
+
7
+
8
+ ## 3rd party gems
9
+ require 'alphabets' # downcase_i18n, unaccent, variants, ...
10
+ require 'csvreader'
11
+
12
+ def read_csv( path )
13
+ CsvHash.read( path, :header_converters => :symbol )
14
+ end
15
+
16
+ def parse_csv( txt )
17
+ CsvHash.parse( txt, :header_converters => :symbol )
18
+ end
19
+
20
+
21
+ ###
22
+ # our own code
23
+ require 'sportdb/formats/version' # let version always go first
24
+ require 'sportdb/formats/outline_reader'
25
+
26
+
27
+
28
+
29
+ ## let's put test configuration in its own namespace / module
30
+ module SportDb
31
+ class Test ## todo/check: works with module too? use a module - why? why not?
32
+
33
+ ####
34
+ # todo/fix: find a better way to configure shared test datasets - why? why not?
35
+ # note: use one-up (..) directory for now as default - why? why not?
36
+ def self.data_dir() @data_dir ||= '../test'; end
37
+ def self.data_dir=( path ) @data_dir = path; end
38
+ end
39
+ end # module SportDb
40
+
41
+
42
+
43
+ puts SportDb::Formats.banner # say hello
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ module SportDb
4
+
5
+ class OutlineReader
6
+
7
+ def self.read( path ) ## use - rename to read_file or from_file etc. - why? why not?
8
+ txt = File.open( path, 'r:utf-8' ).read
9
+ parse( txt )
10
+ end
11
+
12
+ def self.parse( txt )
13
+ outline=[] ## outline structure
14
+
15
+ txt.each_line do |line|
16
+ line = line.strip ## todo/fix: keep leading and trailing spaces - why? why not?
17
+
18
+ next if line.empty? ## todo/fix: keep blank line nodes e.g. just remove comments and process headings?! - why? why not?
19
+ break if line == '__END__'
20
+
21
+ next if line.start_with?( '#' ) ## skip comments too
22
+ ## strip inline (until end-of-line) comments too
23
+ ## e.g Eupen | KAS Eupen ## [de]
24
+ ## => Eupen | KAS Eupen
25
+ ## e.g bq Bonaire, BOE # CONCACAF
26
+ ## => bq Bonaire, BOE
27
+ line = line.sub( /#.*/, '' ).strip
28
+ pp line
29
+
30
+ next if line =~ /^={1,}$/ ## skip "decorative" only heading e.g. ========
31
+
32
+ ## note: like in wikimedia markup (and markdown) all optional trailing ==== too
33
+ ## todo/check: allow === Text =-=-=-=-=-= too - why? why not?
34
+ if line =~ /^(={1,}) ## leading ======
35
+ ([^=]+?) ## text (note: for now no "inline" = allowed)
36
+ =* ## (optional) trailing ====
37
+ $/x
38
+ heading_marker = $1
39
+ heading_level = $1.length ## count number of = for heading level
40
+ heading = $2.strip
41
+
42
+ puts "heading #{heading_level} >#{heading}<"
43
+ outline << [:"h#{heading_level}", heading]
44
+ else
45
+ ## assume it's a (plain/regular) text line
46
+ outline << [:l, line]
47
+ end
48
+ end
49
+ outline
50
+ end # method read
51
+ end # class OutlineReader
52
+
53
+ end # module SportDb
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ module SportDb
5
+ module Formats
6
+
7
+ MAJOR = 0 ## todo: namespace inside version or something - why? why not??
8
+ MINOR = 0
9
+ PATCH = 1
10
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
11
+
12
+ def self.version
13
+ VERSION
14
+ end
15
+
16
+ def self.banner
17
+ "sportdb-formats/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
18
+ end
19
+
20
+ def self.root
21
+ File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )
22
+ end
23
+
24
+ end # module Formats
25
+ end # module SportDb
data/test/helper.rb ADDED
@@ -0,0 +1,8 @@
1
+ ## $:.unshift(File.dirname(__FILE__))
2
+
3
+ ## minitest setup
4
+ require 'minitest/autorun'
5
+
6
+
7
+ ## our own code
8
+ require 'sportdb/formats'
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_csv_reader.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestCsvReader < MiniTest::Test
11
+
12
+ def test_parse
13
+ recs = parse_csv( <<TXT )
14
+ ### World Countries
15
+
16
+ key, fifa, name
17
+ af, AFG, Afghanistan
18
+ al, ALB, Albania
19
+ dz, ALG, Algeria
20
+ as, ASA, American Samoa (US)
21
+ TXT
22
+
23
+ pp recs
24
+ assert_equal [{ key:'af', fifa:'AFG', name:'Afghanistan'},
25
+ { key:'al', fifa:'ALB', name:'Albania'},
26
+ { key:'dz', fifa:'ALG', name:'Algeria'},
27
+ { key:'as', fifa:'ASA', name:'American Samoa (US)'},
28
+ ], recs[0..3]
29
+ end
30
+
31
+ end # class TestCsvReader
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_outline_reader.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestOutlineReader < MiniTest::Test
11
+
12
+ def test_parse
13
+ outline = SportDb::OutlineReader.parse( <<TXT )
14
+ =============================
15
+ = ÖFB Cup 2011/12
16
+ =============================
17
+
18
+ FC Red Bull Salzburg ## Bundesliga
19
+ FK Austria Wien
20
+ TXT
21
+
22
+ pp outline
23
+
24
+ assert_equal 3, outline.size
25
+
26
+ assert_equal [:h1, 'ÖFB Cup 2011/12'], outline[0]
27
+ assert_equal [:l, 'FC Red Bull Salzburg'], outline[1]
28
+ assert_equal [:l, 'FK Austria Wien'], outline[2]
29
+ end
30
+
31
+ end # class TestOutlineReader
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sportdb-formats
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gerald Bauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-10-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: alphabets
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: csvreader
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.16'
69
+ description: sportdb-formats - sport.db format and text utilities
70
+ email: opensport@googlegroups.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files:
74
+ - CHANGELOG.md
75
+ - Manifest.txt
76
+ - README.md
77
+ files:
78
+ - CHANGELOG.md
79
+ - Manifest.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/sportdb/formats.rb
83
+ - lib/sportdb/formats/outline_reader.rb
84
+ - lib/sportdb/formats/version.rb
85
+ - test/helper.rb
86
+ - test/test_csv_reader.rb
87
+ - test/test_outline_reader.rb
88
+ homepage: https://github.com/sportdb/sport.db
89
+ licenses:
90
+ - Public Domain
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options:
94
+ - "--main"
95
+ - README.md
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 2.2.2
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.5.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: sportdb-formats - sport.db format and text utilities
114
+ test_files: []