worlddb 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -62,4 +62,5 @@ lib/worlddb/models/tag.rb
62
62
  lib/worlddb/models/tagging.rb
63
63
  lib/worlddb/reader.rb
64
64
  lib/worlddb/schema.rb
65
+ lib/worlddb/utils.rb
65
66
  lib/worlddb/version.rb
@@ -0,0 +1,140 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ class Time
5
+
6
+ def self.cet( str ) # central european time (cet) + central european summer time (cest)
7
+ ActiveSupport::TimeZone['Vienna'].parse( str )
8
+ end
9
+
10
+ def self.eet( str ) # eastern european time (eet) + 2 hours
11
+ ActiveSupport::TimeZone['Bucharest'].parse( str )
12
+ end
13
+
14
+ def self.cst( str ) # central standard time (cst) - 6 hours
15
+ ActiveSupport::TimeZone['Mexico City'].parse( str )
16
+ end
17
+
18
+ end # class Time
19
+
20
+
21
+ class File
22
+ def self.read_utf8( path )
23
+ open( path, 'r:bom|utf-8' ) do |file|
24
+ file.read
25
+ end
26
+ end
27
+ end # class File
28
+
29
+
30
+
31
+ ##
32
+ # fix/todo: share helper w/ other readers
33
+
34
+ # helper
35
+ # change at/2012_13/bl to at.2012/13.bl
36
+ # or quali_2012_13_europe_c to quali.2012/13.europe.c
37
+
38
+ def fixture_name_to_prop_key( name )
39
+ prop_key = name.gsub( '/', '.' )
40
+ prop_key = prop_key.gsub( /(\d{4})_(\d{2})/, '\1/\2' ) # 2012_13 => 2012/13
41
+ prop_key = prop_key.gsub( '_', '.' )
42
+ prop_key
43
+ end
44
+
45
+ ############
46
+ ### fix/todo: share helper for all text readers/parsers- where to put it?
47
+ ###
48
+
49
+ def title_esc_regex( title_unescaped )
50
+
51
+ ## escape regex special chars e.g. . to \. and ( to \( etc.
52
+ # e.g. Benfica Lis.
53
+ # e.g. Club Atlético Colón (Santa Fe)
54
+
55
+ ## NB: cannot use Regexp.escape! will escape space '' to '\ '
56
+ ## title = Regexp.escape( title_unescaped )
57
+ title = title_unescaped.gsub( '.', '\.' )
58
+ title = title.gsub( '(', '\(' )
59
+ title = title.gsub( ')', '\)' )
60
+
61
+ ## match accented char with or without accents
62
+ ## add (ü|ue) etc.
63
+ ## also make - optional change to (-| ) e.g. Blau-Weiss == Blau Weiss
64
+
65
+ ## todo: add some more
66
+ ## see http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references for more
67
+ ##
68
+ ## reuse for all readers!
69
+
70
+ alternatives = [
71
+ ['-', '(-| )'],
72
+ ['ß', '(ß|ss)'],
73
+ ['æ', '(æ|ae)'],
74
+ ['á', '(á|a)'], ## e.g. Bogotá
75
+ ['ã', '(ã|a)'], ## e.g São Paulo
76
+ ['ä', '(ä|ae)'], ## add a ?
77
+ ['Ö', '(Ö|Oe)'], ## e.g. Österreich
78
+ ['ö', '(ö|oe)'], ## add o ?
79
+ ['ó', '(ó|o)'], ## e.g. Colón
80
+ ['ü', '(ü|ue)'], ## add u ?
81
+ ['é', '(é|e)'], ## e.g. Vélez
82
+ ['ê', '(ê|e)'], ## e.g. Grêmio
83
+ ['ñ', '(ñ|n)'], ## e.g. Porteño
84
+ ['ú', '(ú|u)'] ## e.g. Fútbol
85
+ ]
86
+
87
+ alternatives.each do |alt|
88
+ title = title.gsub( alt[0], alt[1] )
89
+ end
90
+
91
+ title
92
+ end
93
+
94
+
95
+ class FixtureReader
96
+
97
+ def initialize( logger=nil, path )
98
+ if logger.nil?
99
+ @logger = Logger.new(STDOUT)
100
+ @logger.level = Logger::INFO
101
+ else
102
+ @logger = logger
103
+ end
104
+
105
+ @path = path
106
+
107
+ ## nb: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
108
+ ## - see worlddb/utils.rb
109
+ @data = File.read_utf8( @path )
110
+ end
111
+
112
+ attr_reader :logger
113
+
114
+
115
+ def each_line
116
+ @data.each_line do |line|
117
+
118
+ if line =~ /^\s*#/
119
+ # skip komments and do NOT copy to result (keep comments secret!)
120
+ logger.debug 'skipping comment line'
121
+ next
122
+ end
123
+
124
+ if line =~ /^\s*$/
125
+ # kommentar oder leerzeile überspringen
126
+ logger.debug 'skipping blank line'
127
+ next
128
+ end
129
+
130
+ # remove leading and trailing whitespace
131
+ line = line.strip
132
+
133
+ yield(line)
134
+ end # lines.each
135
+ end
136
+
137
+ end # class FixtureReader
138
+
139
+
140
+
@@ -1,5 +1,5 @@
1
1
 
2
2
  module WorldDB
3
- VERSION = '0.3.2'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
 
data/lib/worlddb.rb CHANGED
@@ -19,8 +19,8 @@ require 'active_record' ## todo: add sqlite3? etc.
19
19
 
20
20
  # our own code
21
21
 
22
- module WorldDB # forward reference; more to come later
23
- end
22
+
23
+ require 'worlddb/version'
24
24
 
25
25
  require 'worlddb/models/prop'
26
26
  require 'worlddb/models/country'
@@ -29,9 +29,9 @@ require 'worlddb/models/city'
29
29
  require 'worlddb/models/tag'
30
30
  require 'worlddb/models/tagging'
31
31
  require 'worlddb/schema' # NB: requires worlddb/models (include WorldDB::Models)
32
+ require 'worlddb/utils'
32
33
  require 'worlddb/reader'
33
34
  require 'worlddb/loader'
34
- require 'worlddb/version'
35
35
  require 'worlddb/cli/opts'
36
36
  require 'worlddb/cli/runner'
37
37
 
@@ -154,6 +154,7 @@ module WorldDB
154
154
 
155
155
  # delete ALL records (use with care!)
156
156
  def self.delete!
157
+ puts '*** deleting world table records/data...'
157
158
  Deleter.new.run
158
159
  end # method delete!
159
160
 
@@ -194,4 +195,9 @@ module WorldDB
194
195
  end # module WorldDB
195
196
 
196
197
 
197
- WorldDB.main if __FILE__ == $0
198
+ if __FILE__ == $0
199
+ WorldDB.main
200
+ else
201
+ # say hello
202
+ puts WorldDB.banner
203
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worlddb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 2
10
- version: 0.3.2
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gerald Bauer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-11-16 00:00:00 Z
18
+ date: 2012-11-20 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activerecord
@@ -173,6 +173,7 @@ files:
173
173
  - lib/worlddb/models/tagging.rb
174
174
  - lib/worlddb/reader.rb
175
175
  - lib/worlddb/schema.rb
176
+ - lib/worlddb/utils.rb
176
177
  - lib/worlddb/version.rb
177
178
  homepage: http://geraldb.github.com/world.db
178
179
  licenses: []