persondb-models 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/HISTORY.md +4 -0
- data/Manifest.txt +17 -0
- data/README.md +34 -0
- data/Rakefile +31 -0
- data/lib/persondb/models.rb +71 -0
- data/lib/persondb/models/forward.rb +33 -0
- data/lib/persondb/models/person.rb +109 -0
- data/lib/persondb/models/world/city.rb +10 -0
- data/lib/persondb/models/world/country.rb +10 -0
- data/lib/persondb/models/world/region.rb +10 -0
- data/lib/persondb/reader.rb +52 -0
- data/lib/persondb/schema.rb +66 -0
- data/lib/persondb/version.rb +22 -0
- data/test/data/players/south-america/br-brazil/players.txt +39 -0
- data/test/helper.rb +28 -0
- data/test/test_models.rb +39 -0
- data/test/test_reader.rb +36 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d3da2b33fdafe18b96c185cc7917c19da383f99c
|
4
|
+
data.tar.gz: be15b5111437540510df731ad51315d97ed7de37
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d25360bbcfb330021ff1662838385e2b174fc61e0f2947e583e46b49e97b3977234f77f9d585f386aea4b6c853b18edbc5f57fde6619513ecbf070de360cc2d
|
7
|
+
data.tar.gz: a16843304349ee92544a26e01f26d8781dddc80f704afba593973732d9dc2b0c0d0bb56dad4df26dba77af5e6e193b9da637cb10092450cf1efb27ef386aa349
|
data/.gemtest
ADDED
File without changes
|
data/HISTORY.md
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
HISTORY.md
|
2
|
+
Manifest.txt
|
3
|
+
README.md
|
4
|
+
Rakefile
|
5
|
+
lib/persondb/models.rb
|
6
|
+
lib/persondb/models/forward.rb
|
7
|
+
lib/persondb/models/person.rb
|
8
|
+
lib/persondb/models/world/city.rb
|
9
|
+
lib/persondb/models/world/country.rb
|
10
|
+
lib/persondb/models/world/region.rb
|
11
|
+
lib/persondb/reader.rb
|
12
|
+
lib/persondb/schema.rb
|
13
|
+
lib/persondb/version.rb
|
14
|
+
test/data/players/south-america/br-brazil/players.txt
|
15
|
+
test/helper.rb
|
16
|
+
test/test_models.rb
|
17
|
+
test/test_reader.rb
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# persondb-models
|
2
|
+
|
3
|
+
persondb-models gem - person.db schema 'n' models for easy (re)use
|
4
|
+
|
5
|
+
* home :: [github.com/persondb/person.db.models](https://github.com/persondb/person.db.models)
|
6
|
+
* bugs :: [github.com/persondb/person.db.models/issues](https://github.com/persondb/person.db.models/issues)
|
7
|
+
* gem :: [rubygems.org/gems/persondb-models](https://rubygems.org/gems/persondb-models)
|
8
|
+
* rdoc :: [rubydoc.info/gems/persondb-models](http://rubydoc.info/gems/persondb-models)
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
TBD
|
13
|
+
|
14
|
+
## Alternatives
|
15
|
+
|
16
|
+
TBD
|
17
|
+
|
18
|
+
|
19
|
+
## Real World Usage
|
20
|
+
|
21
|
+
[wine.db](https://github.com/openwine) - Used for Winemakers
|
22
|
+
|
23
|
+
[football.db](https://github.com/openfootball) - Used for Football Players (Goalies, Defenders, Midfielders, etc.)
|
24
|
+
|
25
|
+
[ski.db](https://github.com/opensport/ski.db) - Use for Alpine Ski Racers
|
26
|
+
|
27
|
+
[forumula1.db](https://github.com/opensport/formula1.db) - Used for Formula 1 Race Drivers
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
The `persondb-models` scripts are dedicated to the public domain.
|
34
|
+
Use it as you please with no restrictions whatsoever.
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'hoe'
|
2
|
+
require './lib/persondb/version.rb'
|
3
|
+
|
4
|
+
Hoe.spec 'persondb-models' do
|
5
|
+
|
6
|
+
self.version = PersonDb::VERSION
|
7
|
+
|
8
|
+
self.summary = "persondb-models - person schema 'n' models for easy (re)use"
|
9
|
+
self.description = summary
|
10
|
+
|
11
|
+
self.urls = ['https://github.com/persondb/person.db.models']
|
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 = 'HISTORY.md'
|
19
|
+
|
20
|
+
self.extra_deps = [
|
21
|
+
['worlddb-models'] ## get all (extra) dependencies via worlddb-models
|
22
|
+
]
|
23
|
+
|
24
|
+
self.licenses = ['Public Domain']
|
25
|
+
|
26
|
+
self.spec_extras = {
|
27
|
+
required_ruby_version: '>= 1.9.2'
|
28
|
+
}
|
29
|
+
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
# 3rd party gems / libs
|
6
|
+
require 'worlddb/models' # note: let worlddb pull in all 3rd party gems / libs (do NOT duplicate here)
|
7
|
+
|
8
|
+
|
9
|
+
### our own code
|
10
|
+
|
11
|
+
require 'persondb/version' # let it always go first
|
12
|
+
require 'persondb/schema'
|
13
|
+
|
14
|
+
require 'persondb/models/forward'
|
15
|
+
|
16
|
+
require 'persondb/models/world/city'
|
17
|
+
require 'persondb/models/world/region'
|
18
|
+
require 'persondb/models/world/country'
|
19
|
+
|
20
|
+
require 'persondb/models/person'
|
21
|
+
require 'persondb/reader'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
module PersonDb
|
26
|
+
|
27
|
+
def self.test_data_path
|
28
|
+
"#{root}/test/data"
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def self.create
|
33
|
+
CreateDb.new.up
|
34
|
+
|
35
|
+
Model::Prop.create!( key: 'db.schema.person.version', value: VERSION )
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.delete!
|
39
|
+
## fix/todo: move into deleter class (see worlddb,sportdb etc.)
|
40
|
+
Model::Person.delete_all
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.tables
|
44
|
+
## fix/todo: move into stats class (see worlddb,sportdb etc.)
|
45
|
+
puts " #{Model::Person.count} persons"
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.setup_in_memory_db
|
49
|
+
# Database Setup & Config
|
50
|
+
|
51
|
+
ActiveRecord::Base.logger = Logger.new( STDOUT )
|
52
|
+
## ActiveRecord::Base.colorize_logging = false - no longer exists - check new api/config setting?
|
53
|
+
|
54
|
+
## NB: every connect will create a new empty in memory db
|
55
|
+
ActiveRecord::Base.establish_connection(
|
56
|
+
adapter: 'sqlite3',
|
57
|
+
database: ':memory:' )
|
58
|
+
|
59
|
+
## build schema
|
60
|
+
LogDb.create
|
61
|
+
ConfDb.create
|
62
|
+
TagDb.create
|
63
|
+
WorldDb.create
|
64
|
+
PersonDb.create
|
65
|
+
end # method setup_in_memory_db
|
66
|
+
|
67
|
+
|
68
|
+
end # module PersonDb
|
69
|
+
|
70
|
+
# say hello
|
71
|
+
puts PersonDb.banner if $DEBUG || (defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
### forward references
|
2
|
+
## require first to resolve circular references
|
3
|
+
|
4
|
+
module PersonDb
|
5
|
+
module Model
|
6
|
+
|
7
|
+
## todo: why? why not use include WorldDb::Models here???
|
8
|
+
Continent = WorldDb::Model::Continent
|
9
|
+
Country = WorldDb::Model::Country
|
10
|
+
Region = WorldDb::Model::Region
|
11
|
+
City = WorldDb::Model::City
|
12
|
+
|
13
|
+
Tagging = TagDb::Model::Tagging
|
14
|
+
Tag = TagDb::Model::Tag
|
15
|
+
|
16
|
+
Prop = ConfDb::Model::Prop
|
17
|
+
|
18
|
+
class Person < ActiveRecord::Base ; end
|
19
|
+
|
20
|
+
end # module Model
|
21
|
+
|
22
|
+
## note: for convenciene (and compatibility) add alias Models for Model namespace
|
23
|
+
## e.g lets you use include PersonDb::Models
|
24
|
+
Models = Model
|
25
|
+
|
26
|
+
end # module PersonDb
|
27
|
+
|
28
|
+
|
29
|
+
module WorldDb
|
30
|
+
module Model
|
31
|
+
Person = PersonDb::Model::Person
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module PersonDb
|
4
|
+
module Model
|
5
|
+
|
6
|
+
class Person < ActiveRecord::Base
|
7
|
+
|
8
|
+
self.table_name = 'persons'
|
9
|
+
|
10
|
+
def title() name end # alias for name
|
11
|
+
def title=(value) self.name = value end # alias for name
|
12
|
+
|
13
|
+
|
14
|
+
def self.create_or_update_from_values( new_attributes, values )
|
15
|
+
|
16
|
+
## fix: add/configure logger for ActiveRecord!!!
|
17
|
+
logger = LogKernel::Logger.root
|
18
|
+
|
19
|
+
## check optional values
|
20
|
+
values.each_with_index do |value, index|
|
21
|
+
if value =~ /^[a-z]{2}$/ ## assume two-letter country key e.g. at,de,mx,etc.
|
22
|
+
value_country = Country.find_by_key!( value )
|
23
|
+
new_attributes[ :country_id ] = value_country.id
|
24
|
+
elsif value =~ /^[A-Z]{3}$/ ## assume three-letter code e.g. AUS, MAL, etc.
|
25
|
+
new_attributes[ :code ] = value
|
26
|
+
|
27
|
+
#### fix: use more generic/better date reader (allow more formats!!!)
|
28
|
+
elsif value =~ /^([0-9]{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s([0-9]{4})$/ ## assume birthday
|
29
|
+
value_date_str = '%02d/%s/%d' % [$1, $2, $3] ## move to matcher!!
|
30
|
+
value_date = Date.strptime( value_date_str, '%d/%b/%Y' ) ## %b - abbreviated month name (e.g. Jan,Feb, etc.)
|
31
|
+
logger.debug " birthday #{value_date_str} - #{value_date}"
|
32
|
+
new_attributes[ :born_at ] = value_date
|
33
|
+
## todo: convert to date
|
34
|
+
else
|
35
|
+
## todo: assume title2 ??
|
36
|
+
## assume title2 if title2 is empty (not already in use)
|
37
|
+
## and if it title2 contains at least two letter e.g. [a-zA-Z].*[a-zA-Z]
|
38
|
+
# issue warning: unknown type for value
|
39
|
+
logger.warn "unknown type for value >#{value}< - key #{new_attributes[:key]}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
## quick hack: set nationality_id if not present to country_id
|
44
|
+
if new_attributes[ :nationality_id ].blank?
|
45
|
+
new_attributes[ :nationality_id ] = new_attributes[ :country_id ]
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
####################################################
|
50
|
+
# title-ize / normal-ize names (titles/synonyms)
|
51
|
+
|
52
|
+
##
|
53
|
+
## make sure title and synonyms do NOT use all UPPERCASE
|
54
|
+
## e.g. convert Neymar DA SILVA SANTOS to Neymar Da Sliva Santos etc.
|
55
|
+
|
56
|
+
### fix: add auto camelcase/titlecase
|
57
|
+
## move to textutils
|
58
|
+
## make it an option for name to auto Camelcase/titlecase?
|
59
|
+
## e.g. BONFIM COSTA SANTOS becomes
|
60
|
+
## Bonfim Costa Santos etc.
|
61
|
+
## fix: better move into person parser?
|
62
|
+
## store all alt_names titleized!!!
|
63
|
+
|
64
|
+
raw_title = new_attributes[ :title ]
|
65
|
+
new_title = titleize( raw_title )
|
66
|
+
if raw_title != new_title
|
67
|
+
logger.debug " change person title/name to <#{new_title}> from >#{raw_title}<"
|
68
|
+
new_attributes[ :title ] = new_title
|
69
|
+
end
|
70
|
+
|
71
|
+
raw_synonyms = new_attributes[ :synonyms ]
|
72
|
+
if raw_synonyms.present?
|
73
|
+
new_synonyms = raw_synonyms.split('|').map { |value| titleize(value) }.join('|')
|
74
|
+
|
75
|
+
if raw_synonyms != new_synonyms
|
76
|
+
logger.debug " change person synonyms/alt_names to <#{new_synonyms}> from >#{raw_synonyms}<"
|
77
|
+
new_attributes[ :synonyms ] = new_synonyms
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
rec = Person.find_by_key( new_attributes[ :key ] )
|
84
|
+
if rec.present?
|
85
|
+
logger.debug "update Person #{rec.id}-#{rec.key}:"
|
86
|
+
else
|
87
|
+
logger.debug "create Person:"
|
88
|
+
rec = Person.new
|
89
|
+
end
|
90
|
+
|
91
|
+
logger.debug new_attributes.to_json
|
92
|
+
|
93
|
+
rec.update_attributes!( new_attributes )
|
94
|
+
end # create_or_update_from_values
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
|
99
|
+
def self.titleize( str ) # note: added as class-level method for self.create etc.
|
100
|
+
## fix: for now works only with ASCII only
|
101
|
+
## words 2 letters and ups
|
102
|
+
## fix also allow words w/ quote e.g. O'Connor etc.
|
103
|
+
str.gsub(/\b[A-Z]{2,}\b/) { |match| match.capitalize }
|
104
|
+
end
|
105
|
+
|
106
|
+
end # class Person
|
107
|
+
|
108
|
+
end # module Model
|
109
|
+
end # module PersonDb
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
module PersonDb
|
5
|
+
|
6
|
+
|
7
|
+
class PersonReader
|
8
|
+
|
9
|
+
include LogUtils::Logging
|
10
|
+
|
11
|
+
## make models available by default with namespace
|
12
|
+
# e.g. lets you use Usage instead of Model::Usage
|
13
|
+
include Models
|
14
|
+
|
15
|
+
def self.from_zip( zip_file, entry_path, more_attribs={} )
|
16
|
+
## get text content from zip
|
17
|
+
entry = zip_file.find_entry( entry_path )
|
18
|
+
|
19
|
+
text = entry.get_input_stream().read()
|
20
|
+
text = text.force_encoding( Encoding::UTF_8 )
|
21
|
+
|
22
|
+
self.from_string( text, more_attribs )
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.from_file( path, more_attribs={} )
|
26
|
+
## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
|
27
|
+
## - see textutils/utils.rb
|
28
|
+
text = File.read_utf8( path )
|
29
|
+
self.from_string( text, more_attribs )
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.from_string( text, more_attribs={} )
|
33
|
+
PersonReader.new( text, more_attribs )
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def initialize( text, more_attribs={} )
|
38
|
+
## todo/fix: how to add opts={} ???
|
39
|
+
@text = text
|
40
|
+
@more_attribs = more_attribs
|
41
|
+
end
|
42
|
+
|
43
|
+
def read()
|
44
|
+
reader = ValuesReader.from_string( @text, @more_attribs )
|
45
|
+
|
46
|
+
reader.each_line do |new_attributes, values|
|
47
|
+
Person.create_or_update_from_values( new_attributes, values )
|
48
|
+
end # each lines
|
49
|
+
end
|
50
|
+
|
51
|
+
end # class PersonReader
|
52
|
+
end # module PersonDb
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module PersonDb
|
4
|
+
|
5
|
+
class CreateDb
|
6
|
+
|
7
|
+
def up
|
8
|
+
ActiveRecord::Schema.define do
|
9
|
+
|
10
|
+
###########
|
11
|
+
# use people ? instead of persons (person/persons makes it easier?)
|
12
|
+
|
13
|
+
create_table :persons do |t|
|
14
|
+
t.string :key, null: false # import/export key
|
15
|
+
t.string :name, null: false
|
16
|
+
t.string :synonyms # comma separated list of synonyms
|
17
|
+
### fix: change to alt_names
|
18
|
+
|
19
|
+
t.string :code # three letter code (short title) e.g used for formula1 driver etc.
|
20
|
+
|
21
|
+
|
22
|
+
## todo: add gender flag (male/female -man/lady how?)
|
23
|
+
t.date :born_at # optional date of birth (birthday)
|
24
|
+
## todo: add country of birth might not be the same as nationality
|
25
|
+
|
26
|
+
t.references :city
|
27
|
+
t.references :region
|
28
|
+
t.references :country ## , null: false
|
29
|
+
|
30
|
+
t.references :nationality ## , null: false # by default assume same as country of birth (see above)
|
31
|
+
## fix: add nationality2 n nationality3 too
|
32
|
+
|
33
|
+
t.timestamps
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
end # Schema.define
|
38
|
+
end # method up
|
39
|
+
|
40
|
+
end # class CreateDb
|
41
|
+
|
42
|
+
end # module PersonDb
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
=begin
|
47
|
+
# old (original) sportdb persons table
|
48
|
+
create_table :persons do |t| # use people ? instead of persons (person/persons makes it easier?)
|
49
|
+
t.string :key, null: false # import/export key
|
50
|
+
t.string :name, null: false
|
51
|
+
t.string :synonyms # comma separated list of synonyms
|
52
|
+
t.string :code # three letter code (short title)
|
53
|
+
|
54
|
+
## todo: add gender flag (male/female -man/lady how?)
|
55
|
+
t.date :born_at # optional date of birth (birthday)
|
56
|
+
## todo: add country of birth might not be the same as nationality
|
57
|
+
|
58
|
+
t.references :city
|
59
|
+
t.references :region
|
60
|
+
t.references :country, null: false
|
61
|
+
|
62
|
+
t.references :nationality, null: false # by default assume same as country of birth (see above)
|
63
|
+
|
64
|
+
t.timestamps
|
65
|
+
end
|
66
|
+
=end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PersonDb
|
4
|
+
|
5
|
+
MAJOR = 0 ## todo: namespace inside version or something - why? why not??
|
6
|
+
MINOR = 4
|
7
|
+
PATCH = 2
|
8
|
+
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
9
|
+
|
10
|
+
def self.version
|
11
|
+
VERSION
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.banner
|
15
|
+
"persondb-models/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.root
|
19
|
+
"#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
|
20
|
+
end
|
21
|
+
|
22
|
+
end # module PersonDb
|
@@ -0,0 +1,39 @@
|
|
1
|
+
###
|
2
|
+
# NB: let official (player) shirt name go first (e.g. Neymar Jr)
|
3
|
+
|
4
|
+
|
5
|
+
## GK / Goalkeepers
|
6
|
+
|
7
|
+
Jefferson|Jefferson DE OLIVEIRA GALVAO, 2 Jan 1983, 190
|
8
|
+
Júlio César|Júlio César SOARES DE ESPINDOLA, 3 Sep 1979, 186
|
9
|
+
D. Cavalieri|Diego CAVALIERI, 1 Dec 1982, 189
|
10
|
+
|
11
|
+
|
12
|
+
## DF / Defenders
|
13
|
+
|
14
|
+
Dani Alves|Daniel ALVES DA SILVA, 6 May 1983, 172
|
15
|
+
T. Silva|Thiago SILVA|Thiago EMILIANO DA SILVA, 22 Sep 1984, 183
|
16
|
+
David Luiz, David Luiz MOREIRA MARINHO, 22 Apr 1987, 189
|
17
|
+
Marcelo|Marcelo VIEIRA DA SILVA JUNIOR, 12 May 1988, 174
|
18
|
+
Dante|Dante BONFIM COSTA SANTOS, 18 Oct 1983, 188
|
19
|
+
Filipe Luís|Filipe Luís KASMIRSKI, 9 Aug 1985, 182
|
20
|
+
Réver|Réver Humberto ALVES ARAUJO, 4 Jan 1985, 192
|
21
|
+
|
22
|
+
## MF / Midfielders
|
23
|
+
|
24
|
+
Fernando|Fernando Lucas MARTINS, 3 Mar 1992, 175
|
25
|
+
Lucas|Lucas RODRIGUES MOURA SILVA, 13 Aug 1992, 173
|
26
|
+
Hernanes|Anderson Hernanes DE CARVALHO VIANA LIMA, 29 May 1985, 180
|
27
|
+
Oscar|Oscar DOS SANTOS EMBOABA JUNIOR, 9 Sep 1991, 180
|
28
|
+
Jean|Jean Raphael VANDERLEI MOREIRA, 24 Jun 1986, 170
|
29
|
+
L. Gustavo|Luiz Gustavo|Luiz Gustavo DIAS, 23 Jul 1987, 186
|
30
|
+
Paulinho|José Paulo BEZERRA MACIEL JUNIOR, 25 Jul 1988, 182
|
31
|
+
Bernard|Bernard ANICIO CALDEIRA DUARTE, 8 Sep 1992, 164
|
32
|
+
Jádson|Jádson RODRIGUES, 5 Oct 1983, 169
|
33
|
+
|
34
|
+
## FW / Forwards
|
35
|
+
|
36
|
+
Fred|Frederico CHAVES GUEDES, 3 Oct 1983, 185
|
37
|
+
Neymar Jr|Neymar|Neymar DA SILVA SANTOS JUNIOR, 5 Feb 1992, 174
|
38
|
+
Hulk|Givanildo VIEIRA DE SOUSA, 25 Jul 1986, 180
|
39
|
+
Jô|João Alves de Assis Silva, 20 Mar 1987
|
data/test/helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
## $:.unshift(File.dirname(__FILE__))
|
4
|
+
|
5
|
+
## minitest setup
|
6
|
+
require 'minitest/autorun'
|
7
|
+
|
8
|
+
# our own code
|
9
|
+
|
10
|
+
require 'persondb/models'
|
11
|
+
|
12
|
+
|
13
|
+
################
|
14
|
+
# shortcuts
|
15
|
+
Country = WorldDb::Model::Country
|
16
|
+
Region = WorldDb::Model::Region
|
17
|
+
City = WorldDb::Model::City
|
18
|
+
|
19
|
+
## todo: get all models aliases (e.g. from console script)
|
20
|
+
|
21
|
+
Person = PersonDb::Model::Person
|
22
|
+
PersonReader = PersonDb::PersonReader
|
23
|
+
|
24
|
+
|
25
|
+
############
|
26
|
+
# setup
|
27
|
+
PersonDb.setup_in_memory_db
|
28
|
+
|
data/test/test_models.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
require 'helper'
|
5
|
+
|
6
|
+
|
7
|
+
class TestModels < MiniTest::Test
|
8
|
+
|
9
|
+
def setup # runs before every test
|
10
|
+
PersonDb.delete! # always clean-out tables
|
11
|
+
WorldDb.delete!
|
12
|
+
add_world
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_world
|
16
|
+
## add some counties
|
17
|
+
at = Country.create!( key: 'at', title: 'Austria', code: 'AUT', pop: 0, area: 0 )
|
18
|
+
n = Region.create!( key: 'n', title: 'Niederösterreich', country_id: at.id )
|
19
|
+
feuersbrunn = City.create!( key: 'feuersbrunn', title: 'Feuersbrunn', country_id: at.id, region_id: n.id )
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def test_worlddb_assocs
|
24
|
+
at = Country.find_by_key!( 'at' )
|
25
|
+
n = Region.find_by_key!( 'n' )
|
26
|
+
feuersbrunn = City.find_by_key!( 'feuersbrunn' )
|
27
|
+
|
28
|
+
assert_equal 0, at.persons.count
|
29
|
+
assert_equal 0, n.persons.count
|
30
|
+
assert_equal 0, feuersbrunn.persons.count
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_count
|
34
|
+
assert_equal 0, Person.count
|
35
|
+
|
36
|
+
PersonDb.tables # print stats
|
37
|
+
end
|
38
|
+
|
39
|
+
end # class TestModels
|
data/test/test_reader.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
|
6
|
+
class TestReader < MiniTest::Test
|
7
|
+
|
8
|
+
def setup # runs before every test
|
9
|
+
PersonDb.delete! # always clean-out tables
|
10
|
+
WorldDb.delete!
|
11
|
+
add_world
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_world
|
15
|
+
## add some counties
|
16
|
+
Country.create!( key: 'br', title: 'Brazil', code: 'BRA', pop: 0, area: 0 )
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_read
|
20
|
+
br = Country.find_by_key!( 'br' )
|
21
|
+
|
22
|
+
path = "#{PersonDb.test_data_path}/players/south-america/br-brazil/players.txt"
|
23
|
+
reader = PersonReader.from_file( path, country_id: br.id )
|
24
|
+
reader.read()
|
25
|
+
|
26
|
+
assert_equal 23, Person.count
|
27
|
+
assert_equal 23, br.persons.count
|
28
|
+
|
29
|
+
jefferson = Person.find_by_key!( 'jefferson' )
|
30
|
+
assert_equal 'Jefferson De Oliveira Galvao', jefferson.synonyms
|
31
|
+
## todo: add more asserts - use assert_persons ?
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end # class TestReader
|
36
|
+
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: persondb-models
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gerald Bauer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: worlddb-models
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: hoe
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.13'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.13'
|
55
|
+
description: persondb-models - person schema 'n' models for easy (re)use
|
56
|
+
email: opensport@googlegroups.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files:
|
60
|
+
- HISTORY.md
|
61
|
+
- Manifest.txt
|
62
|
+
- README.md
|
63
|
+
files:
|
64
|
+
- ".gemtest"
|
65
|
+
- HISTORY.md
|
66
|
+
- Manifest.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/persondb/models.rb
|
70
|
+
- lib/persondb/models/forward.rb
|
71
|
+
- lib/persondb/models/person.rb
|
72
|
+
- lib/persondb/models/world/city.rb
|
73
|
+
- lib/persondb/models/world/country.rb
|
74
|
+
- lib/persondb/models/world/region.rb
|
75
|
+
- lib/persondb/reader.rb
|
76
|
+
- lib/persondb/schema.rb
|
77
|
+
- lib/persondb/version.rb
|
78
|
+
- test/data/players/south-america/br-brazil/players.txt
|
79
|
+
- test/helper.rb
|
80
|
+
- test/test_models.rb
|
81
|
+
- test/test_reader.rb
|
82
|
+
homepage: https://github.com/persondb/person.db.models
|
83
|
+
licenses:
|
84
|
+
- Public Domain
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options:
|
88
|
+
- "--main"
|
89
|
+
- README.md
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.9.2
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.4.2
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: persondb-models - person schema 'n' models for easy (re)use
|
108
|
+
test_files:
|
109
|
+
- test/test_models.rb
|
110
|
+
- test/test_reader.rb
|