sportdb-models 1.16.1 → 1.16.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
2
  SHA1:
3
- metadata.gz: 10615c8f4aae44186f6e58fe21226b4c36dade4a
4
- data.tar.gz: 4c990c6e759d0d75e759f15be206932583473e82
3
+ metadata.gz: 3e6613873f974d76aac5c937bed28e683c16622d
4
+ data.tar.gz: 4c08c536d892a0796aa39e102dd90064f5ab9e95
5
5
  SHA512:
6
- metadata.gz: 0cf4c1dce575fd254f783b0434e29e6a1b61d5dd9451c29c7fbf553a1795e6df006c98d4f74937165db5291be1ddf00da510dc2ff07df2ea78dd5d93ef70dc3c
7
- data.tar.gz: 951f5e611560a39e7287377dff861d5c596c08b8e51694518d62f7ca7571fcb1cbf8ae1c373ac5bf5a6ddbc6bff92a201e919b32c665b591e61f71e27943407a
6
+ metadata.gz: 6560646347df56c45606bfb2cf6c034e229d72822f3bb80ffc0e1b782ed7b14dec0d8c2ae1a4589112a4eccb9e8c0ce46b5752c3f8c112ed357d8b772ff6cd6a
7
+ data.tar.gz: 93241e25ca9f4e382094bacb3e147346bfb12e0a8e2cfc6db9b31b14898a2e91397308108d6c435267006ad302a3335c3e24df6761bd3c142ba677347b687696
data/Manifest.txt CHANGED
@@ -17,6 +17,7 @@ lib/sportdb/deleter.rb
17
17
  lib/sportdb/finders/date.rb
18
18
  lib/sportdb/finders/goals.rb
19
19
  lib/sportdb/finders/scores.rb
20
+ lib/sportdb/indexers/team.rb
20
21
  lib/sportdb/lang.rb
21
22
  lib/sportdb/mapper_teams.rb
22
23
  lib/sportdb/matcher.rb
@@ -151,6 +152,7 @@ test/test_event_meta_reader.rb
151
152
  test/test_event_reader.rb
152
153
  test/test_event_table_reader.rb
153
154
  test/test_goals.rb
155
+ test/test_indexer_team.rb
154
156
  test/test_lang.rb
155
157
  test/test_load.rb
156
158
  test/test_pp.rb
@@ -0,0 +1,87 @@
1
+ # encoding: UTF-8
2
+
3
+ module SportDb
4
+
5
+
6
+ ##
7
+ # todo/check:
8
+ # simply add index() method to TeamReader (and remove this class) - why? why not??
9
+
10
+
11
+ class TeamIndexer
12
+
13
+ include LogUtils::Logging
14
+
15
+ ## make models available by default with namespace
16
+ # e.g. lets you use Usage instead of Model::Usage
17
+ include Models
18
+
19
+
20
+ def self.from_file( path, more_attribs={} )
21
+ ## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
22
+ ## - see textutils/utils.rb
23
+ text = File.read_utf8( path )
24
+ self.from_string( text, more_attribs )
25
+ end
26
+
27
+ def self.from_string( text, more_attribs={} )
28
+ self.new( text, more_attribs )
29
+ end
30
+
31
+ def initialize( text, more_attribs={} )
32
+ ## todo/fix: how to add opts={} ???
33
+ @text = text
34
+ @more_attribs = more_attribs
35
+ end
36
+
37
+
38
+ def read
39
+ ## return a hash (with all records) e.g.
40
+ ## {"austria"=>
41
+ ## {:title=>"FK Austria Wien",
42
+ ## :synonyms=>["Austria Wien", "Austria"],
43
+ ## :values=>
44
+ ## ["1911",
45
+ ## "AUS",
46
+ ## "www.fk-austria.at",
47
+ ## "Fischhofgasse 12 // 1100 Wien",
48
+ ## "city:wien"]},
49
+ ## "rapid"=>
50
+ ## {:title=>"SK Rapid Wien",
51
+ ## :synonyms=>["Rapid Wien", "Rapid"],
52
+ ## :values=>
53
+ ## ["1899",
54
+ ## "RAP",
55
+ ## "www.skrapid.at",
56
+ ## "Keisslergasse 3 // 1140 Wien",
57
+ ## "city:wien"]},
58
+ ## ...
59
+
60
+ reader = ValuesReader.from_string( @text, @more_attribs )
61
+
62
+ h = {}
63
+
64
+ reader.each_line do |new_attributes, values|
65
+ puts "attribs:"
66
+ pp new_attributes
67
+
68
+ key = new_attributes.delete( :key ) ## remove key
69
+
70
+ ## turn synonyms into an array
71
+ synonyms = new_attributes[ :synonyms ]
72
+ if synonyms
73
+ new_attributes[ :synonyms ] = synonyms.split('|')
74
+ end
75
+
76
+ new_attributes[ :values ] = values
77
+
78
+ h[ key ] = new_attributes
79
+
80
+ end # each lines
81
+
82
+ h ## return hash with all records (indexed by key)
83
+ end
84
+
85
+
86
+ end # class TeamIndexer
87
+ end # module SportDb
@@ -85,6 +85,7 @@ require 'sportdb/reader'
85
85
  require 'sportdb/reader_file'
86
86
  require 'sportdb/reader_zip'
87
87
 
88
+ require 'sportdb/indexers/team'
88
89
 
89
90
 
90
91
  require 'sportdb/lang'
@@ -4,7 +4,7 @@ module SportDb
4
4
 
5
5
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
6
6
  MINOR = 16
7
- PATCH = 1
7
+ PATCH = 2
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
data/test/helper.rb CHANGED
@@ -46,6 +46,7 @@ AlltimeStandingEntry = SportDb::Model::AlltimeStandingEntry
46
46
 
47
47
  Reader = SportDb::Reader
48
48
  TeamReader = SportDb::TeamReader
49
+ TeamIndexer = SportDb::TeamIndexer
49
50
  AssocReader = SportDb::AssocReader
50
51
  SeasonReader = SportDb::SeasonReader
51
52
  LeagueReader = SportDb::LeagueReader
@@ -77,6 +78,13 @@ module TestTeamReader
77
78
  end
78
79
  end
79
80
 
81
+ module TestTeamIndexer
82
+ def self.from_file( name, more_attribs={} )
83
+ TeamIndexer.from_file( "#{SportDb.test_data_path}/#{name}.txt", more_attribs )
84
+ end
85
+ end
86
+
87
+
80
88
  module TestClubSquadReader
81
89
  def self.from_file( name, more_attribs={} )
82
90
  ClubSquadReader.from_file( "#{SportDb.test_data_path}/#{name}.txt", more_attribs )
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_indexer_team.rb
6
+ # or better
7
+ # rake -I ./lib test
8
+
9
+
10
+ require 'helper'
11
+
12
+ class TestTeamIndexerXX < MiniTest::Test ## note: TestTeamIndexer already exists
13
+
14
+ def setup
15
+ WorldDb.delete!
16
+ SportDb.delete!
17
+ SportDb.read_builtin
18
+ end
19
+
20
+ def test_bl
21
+ at = Country.create!( key: 'at', name: 'Austria', code: 'AUT', pop: 1, area: 1)
22
+
23
+ indexer = TestTeamIndexer.from_file( 'at-austria/teams', country_id: at.id )
24
+ h = indexer.read()
25
+
26
+ pp h
27
+
28
+ ## indexer = TestTeamIndexer.from_file( 'at-austria/teams_2', country_id: at.id )
29
+ ## indexer.read()
30
+
31
+ assert true ## assume everthing ok
32
+ end
33
+
34
+ end # class TestTeamIndexerXX
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.1
4
+ version: 1.16.2
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-12-10 00:00:00.000000000 Z
11
+ date: 2015-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: worlddb-models
@@ -94,6 +94,7 @@ files:
94
94
  - lib/sportdb/finders/date.rb
95
95
  - lib/sportdb/finders/goals.rb
96
96
  - lib/sportdb/finders/scores.rb
97
+ - lib/sportdb/indexers/team.rb
97
98
  - lib/sportdb/lang.rb
98
99
  - lib/sportdb/mapper_teams.rb
99
100
  - lib/sportdb/matcher.rb
@@ -228,6 +229,7 @@ files:
228
229
  - test/test_event_reader.rb
229
230
  - test/test_event_table_reader.rb
230
231
  - test/test_goals.rb
232
+ - test/test_indexer_team.rb
231
233
  - test/test_lang.rb
232
234
  - test/test_load.rb
233
235
  - test/test_pp.rb