worlddb 0.8.0 → 1.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 (110) hide show
  1. data/Manifest.txt +4 -98
  2. data/Rakefile +1 -6
  3. data/lib/worlddb/cli/main.rb +170 -0
  4. data/lib/worlddb/cli/opts.rb +24 -50
  5. data/lib/worlddb/data/fixtures.rb +168 -0
  6. data/lib/worlddb/deleter.rb +26 -0
  7. data/lib/worlddb/reader.rb +8 -61
  8. data/lib/worlddb/stats.rb +30 -0
  9. data/lib/worlddb/utils.rb +0 -60
  10. data/lib/worlddb/version.rb +1 -2
  11. data/lib/worlddb.rb +24 -184
  12. metadata +30 -108
  13. data/data/africa/1_codes/fifa.yml +0 -59
  14. data/data/africa/1_codes/internet.yml +0 -64
  15. data/data/africa/1_codes/iso3.yml +0 -57
  16. data/data/africa/2_names/de.yml +0 -10
  17. data/data/africa/3_more/en.wikipedia.yml +0 -30
  18. data/data/africa/3_more/lang.yml +0 -63
  19. data/data/africa/countries.txt +0 -92
  20. data/data/america/1_codes/fifa.yml +0 -41
  21. data/data/america/1_codes/internet.yml +0 -39
  22. data/data/america/1_codes/iso3.yml +0 -39
  23. data/data/america/1_codes/motor.yml +0 -26
  24. data/data/america/2_names/de.yml +0 -31
  25. data/data/america/2_names/es.yml +0 -30
  26. data/data/america/3_more/en.wikipedia.yml +0 -9
  27. data/data/america/3_more/lang.yml +0 -60
  28. data/data/america/br/regions.txt +0 -27
  29. data/data/america/ca/cities.txt +0 -48
  30. data/data/america/ca/regions.txt +0 -28
  31. data/data/america/countries.txt +0 -70
  32. data/data/america/mx/cities.txt +0 -32
  33. data/data/america/mx/regions.txt +0 -54
  34. data/data/america/us/cities.txt +0 -46
  35. data/data/america/us/regions.txt +0 -64
  36. data/data/america/ve/cities.txt +0 -358
  37. data/data/america/ve/regions.txt +0 -46
  38. data/data/asia/1_codes/fifa.yml +0 -53
  39. data/data/asia/1_codes/internet.yml +0 -51
  40. data/data/asia/1_codes/iso3.yml +0 -51
  41. data/data/asia/2_names/de.yml +0 -9
  42. data/data/asia/3_more/en.wikipedia.yml +0 -26
  43. data/data/asia/3_more/lang.yml +0 -55
  44. data/data/asia/countries.txt +0 -126
  45. data/data/asia/jp/cities.txt +0 -3
  46. data/data/europe/1_codes/fifa.yml +0 -60
  47. data/data/europe/1_codes/internet.yml +0 -59
  48. data/data/europe/1_codes/iso3.yml +0 -59
  49. data/data/europe/1_codes/motor.yml +0 -60
  50. data/data/europe/2_names/de.yml +0 -42
  51. data/data/europe/2_names/es.yml +0 -43
  52. data/data/europe/3_more/en.wikipedia.yml +0 -12
  53. data/data/europe/3_more/lang.yml +0 -47
  54. data/data/europe/at/cities.txt +0 -45
  55. data/data/europe/at/regions.txt +0 -26
  56. data/data/europe/be/cities.txt +0 -19
  57. data/data/europe/be/regions.txt +0 -23
  58. data/data/europe/bg/cities.txt +0 -4
  59. data/data/europe/by/cities.txt +0 -4
  60. data/data/europe/ch/cities.txt +0 -4
  61. data/data/europe/countries.txt +0 -123
  62. data/data/europe/cy/cities.txt +0 -1
  63. data/data/europe/cz/cities.txt +0 -26
  64. data/data/europe/cz/regions.txt +0 -32
  65. data/data/europe/de/cities.txt +0 -44
  66. data/data/europe/de/regions.txt +0 -16
  67. data/data/europe/dk/cities.txt +0 -6
  68. data/data/europe/ee/cities.txt +0 -2
  69. data/data/europe/en/cities.txt +0 -32
  70. data/data/europe/en/regions.txt +0 -21
  71. data/data/europe/es/cities.txt +0 -17
  72. data/data/europe/es/regions.txt +0 -26
  73. data/data/europe/fi/cities.txt +0 -2
  74. data/data/europe/fr/cities.txt +0 -15
  75. data/data/europe/fr/regions.txt +0 -32
  76. data/data/europe/gr/cities.txt +0 -6
  77. data/data/europe/hr/cities.txt +0 -1
  78. data/data/europe/hu/cities.txt +0 -2
  79. data/data/europe/ie/cities.txt +0 -3
  80. data/data/europe/it/cities.txt +0 -17
  81. data/data/europe/lt/cities.txt +0 -3
  82. data/data/europe/lv/cities.txt +0 -4
  83. data/data/europe/nl/cities.txt +0 -11
  84. data/data/europe/no/cities.txt +0 -3
  85. data/data/europe/pl/cities.txt +0 -12
  86. data/data/europe/pt/cities.txt +0 -6
  87. data/data/europe/ro/cities.txt +0 -4
  88. data/data/europe/rs/cities.txt +0 -3
  89. data/data/europe/ru/cities.txt +0 -14
  90. data/data/europe/sc/cities.txt +0 -3
  91. data/data/europe/se/cities.txt +0 -3
  92. data/data/europe/tr/cities.txt +0 -3
  93. data/data/europe/ua/cities.txt +0 -9
  94. data/data/europe/wa/cities.txt +0 -3
  95. data/data/langs.yml +0 -210
  96. data/data/oceania/1_codes/fifa.yml +0 -21
  97. data/data/oceania/1_codes/internet.yml +0 -17
  98. data/data/oceania/1_codes/iso3.yml +0 -17
  99. data/data/oceania/2_names/de.yml +0 -7
  100. data/data/oceania/3_more/en.wikipedia.yml +0 -11
  101. data/data/oceania/3_more/lang.yml +0 -17
  102. data/data/oceania/au/cities.txt +0 -2
  103. data/data/oceania/countries.txt +0 -40
  104. data/data/tags.1.yml +0 -40
  105. data/data/tags.3.yml +0 -23
  106. data/lib/worlddb/cli/runner.rb +0 -113
  107. data/lib/worlddb/readers/code_reader.rb +0 -34
  108. data/lib/worlddb/readers/hash_reader.rb +0 -81
  109. data/lib/worlddb/readers/line_reader.rb +0 -45
  110. data/lib/worlddb/readers/values_reader.rb +0 -171
data/data/langs.yml DELETED
@@ -1,210 +0,0 @@
1
- ## list of languages
2
- ## use key / title e.g. en: English, de: Deutsch etc.
3
-
4
- ## for a list see http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
5
-
6
-
7
- ### languages in europe
8
-
9
- sq: Albanian
10
- eu: Basque
11
- be: Belarusian
12
- bs: Bosnian
13
- br: Breton
14
- bg: Bulgarian
15
- ca: Catalan
16
- kw: Cornish
17
- co: Corsican
18
- hr: Croatian
19
- cs: Czech
20
- da: Danish
21
- nl: Dutch
22
- en: English
23
- et: Estonian
24
- fo: Faroese
25
- fi: Finnish
26
- fr: French
27
- gl: Galician
28
- de: German
29
- el: Greek
30
- hu: Hungarian
31
- ga: Irish
32
- is: Icelandic
33
- it: Italian
34
- lb: Luxembourgish
35
- lt: Lithuanian
36
- lv: Latvian
37
- mk: Macedonian
38
- mt: Maltese
39
- nb: Norwegian Bokmål
40
- nn: Norwegian Nynorsk
41
- no: Norwegian
42
- pl: Polish
43
- pt: Portuguese
44
- rm: Romansh
45
- ro: Romanian|Moldavian
46
- ru: Russian
47
- sc: Sardinian
48
- sr: Serbian
49
- gd: Scottish Gaelic|Gaelic
50
- es: Spanish|Castilian
51
- sv: Swedish
52
- sk: Slovak
53
- sl: Slovene
54
- tr: Turkish
55
- uk: Ukrainian
56
- wa: Walloon
57
- cy: Welsh
58
- fy: Western Frisian
59
- yi: Yiddish
60
- kl: Kalaallisut|Greenlandic
61
-
62
- ### america
63
-
64
- ay: Aymara
65
- cr: Cree
66
- gn: Guaraní
67
- ht: Haitian
68
- ik: Inupiaq
69
- iu: Inuktitut
70
- nv: Navajo
71
- oj: Ojibwe
72
- qu: Quechua
73
-
74
-
75
- ### todo: group/sort by continent
76
- ### africa / asia / oceania
77
-
78
- ab: Abkhaz
79
- aa: Afar
80
- af: Afrikaans
81
- ak: Akan
82
- am: Amharic
83
- ar: Arabic
84
- an: Aragonese
85
- hy: Armenian
86
- as: Assamese
87
- av: Avaric
88
- ae: Avestan
89
- az: Azerbaijani
90
- bm: Bambara
91
- ba: Bashkir
92
- bn: Bengali
93
- bh: Bihari
94
- bi: Bislama
95
- my: Burmese
96
- ch: Chamorro
97
- ce: Chechen
98
- ny: Chichewa
99
- zh: Chinese
100
- cv: Chuvash
101
- dv: Divehi
102
- dz: Dzongkha
103
- ee: Ewe
104
- fj: Fijian
105
- ff: Fula
106
- ka: Georgian
107
- gu: Gujarati
108
- ha: Hausa
109
- he: Hebrew
110
- hz: Herero
111
- hi: Hindi
112
- ho: Hiri Motu
113
- id: Indonesian
114
- ig: Igbo
115
- ja: Japanese
116
- jv: Javanese
117
- kn: Kannada
118
- kr: Kanuri
119
- ks: Kashmiri
120
- kk: Kazakh
121
- km: Khmer|Cambodian
122
- ki: Kikuyu
123
- rw: Kinyarwanda
124
- ky: Kyrgyz
125
- kv: Komi
126
- kg: Kongo
127
- ko: Korean
128
- ku: Kurdish
129
- kj: Kwanyama
130
- lg: Ganda
131
- li: Limburgish
132
- ln: Lingala
133
- lo: Lao
134
- lu: Luba-Katanga
135
- gv: Manx
136
- mg: Malagasy
137
- ms: Malay
138
- ml: Malayalam
139
- mi: Māori
140
- mr: Marathi
141
- mh: Marshallese
142
- mn: Mongolian
143
- na: Nauru
144
- nd: North Ndebele
145
- ne: Nepali
146
- ng: Ndonga
147
- ii: Nuosu
148
- nr: South Ndebele
149
- oc: Occitan
150
- om: Oromo
151
- or: Oriya
152
- os: Ossetian|Ossetic
153
- pa: Panjabi|Punjabi
154
- pi: Pāli
155
- fa: Persian
156
- ps: Pashto
157
- rn: Kirundi
158
- sa: Sanskrit
159
- sd: Sindhi
160
- se: Northern Sami
161
- sm: Samoan
162
- sg: Sango
163
- sn: Shona
164
- si: Sinhala
165
- so: Somali
166
- st: Southern Sotho
167
- su: Sundanese
168
- sw: Swahili
169
- ss: Swati
170
- ta: Tamil
171
- te: Telugu
172
- tg: Tajik
173
- th: Thai
174
- ti: Tigrinya
175
- bo: Tibetan
176
- tk: Turkmen
177
- tl: Tagalog
178
- tn: Tswana
179
- to: Tonga
180
- ts: Tsonga
181
- tt: Tatar
182
- tw: Twi
183
- ty: Tahitiani
184
- ug: Uighur
185
- ur: Urdu
186
- uz: Uzbek
187
- ve: Venda
188
- vi: Vietnamese
189
- wo: Wolof
190
- xh: Xhosa
191
- yo: Yoruba
192
- za: Zhuang
193
- zu: Zulu
194
-
195
-
196
- #####################
197
- ## constructed languages
198
-
199
- ## eo: Esperanto
200
- ## ia: Interlingua
201
- ## ie: Interlingue
202
- ## io: Ido
203
- ## vo: Volapük
204
-
205
-
206
- #########################
207
- ## acient
208
-
209
- ## la: Latin
210
- ## cu: Old Church Slavonic|Old Bulgarian
@@ -1,21 +0,0 @@
1
- ####################
2
- ## oceania
3
-
4
- fj: FIJ # Fiji
5
- ws: SAM # Samoa
6
- sb: SOL # Solomon Islands
7
- to: TGA # Tonga
8
- vu: VAN # Vanuatu
9
- au: AUS # Australia
10
- nz: NZL # New Zealand
11
- pg: PNG # Papua New Guinea
12
-
13
- ####
14
- ## not members - double check if mistaken
15
-
16
- ki: !!null # Kiribati
17
- mh: !!null # Marshall Islands
18
- fm: !!null # Micronesia
19
- nr: !!null # Nauru
20
- pw: !!null # Palau
21
- tv: !!null # Tuvalu
@@ -1,17 +0,0 @@
1
- ####################
2
- ## oceania
3
-
4
- fj: fj # Fiji
5
- ki: ki # Kiribati
6
- mh: mh # Marshall Islands
7
- fm: fm # Micronesia
8
- nr: nr # Nauru
9
- pw: pw # Palau
10
- ws: ws # Samoa
11
- sb: sb # Solomon Islands
12
- to: to # Tonga
13
- tv: tv # Tuvalu
14
- vu: vu # Vanuatu
15
- au: au # Australia
16
- nz: nz # New Zealand
17
- pg: pg # Papua New Guinea
@@ -1,17 +0,0 @@
1
- ####################
2
- ## oceania
3
-
4
- fj: FJI # Fiji
5
- ki: KIR # Kiribati
6
- mh: MHL # Marshall Islands
7
- fm: FSM # Micronesia
8
- nr: NRU # Nauru
9
- pw: PLW # Palau
10
- ws: WSM # Samoa
11
- sb: SLB # Solomon Islands
12
- to: TON # Tonga
13
- tv: TUV # Tuvalu
14
- vu: VUT # Vanuatu
15
- au: AUS # Australia
16
- nz: NZL # New Zealand
17
- pg: PNG # Papua New Guinea
@@ -1,7 +0,0 @@
1
- ###############################
2
- ## australia & oceania
3
-
4
-
5
- au: Australien
6
- nz: Neuseeland
7
-
@@ -1,11 +0,0 @@
1
-
2
- ki: Kiribati
3
- mh: Marshall_Islands
4
- fm: Federated_States_of_Micronesia
5
- nr: Nauru
6
- pw: Palau
7
- ws: Samoa
8
- sb: Solomon_Islands
9
- to: Tonga
10
- tv: Tuvalu
11
- vu: Vanuatu
@@ -1,17 +0,0 @@
1
-
2
- au: en
3
- nz: mi,en
4
-
5
-
6
- fj: en
7
- fm: en
8
- ki: en
9
- mh: en,mh
10
- nr: na,en
11
- pg: en,ho # tpi
12
- pw: en,ja # pau,sov,tox
13
- sb: en
14
- tv: en
15
- vu: bi,en,fr
16
- ws: sm,en
17
-
@@ -1,2 +0,0 @@
1
-
2
- ## add australian regions and cities here
@@ -1,40 +0,0 @@
1
- ###############################
2
- ## australia & oceania
3
-
4
- ####
5
- ## regions
6
- ## - Melanesia
7
- ## - Micronesia
8
- ## - Polynesia
9
-
10
-
11
- au, Australia, AUS, 7_686_850, 22_028_000, un|fifa|g20|commonwealth
12
-
13
- ##############
14
- ### Melanesia
15
- ## see http://en.wikipedia.org/wiki/Melanesia
16
-
17
- pg, Papua New Guinea, PNG, 462_840, 5_172_033, un|fifa|melanesia|commonwealth
18
- fj, Fiji, FIJ, 18_274, 849_000, Suva, un|fifa|melanesia|commonwealth
19
- sb, Solomon Islands, SOL, 28_400, 523_000, Honiara, un|fifa|melanesia|commonwealth
20
- vu, Vanuatu, VAN, 12_190, 224_564, Port Vila, un|fifa|melanesia|commonwealth
21
-
22
-
23
- #############
24
- ## Micronesia
25
- ## see http://en.wikipedia.org/wiki/Micronesia
26
-
27
- pw, Palau, PLW, 459, 20_956, Ngerulmud, un|micronesia|microstate # nb: use ISO code; NOT fifa member
28
- fm, Micronesia, FSM, 702, 111_000, Palikir, un|micronesia|microstate # nb: use ISO code; NOT fifa member
29
- mh, Marshall Islands, MHL, 181, 68_000, Majuro, un|micronesia|microstate # nb: use ISO code; NOT fifa member
30
- nr, Nauru, NRU, 21, 9_378, Yaren, un|micronesia|microstate|commonwealth # nb: use ISO code; NOT fifa member
31
- ki, Kiribati, KIR, 811, 103_500, Tarawa, un|micronesia|microstate|commonwealth # nb: use ISO code; NOT fifa member
32
-
33
- ##############
34
- ## Polynesia
35
- ## see http://en.wikipedia.org/wiki/Polynesia
36
-
37
- nz, New Zealand, NZL, 268_680, 4_108_037, un|fifa|polynesia|commonwealth
38
- ws, Samoa, SAM, 2_831, 194_320, Apia, un|fifa|polynesia|commonwealth
39
- to, Tonga, TGA, 748, 103_036, Nuku'alofa, un|fifa|polynesia|microstate|commonwealth
40
- tv, Tuvalu, TUV, 26, 10_544, Funafuti, un|polynesia|microstate|commonwealth # nb: use ISO code; NOT fifa member
data/data/tags.1.yml DELETED
@@ -1,40 +0,0 @@
1
- ### setup some grade 1 tags
2
-
3
-
4
- ###
5
- # for 193 un members see www.un.org/en/members
6
-
7
-
8
- ## some tags
9
-
10
- continents: africa, america, asia, europe, oceania
11
-
12
- ####################
13
- # geo regions
14
- africa: northern africa, western africa, central africa, eastern africa, southern africa
15
-
16
- americas: north america, south america, central america, caribbean (islands)
17
-
18
- ## check if yaml can handle key w/ space??
19
- south_america: andean states, southern cone
20
-
21
- europe: northern europe, southern europe, western europe, central europe, eastern europe, southeastern europe
22
-
23
- ## more regions
24
- europe2: baltic (states), scandinavia, nordic (countries), balkans
25
-
26
-
27
- ## get used for more than one continent
28
- more: middle east, indian ocean, atlantic ocean
29
-
30
- # orgs
31
-
32
- orgs: un, g5, g8, g20, eu, commonwealth, mercosur, nafta
33
- football: fifa, uefa, afc, ofc, caf, csf, concacaf
34
-
35
- europe3: benelux, euro, schengen
36
-
37
- misc: microstate
38
-
39
- # national regions
40
- brasil: s|South, se|Southeast, co|Centerwest, ne|Northeast, n|North
data/data/tags.3.yml DELETED
@@ -1,23 +0,0 @@
1
- ### setup some grade 3 tags
2
-
3
-
4
- ####
5
-
6
- # categorize countries into brackets by area
7
- area: area_1_000_000_n_up,
8
- area_100_000_to_1_000_000,
9
- area_1_000_to_100_000,
10
- area_1_000_n_less # microstate
11
-
12
- # include all
13
- area2: area_100_000_n_up, area_1_000_n_up
14
-
15
-
16
- # categorize countries into brackets by pop(ulation)
17
- pop: pop_100m_n_up,
18
- pop_10m_to_100m,
19
- pop_1m_to_10m,
20
- pop_1m_n_less
21
-
22
- # include all
23
- pop2: pop_10m_n_up, pop_1m_n_up
@@ -1,113 +0,0 @@
1
-
2
- module WorldDB
3
-
4
- class Runner
5
-
6
- include WorldDB::Models
7
-
8
- def initialize
9
- @logger = Logger.new(STDOUT)
10
- @logger.level = Logger::INFO
11
-
12
- @opts = Opts.new
13
- end
14
-
15
- attr_reader :logger, :opts
16
-
17
-
18
- def run( args )
19
- opt=OptionParser.new do |cmd|
20
-
21
- cmd.banner = "Usage: worlddb [options]"
22
-
23
- ## NB: reserve -c for use with -c/--config
24
- cmd.on( '--create', 'Create DB schema' ) { opts.create = true }
25
- cmd.on( '--setup', "Create DB schema 'n' load builtin world data" ) { opts.setup = true }
26
-
27
- ### todo: in future allow multiple search path??
28
- cmd.on( '-i', '--include PATH', "Data path (default is #{opts.data_path})" ) { |path| opts.data_path = path }
29
-
30
- cmd.on( '--country KEY', "Default country for regions 'n' cities" ) { |key| opts.country = key; }
31
-
32
- ## todo: add (generic) alias -t/--type cities for --cities
33
- ## -t/--type regions for --regions
34
- ## -t/--type countries for --countries --why? why not?
35
-
36
- cmd.on( '--countries', 'Use country plain text fixture reader' ) { opts.countries = true }
37
- cmd.on( '--regions', 'Use regions plain text fixture reader' ) { opts.regions = true }
38
- cmd.on( '--cities', 'Use cities plain text fixture reader' ) { opts.cities = true }
39
-
40
- ## todo: change to --builtin?? more clear why? why not?
41
- cmd.on( '--load', 'Use loader for builtin world data' ) { opts.load = true }
42
-
43
- cmd.on( '--delete', 'Delete all records' ) { opts.delete = true }
44
-
45
- cmd.on( '-v', '--version', "Show version" ) do
46
- puts WorldDB.banner
47
- exit
48
- end
49
-
50
- cmd.on( "--verbose", "Show debug trace" ) do
51
- logger.datetime_format = "%H:%H:%S"
52
- logger.level = Logger::DEBUG
53
-
54
- ActiveRecord::Base.logger = Logger.new(STDOUT)
55
- end
56
-
57
- cmd.on_tail( "-h", "--help", "Show this message" ) do
58
- puts <<EOS
59
-
60
- worlddb - world.db command line tool, version #{VERSION}
61
-
62
- #{cmd.help}
63
-
64
- Examples:
65
- worlddb at/cities # import austrian cities
66
- worlddb --create # create database schema
67
-
68
- More Examples:
69
- worlddb # show stats (table counts, table props)
70
-
71
- Further information:
72
- http://geraldb.github.com/world.db
73
-
74
- EOS
75
- exit
76
- end
77
- end
78
-
79
- opt.parse!( args )
80
-
81
- puts WorldDB.banner
82
-
83
- puts "working directory: #{Dir.pwd}"
84
-
85
- db_config = {
86
- adapter: 'sqlite3',
87
- database: "#{opts.output_path}/world.db"
88
- }
89
-
90
- puts "Connecting to db using settings: "
91
- pp db_config
92
-
93
- ActiveRecord::Base.establish_connection( db_config )
94
-
95
- if opts.setup?
96
- WorldDB.create
97
- WorldDB.read_all
98
- else
99
- WorldDB.create if opts.create?
100
- WorldDB.delete! if opts.delete?
101
-
102
- # read plain text country/region/city fixtures
103
- Reader.new( logger ).run( opts, args )
104
- end
105
-
106
- WorldDB.stats
107
-
108
- puts 'Done.'
109
-
110
- end # method run
111
-
112
- end # class Runner
113
- end # module WorldDB
@@ -1,34 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class CodeReader
4
-
5
- def initialize( logger=nil, path )
6
- if logger.nil?
7
- @logger = Logger.new(STDOUT)
8
- @logger.level = Logger::INFO
9
- else
10
- @logger = logger
11
- end
12
-
13
- @path = path
14
-
15
- ## nb: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
16
- ## - see worlddb/utils.rb
17
-
18
- @code = File.read_utf8( @path )
19
- end
20
-
21
- def eval( klass )
22
- klass.class_eval( @code )
23
-
24
- # NB: same as
25
- #
26
- # module WorldDB
27
- # include WorldDB::Models
28
- # <code here>
29
- # end
30
- end
31
-
32
- attr_reader :logger
33
-
34
- end # class CodeReader
@@ -1,81 +0,0 @@
1
- # encoding: utf-8
2
-
3
-
4
- class HashReader
5
-
6
- def initialize( logger=nil, path )
7
- if logger.nil?
8
- @logger = Logger.new(STDOUT)
9
- @logger.level = Logger::INFO
10
- else
11
- @logger = logger
12
- end
13
-
14
- @path = path
15
-
16
- ## nb: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
17
- ## - see worlddb/utils.rb
18
-
19
- text = File.read_utf8( @path )
20
-
21
- ### hack for syck yaml parser (e.g.ruby 1.9.2) (cannot handle !!null)
22
- ## change it to !null to get plain nil
23
- ## w/ both syck and psych/libyml
24
-
25
- text = text.gsub( '!!null', '!null' )
26
-
27
- ### hacks for yaml
28
-
29
- ### see yaml gotschas
30
- ## - http://www.perlmonks.org/?node_id=738671
31
- ## -
32
-
33
- ## replace all tabs w/ two spaces and issue a warning
34
- ## nb: yaml does NOT support tabs see why here -> yaml.org/faq.html
35
-
36
- text = text.gsub( "\t" ) do |_|
37
- puts "*** warn: hash reader - found tab (\t) replacing w/ two spaces; yaml forbids tabs; see yaml.org/faq.html"
38
- ' ' # replace w/ two spaces
39
- end
40
-
41
- ## quote implicit boolean types on,no,n,y
42
-
43
- ## nb: escape only if key e.g. no: or "free standing" value on its own line e.g.
44
- ## no: no
45
-
46
- text = text.gsub( /^([ ]*)(ON|On|on|NO|No|no|N|n|Y|y)[ ]*:/ ) do |value|
47
- puts "*** warn: hash reader - found implicit bool (#{$1}#{$2}) for key; adding quotes to turn into string; see yaml.org/refcard.html"
48
- # nb: preserve leading spaces for structure - might be significant
49
- "#{$1}'#{$2}':" # add quotes to turn it into a string (not bool e.g. true|false)
50
- end
51
-
52
- ## nb: value must be freestanding (only allow optional eol comment)
53
- ## do not escape if part of string sequence e.g.
54
- ## key: nb,nn,no,se => nb,nn,'no',se -- avoid!!
55
-
56
- text = text.gsub( /:[ ]+(ON|On|on|NO|No|no|N|n|Y|y)[ ]*($| #.*$)/ ) do |value|
57
- puts "*** warn: hash reader - found implicit bool (#{$1}) for value; adding quotes to turn into string; see yaml.org/refcard.html"
58
- ": '#{$1}'" # add quotes to turn it into a string (not bool e.g. true|false)
59
- end
60
-
61
-
62
- @hash = YAML.load( text )
63
- end
64
-
65
- attr_reader :logger
66
-
67
- def each
68
- @hash.each do |key_wild, value_wild|
69
- # normalize
70
- # - key n value as string (not symbols, bool? int? array?)
71
- # - remove leading and trailing whitespace
72
- key = key_wild.to_s.strip
73
- value = value_wild.to_s.strip
74
-
75
- puts "yaml key:#{key_wild.class.name} >>#{key}<<, value:#{value_wild.class.name} >>#{value}<<"
76
-
77
- yield( key, value )
78
- end
79
- end # method each
80
-
81
- end # class HashReader
@@ -1,45 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class LineReader
4
-
5
- def initialize( logger=nil, path )
6
- if logger.nil?
7
- @logger = Logger.new(STDOUT)
8
- @logger.level = Logger::INFO
9
- else
10
- @logger = logger
11
- end
12
-
13
- @path = path
14
-
15
- ## nb: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
16
- ## - see worlddb/utils.rb
17
- @data = File.read_utf8( @path )
18
- end
19
-
20
- attr_reader :logger
21
-
22
-
23
- def each_line
24
- @data.each_line do |line|
25
-
26
- if line =~ /^\s*#/
27
- # skip komments and do NOT copy to result (keep comments secret!)
28
- logger.debug 'skipping comment line'
29
- next
30
- end
31
-
32
- if line =~ /^\s*$/
33
- # kommentar oder leerzeile überspringen
34
- logger.debug 'skipping blank line'
35
- next
36
- end
37
-
38
- # remove leading and trailing whitespace
39
- line = line.strip
40
-
41
- yield( line )
42
- end # each lines
43
- end # method each_line
44
-
45
- end # class LineReader