worlddb 2.0.1 → 2.0.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: 6b65594f88cfffccc8acebb72f70c8a159f0567b
4
- data.tar.gz: 992aee423be6b539415f6dadd8a38dd59a7d32ca
3
+ metadata.gz: c62e293d5310b55d31543e8153f06671c432d3ff
4
+ data.tar.gz: 84b4808b38432d6e67eef3c136719af4231ee060
5
5
  SHA512:
6
- metadata.gz: ab185997dfc12146ed72b4b7e78a38307e1bff1312ce6a0cf65e77c5038446e42da0dde0849031eb43238024331fb6f66d7815cc17fffab34a0f82869188bf49
7
- data.tar.gz: 15a37472e6017d9609ad4d057a4480d022793f853219d693f35add17d09e1705e6db1e6a181302eee1dd81f894ee1f1108da8df2ac8b023e4746dffd1f1d0ff3
6
+ metadata.gz: 0e9a6f9c97537eee941f18178d6d0115d9dd4dd202390c260054b90c4601c10b913ee8fd2cbc4f22ea552c590ea6e2297e663215331bd82471b980298e1dd92e
7
+ data.tar.gz: 07649e1df32a66995c83d72d0f7ff8ff29575a2d17b6c1b347b15812e80786777dc2d50b667241570431a0f74bc4cd45e5169439b0a0485f09bef1955b8a56ea
data/Manifest.txt CHANGED
@@ -25,6 +25,7 @@ lib/worlddb/models/region_comp.rb
25
25
  lib/worlddb/models/tagdb/tag.rb
26
26
  lib/worlddb/models/tagdb/tagging.rb
27
27
  lib/worlddb/models/usage.rb
28
+ lib/worlddb/patterns.rb
28
29
  lib/worlddb/reader.rb
29
30
  lib/worlddb/readers/base.rb
30
31
  lib/worlddb/readers/city.rb
@@ -34,6 +35,7 @@ lib/worlddb/readers/region.rb
34
35
  lib/worlddb/readers/usage.rb
35
36
  lib/worlddb/schema.rb
36
37
  lib/worlddb/stats.rb
38
+ lib/worlddb/stats_comp.rb
37
39
  lib/worlddb/version.rb
38
40
  test/helper.rb
39
41
  test/test_fixture_matchers.rb
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ Hoe.spec 'worlddb' do
17
17
  self.extra_deps = [
18
18
  ['props'], # settings / prop(ertie)s / env / INI
19
19
  ['logutils'], # logging
20
- ['textutils', '>= 0.9.2'], # e.g. >= 0.6 && <= 1.0 ## will include logutils, props
20
+ ['textutils', '>= 0.9.4'], # e.g. >= 0.6 && <= 1.0 ## will include logutils, props
21
21
  ['tagutils'], # tags n categories for activerecord
22
22
 
23
23
  ## 3rd party
data/lib/worlddb.rb CHANGED
@@ -27,6 +27,7 @@ require 'props/db' # includes ConfDb (ConfDb::Model::Prop, etc.)
27
27
 
28
28
  require 'worlddb/version' # always goes first
29
29
 
30
+ require 'worlddb/patterns' # regex patterns (constants)
30
31
  require 'worlddb/models/forward'
31
32
 
32
33
  require 'worlddb/models/name'
@@ -61,6 +62,7 @@ require 'worlddb/readers/city'
61
62
  require 'worlddb/reader'
62
63
  require 'worlddb/deleter'
63
64
  require 'worlddb/stats'
65
+ require 'worlddb/stats_comp'
64
66
 
65
67
 
66
68
  module WorldDb
@@ -13,6 +13,7 @@ module WorldDb
13
13
 
14
14
  ## Tagging.delete_all # - use TagDb.delete!
15
15
  ## Tag.delete_all
16
+
16
17
  Name.delete_all
17
18
  Place.delete_all
18
19
  City.delete_all
@@ -21,9 +22,10 @@ module WorldDb
21
22
  Continent.delete_all
22
23
  Usage.delete_all
23
24
  Lang.delete_all
25
+
24
26
  # Prop.delete_all # - use ConfDb.delete!
25
27
  end
26
-
28
+
27
29
  end # class Deleter
28
30
 
29
- end # module WorldDb
31
+ end # module WorldDb
@@ -80,8 +80,8 @@ class City < ActiveRecord::Base
80
80
  end
81
81
 
82
82
 
83
- validates :key, format: { with: /^[a-z]{3,}$/, message: 'expected three or more lowercase letters a-z' }
84
- validates :code, format: { with: /^[A-Z_]{3}$/, message: 'expected three uppercase letters A-Z (and _)' }, :allow_nil => true
83
+ validates :key, format: { with: /#{CITY_KEY_PATTERN}/, message: CITY_KEY_PATTERN_MESSAGE }
84
+ validates :code, format: { with: /#{CITY_CODE_PATTERN}/, message: CITY_CODE_PATTERN_MESSAGE }, allow_nil: true
85
85
 
86
86
 
87
87
  scope :by_key, ->{ order( 'key asc' ) } # order by key (a-z)
@@ -175,7 +175,7 @@ class City < ActiveRecord::Base
175
175
  elsif match_number( value ) do |num| # numeric (nb: can use any _ or spaces inside digits e.g. 1_000_000 or 1 000 000)
176
176
  value_numbers << num
177
177
  end
178
- elsif value =~ /^[A-Z]{3}$/ ## assume three-letter code
178
+ elsif value =~ /#{CITY_CODE_PATTERN}/ ## assume three-letter code
179
179
  new_attributes[ :code ] = value
180
180
  elsif (values.size==(index+1)) && is_taglist?( value ) # tags must be last entry
181
181
  logger.debug " found tags: >>#{value}<<"
@@ -32,8 +32,8 @@ class Country < ActiveRecord::Base
32
32
 
33
33
  has_many_tags
34
34
 
35
- validates :key, format: { with: /^[a-z]{2}$/, message: 'expected two lowercase letters a-z' }
36
- validates :code, format: { with: /^[A-Z_]{3}$/, message: 'expected three uppercase letters A-Z (and _)' }
35
+ validates :key, format: { with: /#{COUNTRY_KEY_PATTERN}/, message: COUNTRY_KEY_PATTERN_MESSAGE }
36
+ validates :code, format: { with: /#{COUNTRY_CODE_PATTERN}/, message: COUNTRY_CODE_PATTERN_MESSAGE }
37
37
 
38
38
 
39
39
  scope :by_key, ->{ order( 'key asc' ) } # order by key (a-z)
@@ -49,10 +49,16 @@ class Country < ActiveRecord::Base
49
49
  def on_create
50
50
  place_rec = Place.create!( name: name, kind: place_kind )
51
51
  self.place_id = place_rec.id
52
-
53
- self.slug = TextUtils.slugify( name ) if slug.blank?
52
+
53
+ if slug.blank?
54
+ ## todo: change and to n (if en/english) ?? - why? why not?
55
+ ## remove subtitles/subnames e.g. () -- why? why not?
56
+
57
+ ## remove translations [] e.g. México [Mexico] -> México etc.
58
+ self.slug = TextUtils.slugify( name.gsub( /\[[^\]]+\]/, '' ) )
59
+ end
54
60
  end
55
-
61
+
56
62
  def on_update
57
63
  ## fix/todo: check - if name or kind changed - only update if changed ?? why? why not??
58
64
  place.update_attributes!( name: name, kind: place_kind )
@@ -151,7 +157,7 @@ class Country < ActiveRecord::Base
151
157
  elsif match_number( value ) do |num| # numeric (nb: can use any _ or spaces inside digits e.g. 1_000_000 or 1 000 000)
152
158
  value_numbers << num
153
159
  end
154
- elsif value =~ /^[A-Z]{2,3}$/ ## assume two or three-letter code
160
+ elsif value =~ /#{COUNTRY_CODE_PATTERN}/ ## three letter code
155
161
  new_attributes[ :code ] = value
156
162
  elsif (values.size==(index+1)) && is_taglist?( value ) # tags must be last entry
157
163
  logger.debug " found tags: >>#{value}<<"
@@ -9,11 +9,10 @@ class Lang < ActiveRecord::Base
9
9
 
10
10
  has_many :countries, :through => :usages
11
11
 
12
- validates :key, format: { with: /^[a-z]{2}$/, message: 'expected two lowercase letters a-z' }
12
+ validates :key, format: { with: /#{LANG_KEY_PATTERN}/, message: LANG_KEY_PATTERN_MESSAGE }
13
13
 
14
14
  end # class Lang
15
15
 
16
16
  end # module Model
17
17
  end # module WorldDb
18
18
 
19
-
@@ -19,8 +19,9 @@ class Region < ActiveRecord::Base
19
19
 
20
20
  has_many_tags
21
21
 
22
- validates :key, format: { with: /^[a-z]+$/, message: 'expected one or more lowercase letters a-z' }
23
- validates :code, format: { with: /^[A-Z_]{2,3}$/, message: 'expected two or three uppercase letters A-Z (and _)' }, allow_nil: true
22
+ validates :key, format: { with: /#{REGION_KEY_PATTERN}/, message: REGION_KEY_PATTERN_MESSAGE }
23
+ validates :code, format: { with: /#{REGION_CODE_PATTERN}/, message: REGION_CODE_PATTERN_MESSAGE }, allow_nil: true
24
+
24
25
 
25
26
  before_create :on_create
26
27
  before_update :on_update
@@ -91,7 +92,7 @@ class Region < ActiveRecord::Base
91
92
  elsif match_number( value ) do |num| # numeric (nb: can use any _ or spaces inside digits e.g. 1_000_000 or 1 000 000)
92
93
  value_numbers << num
93
94
  end
94
- elsif value =~ /^[A-Z]{2,3}$/ ## assume two or three-letter code
95
+ elsif value =~ /#{REGION_CODE_PATTERN}/ ## assume two or three-letter code
95
96
  new_attributes[ :code ] = value
96
97
  elsif (values.size==(index+1)) && is_taglist?( value ) # tags must be last entry
97
98
  logger.debug " found tags: >>#{value}<<"
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ module WorldDb
4
+
5
+ # collection of regex patterns for reuse (WorldDb specific)
6
+
7
+ ### todo: add a patterns.md page to github ??
8
+ ## - add regexper pics??
9
+
10
+ ############
11
+ # about ruby regexps
12
+ #
13
+ # try the rubular - Ruby regular expression editor and tester
14
+ # -> http://rubular.com
15
+ # code -> ?? by ??
16
+ #
17
+ #
18
+ # Jeff Avallone's Regexper - Shows State-Automata Diagrams
19
+ # try -> http://regexper.com
20
+ # code -> https://github.com/javallone/regexper
21
+ #
22
+ #
23
+ # Regular Expressions | The Bastards Book of Ruby by Dan Nguyen
24
+ # http://ruby.bastardsbook.com/chapters/regexes/
25
+ #
26
+ # move to notes regex|patterns on geraldb.github.io ??
27
+ #
28
+
29
+ COUNTRY_KEY_PATTERN = '^[a-z]{2,3}$' # allow two AND three letter keys e.g. at, mx, eng, sco, etc.
30
+ COUNTRY_KEY_PATTERN_MESSAGE = "expected two or three lowercase letters a-z /#{COUNTRY_KEY_PATTERN}/"
31
+
32
+ COUNTRY_CODE_PATTERN = '^[A-Z_]{3}$'
33
+ COUNTRY_CODE_PATTERN_MESSAGE = "expected three uppercase letters A-Z (and _) /#{COUNTRY_CODE_PATTERN}/"
34
+
35
+
36
+ REGION_KEY_PATTERN = '^[a-z]+$'
37
+ REGION_KEY_PATTERN_MESSAGE = "expected one or more lowercase letters a-z /#{REGION_KEY_PATTERN}/"
38
+
39
+ REGION_CODE_PATTERN = '^[A-Z_]{2,3}$'
40
+ REGION_CODE_PATTERN_MESSAGE = "expected two or three uppercase letters A-Z (and _) /#{REGION_CODE_PATTERN}/"
41
+
42
+
43
+ CITY_KEY_PATTERN = '^[a-z]{3,}$'
44
+ CITY_KEY_PATTERN_MESSAGE = "expected three or more lowercase letters a-z' /#{CITY_KEY_PATTERN}/"
45
+
46
+ CITY_CODE_PATTERN = '^[A-Z_]{3}$'
47
+ CITY_CODE_PATTERN_MESSAGE = "expected three uppercase letters A-Z (and _)' /#{CITY_CODE_PATTERN}/"
48
+
49
+
50
+ LANG_KEY_PATTERN = '^[a-z]{2}$'
51
+ LANG_KEY_PATTERN_MESSAGE = "expected two lowercase letters a-z' /#{LANG_KEY_PATTERN}/"
52
+
53
+ end # module WorldDb
54
+
@@ -35,22 +35,14 @@ class Reader
35
35
 
36
36
 
37
37
  def load_setup( name )
38
- path = "#{include_path}/#{name}.yml"
38
+ path = "#{include_path}/#{name}.txt"
39
39
 
40
40
  logger.info "parsing data '#{name}' (#{path})..."
41
41
 
42
42
  reader = FixtureReader.new( path )
43
43
 
44
- # too big for heroku free db plan (10,000 record limit)
45
- # - sorry, can't load by default
46
- fixture_excludes = [
47
- 'south-america/ve/cities'
48
- ]
49
-
50
- reader.each do |fixture_name|
51
- next if fixture_excludes.include?( fixture_name ) # skip loading
52
-
53
- load( fixture_name )
44
+ reader.each do |fixture|
45
+ load( fixture )
54
46
  end
55
47
  end # method load_setup
56
48
 
@@ -1,10 +1,11 @@
1
1
 
2
2
  module WorldDb
3
3
 
4
- class CreateDb < ActiveRecord::Migration
4
+ class CreateDb
5
5
 
6
6
  def up
7
7
 
8
+ ActiveRecord::Schema.define do
8
9
 
9
10
  create_table :places do |t|
10
11
  t.string :name, null: false
@@ -173,13 +174,11 @@ create_table :usages do |t| # join table for countries_langs
173
174
  t.timestamps
174
175
  end
175
176
 
177
+ end # block Schema.define
176
178
 
177
179
  end # method up
178
180
 
179
- def down
180
- raise ActiveRecord::IrreversibleMigration
181
- end
182
181
 
183
182
  end # class CreateDb
184
183
 
185
- end # module WorldDb
184
+ end # module WorldDb
data/lib/worlddb/stats.rb CHANGED
@@ -21,17 +21,7 @@ module WorldDb
21
21
  puts " #{'%5d' % Usage.count} usages"
22
22
  end
23
23
 
24
-
25
- #
26
- # fix: move to ConfDb for (re)use !!!!!
27
-
28
- def props
29
- puts "Props:"
30
- Prop.order( 'created_at asc' ).all.each do |prop|
31
- puts " #{prop.key} / #{prop.value} || #{prop.created_at}"
32
- end
33
- end
34
24
  end # class Stats
35
25
 
26
+ end # module WorldDb
36
27
 
37
- end # module WorldDb
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ module WorldDb
4
+
5
+ class Stats
6
+
7
+ #
8
+ # fix: move to ConfDb for (re)use - do not use - use Props.dump or similar!!!!!
9
+
10
+ def props
11
+ puts "deprecated API - WorldDb::Stats.props -- use Props.dump or similar"
12
+
13
+ puts "Props:"
14
+ Prop.order( 'created_at asc' ).all.each do |prop|
15
+ puts " #{prop.key} / #{prop.value} || #{prop.created_at}"
16
+ end
17
+ end
18
+ end # class Stats
19
+
20
+
21
+ end # module WorldDb
@@ -1,5 +1,5 @@
1
1
 
2
2
  module WorldDb
3
- VERSION = '2.0.1' # sync version w/ sport.db - why? why not?
3
+ VERSION = '2.0.2' # sync version w/ sport.db - why? why not?
4
4
  end
5
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worlddb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.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: 2014-03-29 00:00:00.000000000 Z
11
+ date: 2014-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: props
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.9.2
47
+ version: 0.9.4
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.9.2
54
+ version: 0.9.4
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: tagutils
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -159,6 +159,7 @@ files:
159
159
  - lib/worlddb/models/tagdb/tag.rb
160
160
  - lib/worlddb/models/tagdb/tagging.rb
161
161
  - lib/worlddb/models/usage.rb
162
+ - lib/worlddb/patterns.rb
162
163
  - lib/worlddb/reader.rb
163
164
  - lib/worlddb/readers/base.rb
164
165
  - lib/worlddb/readers/city.rb
@@ -168,6 +169,7 @@ files:
168
169
  - lib/worlddb/readers/usage.rb
169
170
  - lib/worlddb/schema.rb
170
171
  - lib/worlddb/stats.rb
172
+ - lib/worlddb/stats_comp.rb
171
173
  - lib/worlddb/version.rb
172
174
  - test/helper.rb
173
175
  - test/test_fixture_matchers.rb