sportdb 1.6.7 → 1.6.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,42 @@ class Person < ActiveRecord::Base
5
5
 
6
6
  has_many :goals
7
7
 
8
+ belongs_to :country, :class_name => 'WorldDb::Models::Country', :foreign_key => 'country_id'
9
+
10
+
11
+ def self.create_or_update_from_values( new_attributes, values )
12
+
13
+ ## fix: add/configure logger for ActiveRecord!!!
14
+ logger = LogKernel::Logger.root
15
+
16
+ ## check optional values
17
+ values.each_with_index do |value, index|
18
+ if value =~ /^[a-z]{2}$/ ## assume two-letter country key e.g. at,de,mx,etc.
19
+ value_country = Country.find_by_key!( value )
20
+ new_attributes[ :country_id ] = value_country.id
21
+ else
22
+ ## todo: assume title2 ??
23
+ ## assume title2 if title2 is empty (not already in use)
24
+ ## and if it title2 contains at least two letter e.g. [a-zA-Z].*[a-zA-Z]
25
+ # issue warning: unknown type for value
26
+ logger.warn "unknown type for value >#{value}< - key #{new_attributes[:key]}"
27
+ end
28
+ end
29
+
30
+ rec = Person.find_by_key( new_attributes[ :key ] )
31
+ if rec.present?
32
+ logger.debug "update Person #{rec.id}-#{rec.key}:"
33
+ else
34
+ logger.debug "create Person:"
35
+ rec = Person.new
36
+ end
37
+
38
+ logger.debug new_attributes.to_json
39
+
40
+ rec.update_attributes!( new_attributes )
41
+ end # create_or_update_from_values
42
+
43
+
8
44
  end # class Person
9
45
 
10
46
 
@@ -83,8 +83,12 @@ class Reader
83
83
  ## assume single fixture name
84
84
  name = rec
85
85
 
86
- if name =~ /^circuits/
86
+ if name =~ /^circuits/ # e.g. circuits.txt in formula1.db
87
87
  load_tracks( name )
88
+ elsif name =~ /^drivers/ # e.g. drivers.txt in formula1.db
89
+ load_persons( name )
90
+ elsif name =~ /^teams/ # e.g. teams.txt in formula1.db
91
+ load_teams( name )
88
92
  elsif name =~ /^seasons/
89
93
  load_seasons( name )
90
94
  elsif name =~ /^leagues/
@@ -174,6 +178,25 @@ class Reader
174
178
  end # load_tracks
175
179
 
176
180
 
181
+
182
+ def load_persons( name, more_values={} )
183
+
184
+ path = "#{include_path}/#{name}.txt"
185
+
186
+ logger.info "parsing data '#{name}' (#{path})..."
187
+
188
+ reader = ValuesReader.new( path, more_values )
189
+
190
+ reader.each_line do |new_attributes, values|
191
+ Person.create_or_update_from_values( new_attributes, values )
192
+ end # each lines
193
+
194
+ Prop.create_from_fixture!( name, path )
195
+
196
+ end # load_persons
197
+
198
+
199
+
177
200
  def load_seasons( name )
178
201
  path = "#{include_path}/#{name}.yml"
179
202
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  module SportDb
3
- VERSION = '1.6.7'
3
+ VERSION = '1.6.8'
4
4
  end
5
5
 
6
6
  ###########################################
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.7
4
+ version: 1.6.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-06-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: worlddb
16
- requirement: &73513280 !ruby/object:Gem::Requirement
16
+ requirement: &80599410 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.7'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *73513280
24
+ version_requirements: *80599410
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: commander
27
- requirement: &73513060 !ruby/object:Gem::Requirement
27
+ requirement: &80599190 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 4.1.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *73513060
35
+ version_requirements: *80599190
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &73512840 !ruby/object:Gem::Requirement
38
+ requirement: &80598970 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.10'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *73512840
46
+ version_requirements: *80598970
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: hoe
49
- requirement: &73512620 !ruby/object:Gem::Requirement
49
+ requirement: &80598750 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '3.3'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *73512620
57
+ version_requirements: *80598750
58
58
  description: sportdb - sport.db command line tool
59
59
  email: opensport@googlegroups.com
60
60
  executables: