worlddb 1.8.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/{History.md → HISTORY.md} +0 -0
  3. data/Manifest.txt +22 -5
  4. data/README.md +62 -2
  5. data/Rakefile +14 -6
  6. data/lib/worlddb.rb +34 -12
  7. data/lib/worlddb/cli/main.rb +159 -111
  8. data/lib/worlddb/cli/opts.rb +15 -48
  9. data/lib/worlddb/console.rb +6 -5
  10. data/lib/worlddb/deleter.rb +5 -3
  11. data/lib/worlddb/matcher.rb +16 -5
  12. data/lib/worlddb/models/city.rb +66 -30
  13. data/lib/worlddb/models/city_comp.rb +27 -0
  14. data/lib/worlddb/models/continent.rb +30 -8
  15. data/lib/worlddb/models/continent_comp.rb +24 -0
  16. data/lib/worlddb/models/country.rb +60 -36
  17. data/lib/worlddb/models/country_comp.rb +29 -0
  18. data/lib/worlddb/models/forward.rb +53 -0
  19. data/lib/worlddb/models/lang.rb +9 -7
  20. data/lib/worlddb/models/lang_comp.rb +23 -0
  21. data/lib/worlddb/models/name.rb +13 -0
  22. data/lib/worlddb/models/place.rb +16 -0
  23. data/lib/worlddb/models/region.rb +34 -12
  24. data/lib/worlddb/models/region_comp.rb +26 -0
  25. data/lib/worlddb/models/tagdb/tag.rb +16 -0
  26. data/lib/worlddb/models/tagdb/tagging.rb +15 -0
  27. data/lib/worlddb/models/usage.rb +10 -6
  28. data/lib/worlddb/reader.rb +31 -158
  29. data/lib/worlddb/readers/base.rb +41 -0
  30. data/lib/worlddb/readers/city.rb +18 -0
  31. data/lib/worlddb/readers/country.rb +17 -0
  32. data/lib/worlddb/readers/lang.rb +43 -0
  33. data/lib/worlddb/readers/region.rb +17 -0
  34. data/lib/worlddb/readers/usage.rb +35 -0
  35. data/lib/worlddb/schema.rb +100 -65
  36. data/lib/worlddb/stats.rb +9 -3
  37. data/lib/worlddb/utils.rb +3 -0
  38. data/lib/worlddb/version.rb +1 -6
  39. data/test/helper.rb +13 -3
  40. data/test/test_model_city.rb +60 -0
  41. data/test/test_model_comp.rb +48 -0
  42. data/test/test_model_country.rb +43 -0
  43. data/test/test_model_region.rb +50 -0
  44. data/test/test_models.rb +35 -0
  45. metadata +113 -37
  46. data/lib/worlddb/models/prop.rb +0 -32
  47. data/lib/worlddb/models/tag.rb +0 -33
  48. data/lib/worlddb/models/tagging.rb +0 -13
  49. data/test/test_values.rb +0 -114
@@ -1,32 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module WorldDb::Model
4
-
5
- class Prop < ActiveRecord::Base
6
-
7
- def self.create_from_fixture!( name, path )
8
- key = "db.#{fixture_name_to_prop_key(name)}.version"
9
-
10
- value = "txt.#{File.mtime(path).strftime('%Y.%m.%d')}"
11
-
12
- Prop.create!( key: key, value: value )
13
- end
14
-
15
- private
16
-
17
- # helper
18
- # change at/2012_13/bl to at.2012/13.bl
19
- # or quali_2012_13_europe_c to quali.2012/13.europe.c
20
-
21
- def self.fixture_name_to_prop_key( name )
22
- prop_key = name.gsub( '/', '.' )
23
- prop_key = prop_key.gsub( /(\d{4})_(\d{2})/, '\1/\2' ) # 2012_13 => 2012/13
24
- prop_key = prop_key.gsub( '_', '.' )
25
- prop_key
26
- end
27
-
28
-
29
- end # class Prop
30
-
31
- end # module WorldDb::Model
32
-
@@ -1,33 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module WorldDb::Model
4
-
5
- class Tag < ActiveRecord::Base
6
-
7
- has_many :taggings
8
-
9
- has_many :cities, :through => :taggings, :source => :taggable, :source_type => 'WorldDb::Model::City', :class_name => 'City'
10
- has_many :countries, :through => :taggings, :source => :taggable, :source_type => 'WorldDb::Model::Country', :class_name => 'Country'
11
- has_many :regions, :through => :taggings, :source => :taggable, :source_type => 'WorldDb::Model::Region', :class_name => 'Region'
12
-
13
- ## nb: only allow spaces and underscore inbetween; do not allow digit as first char
14
- validates :key, :format => { :with => /^[a-z]$|^[a-z][a-z0-9_ ]*[a-z0-9]$/, :message => 'expected one or more lowercase letters a-z or 0-9 digits or space or underscore' }
15
-
16
- scope :by_key, order( 'key desc' )
17
- scope :by_title, order( 'title desc' )
18
- scope :top, where( 'grade=1' )
19
-
20
- before_save :on_before_save
21
-
22
- def on_before_save
23
- # replace space with underscore e.g. north america becomes north_america and so on
24
- self.slug = key.gsub( ' ', '_' )
25
-
26
- ## if title is empty auto fill w/ key
27
- self.title = key if title.blank?
28
- end
29
-
30
- end # class Tag
31
-
32
- end # module WorldDb::Model
33
-
@@ -1,13 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module WorldDb::Model
4
-
5
- class Tagging < ActiveRecord::Base
6
-
7
- belongs_to :tag
8
- belongs_to :taggable, :polymorphic => true
9
-
10
- end # class Tagging
11
-
12
- end # module WorldDb::Model
13
-
@@ -1,114 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_helper.rb
6
- # or better
7
- # rake test
8
-
9
- require 'helper'
10
-
11
- class TestValues < MiniTest::Unit::TestCase
12
-
13
- def setup
14
- # delete all countries, regions, cities in in-memory only db
15
- WorldDb.delete!
16
- end
17
-
18
- def test_load_country_values
19
-
20
- new_attributes = {
21
- key: 'at',
22
- title: 'Austria',
23
- synonyms: ''
24
- }
25
-
26
- values = [
27
- 'AUT',
28
- '83_871',
29
- '8_414_638',
30
- 'un|fifa|uefa|eu|euro|schengen|central_europe|western_europe'
31
- ]
32
-
33
- c = Country.create_or_update_from_attribs( new_attributes, values )
34
-
35
- c2 = Country.find_by_key!( new_attributes[:key] )
36
- assert_equal c.id, c2.id
37
-
38
- assert_equal c.title, new_attributes[:title]
39
- assert_equal c.pop, 8_414_638
40
- assert_equal c.area, 83_871
41
- ## todo: assert tag count; add supra:eu etc.
42
- end
43
-
44
- def test_load_region_values
45
-
46
- at = Country.create!( key: 'at',
47
- title: 'Austria',
48
- code: 'AUT',
49
- pop: 8_414_638,
50
- area: 83_871 )
51
-
52
- new_attributes = {
53
- key: 'w',
54
- title: 'Wien',
55
- synonyms: '',
56
- country_id: at.id
57
- }
58
-
59
- values = [
60
- '415 km²',
61
- 'eastern austria'
62
- ]
63
-
64
- r = Region.create_or_update_from_attribs( new_attributes, values )
65
-
66
- r2 = Region.find_by_key!( new_attributes[:key] )
67
- assert_equal r.id, r2.id
68
-
69
- assert_equal r.title, new_attributes[:title]
70
- assert_equal r.area, 415
71
- ## todo: assert country_id & country.title for assoc
72
- end
73
-
74
- def test_load_city_values
75
-
76
- at = Country.create!( key: 'at',
77
- title: 'Austria',
78
- code: 'AUT',
79
- pop: 8_414_638,
80
- area: 83_871 )
81
-
82
- w = Region.create!( key: 'w',
83
- title: 'Wien',
84
- country_id: at.id )
85
-
86
- new_attributes = {
87
- key: 'wien',
88
- title: 'Wien',
89
- synonyms: '',
90
- country_id: at.id
91
- }
92
-
93
- values = [
94
- 'W',
95
- '1_731_236',
96
- 'm:1_724_000'
97
- ]
98
-
99
- c = City.create_or_update_from_attribs( new_attributes, values )
100
-
101
- c2 = City.find_by_key!( new_attributes[:key] )
102
- assert_equal c.id, c2.id
103
-
104
- assert_equal c.title, new_attributes[:title]
105
- assert_equal c.pop, 1_731_236
106
- assert_equal c.popm, 1_724_000
107
- assert_equal c.m, true
108
- assert_equal c.region_id, w.id
109
- assert_equal c.country_id, at.id
110
- end
111
-
112
-
113
- end # class TestValues
114
-