unclekryon 0.4.9.pre.alpha → 0.4.12.pre.alpha
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.
- checksums.yaml +4 -4
- data/Gemfile +10 -26
- data/Gemfile.lock +20 -24
- data/README.md +3 -2
- data/Rakefile +11 -30
- data/bin/unclekryon +4 -15
- data/hax/kryon.yaml +28 -0
- data/hax/kryon_aums_2002-2005.yaml +460 -0
- data/hax/kryon_aums_2006.yaml +601 -0
- data/hax/kryon_aums_2007.yaml +1024 -0
- data/hax/kryon_aums_2008.yaml +950 -0
- data/hax/kryon_aums_2009.yaml +496 -0
- data/hax/kryon_aums_2010.yaml +1443 -0
- data/hax/kryon_aums_2011.yaml +1458 -0
- data/hax/kryon_aums_2012.yaml +2123 -0
- data/hax/kryon_aums_2013.yaml +1647 -0
- data/hax/kryon_aums_2014.yaml +2478 -0
- data/hax/kryon_aums_2015.yaml +3386 -0
- data/hax/kryon_aums_2016.yaml +3476 -0
- data/hax/kryon_aums_2017.yaml +3712 -0
- data/hax/kryon_aums_2018.yaml +3654 -0
- data/lib/unclekryon/data/album_data.rb +74 -82
- data/lib/unclekryon/data/artist_data.rb +24 -36
- data/lib/unclekryon/data/artist_data_data.rb +29 -41
- data/lib/unclekryon/data/aum_data.rb +20 -32
- data/lib/unclekryon/data/base_data.rb +27 -39
- data/lib/unclekryon/data/pic_data.rb +25 -37
- data/lib/unclekryon/data/release_data.rb +14 -26
- data/lib/unclekryon/data/social_data.rb +6 -18
- data/lib/unclekryon/data/timespan_data.rb +16 -28
- data/lib/unclekryon/dev_opts.rb +7 -19
- data/lib/unclekryon/hacker.rb +121 -135
- data/lib/unclekryon/iso/base_iso.rb +69 -81
- data/lib/unclekryon/iso/can_prov_terr.rb +34 -47
- data/lib/unclekryon/iso/country.rb +34 -51
- data/lib/unclekryon/iso/language.rb +84 -98
- data/lib/unclekryon/iso/region.rb +8 -29
- data/lib/unclekryon/iso/subregion.rb +8 -29
- data/lib/unclekryon/iso/usa_state.rb +28 -41
- data/lib/unclekryon/iso.rb +128 -138
- data/lib/unclekryon/jsoner.rb +31 -50
- data/lib/unclekryon/log.rb +34 -46
- data/lib/unclekryon/parsers/kryon_aum_year_album_parser.rb +163 -167
- data/lib/unclekryon/parsers/kryon_aum_year_parser.rb +122 -127
- data/lib/unclekryon/server.rb +8 -17
- data/lib/unclekryon/trainer.rb +68 -85
- data/lib/unclekryon/uploader.rb +8 -17
- data/lib/unclekryon/util.rb +80 -92
- data/lib/unclekryon/version.rb +4 -16
- data/lib/unclekryon.rb +166 -166
- data/train/kryon.yaml +6077 -0
- data/unclekryon.gemspec +49 -49
- metadata +50 -22
|
@@ -1,23 +1,11 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
1
|
# encoding: UTF-8
|
|
3
2
|
# frozen_string_literal: true
|
|
4
3
|
|
|
5
4
|
#--
|
|
6
5
|
# This file is part of UncleKryon-server.
|
|
7
|
-
# Copyright (c) 2018-
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
|
11
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
12
|
-
# (at your option) any later version.
|
|
13
|
-
#
|
|
14
|
-
# UncleKryon-server is distributed in the hope that it will be useful,
|
|
15
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
-
# GNU General Public License for more details.
|
|
18
|
-
#
|
|
19
|
-
# You should have received a copy of the GNU General Public License
|
|
20
|
-
# along with UncleKryon-server. If not, see <https://www.gnu.org/licenses/>.
|
|
6
|
+
# Copyright (c) 2018-2021 Jonathan Bradley Whited
|
|
7
|
+
#
|
|
8
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
21
9
|
#++
|
|
22
10
|
|
|
23
11
|
|
|
@@ -32,120 +20,120 @@ module UncleKryon
|
|
|
32
20
|
class BaseIso < BaseData
|
|
33
21
|
attr_reader :name
|
|
34
22
|
attr_reader :code
|
|
35
|
-
|
|
36
|
-
def initialize
|
|
23
|
+
|
|
24
|
+
def initialize
|
|
37
25
|
super()
|
|
38
|
-
|
|
26
|
+
|
|
39
27
|
@name = nil
|
|
40
28
|
@code = nil
|
|
41
29
|
end
|
|
42
|
-
|
|
30
|
+
|
|
43
31
|
def self.fix_name(name)
|
|
44
|
-
return
|
|
32
|
+
return flip_word_order(simplify_name(name))
|
|
45
33
|
end
|
|
46
|
-
|
|
34
|
+
|
|
47
35
|
def self.flip_word_order(word)
|
|
48
36
|
# e.g., change 'English, Old' to 'Old English'
|
|
49
|
-
return word.gsub(/([^\,\;]+)[[:space:]]*[\,\;]+[[:space:]]*([^\,\;]+)/,'\\2 \\1').strip
|
|
37
|
+
return word.gsub(/([^\,\;]+)[[:space:]]*[\,\;]+[[:space:]]*([^\,\;]+)/,'\\2 \\1').strip
|
|
50
38
|
end
|
|
51
|
-
|
|
39
|
+
|
|
52
40
|
def self.simplify_code(code)
|
|
53
41
|
# e.g., remove 'US-' from 'US-AL'
|
|
54
|
-
return code.gsub(/[[:alnum:][:space:]]+\-[[:space:]]*/,'').strip
|
|
42
|
+
return code.gsub(/[[:alnum:][:space:]]+\-[[:space:]]*/,'').strip
|
|
55
43
|
end
|
|
56
|
-
|
|
44
|
+
|
|
57
45
|
def self.simplify_name(name)
|
|
58
46
|
# e.g., remove '(the)' from 'United States of America (the)'
|
|
59
|
-
return name.gsub(/[[:space:]]*\([^\)]*\)[[:space:]]*/,'').strip
|
|
47
|
+
return name.gsub(/[[:space:]]*\([^\)]*\)[[:space:]]*/,'').strip
|
|
60
48
|
end
|
|
61
|
-
|
|
62
|
-
def ==(
|
|
63
|
-
return @name ==
|
|
49
|
+
|
|
50
|
+
def ==(other)
|
|
51
|
+
return @name == other.name && @code == other.code
|
|
64
52
|
end
|
|
65
|
-
|
|
66
|
-
def to_s
|
|
53
|
+
|
|
54
|
+
def to_s
|
|
67
55
|
return %Q(["#{@name}",#{@code}])
|
|
68
56
|
end
|
|
69
57
|
end
|
|
70
|
-
|
|
58
|
+
|
|
71
59
|
class BaseIsos
|
|
72
60
|
include Logging
|
|
73
|
-
|
|
61
|
+
|
|
74
62
|
DEFAULT_DIR = 'iso'
|
|
75
|
-
|
|
63
|
+
|
|
76
64
|
attr_reader :id
|
|
77
65
|
attr_reader :values
|
|
78
|
-
|
|
79
|
-
def initialize
|
|
66
|
+
|
|
67
|
+
def initialize
|
|
80
68
|
super()
|
|
81
|
-
|
|
69
|
+
|
|
82
70
|
@id = self.class.get_class_name(self)
|
|
83
71
|
@values = {}
|
|
84
72
|
end
|
|
85
|
-
|
|
73
|
+
|
|
86
74
|
def find(text)
|
|
87
75
|
lang = find_by_name(text)
|
|
88
|
-
return lang unless lang.nil?
|
|
89
|
-
|
|
76
|
+
return lang unless lang.nil?
|
|
77
|
+
|
|
90
78
|
lang = find_by_code(text)
|
|
91
79
|
return lang
|
|
92
80
|
end
|
|
93
|
-
|
|
81
|
+
|
|
94
82
|
def find_by_code(code)
|
|
95
|
-
code = code.gsub(/[[:space:]]+/,'').downcase
|
|
96
|
-
|
|
97
|
-
@values.each
|
|
83
|
+
code = code.gsub(/[[:space:]]+/,'').downcase
|
|
84
|
+
|
|
85
|
+
@values.each do |k,v|
|
|
98
86
|
codes = nil
|
|
99
|
-
|
|
87
|
+
|
|
100
88
|
if v.respond_to?(:codes)
|
|
101
89
|
codes = v.codes()
|
|
102
90
|
elsif v.respond_to?(:code)
|
|
103
|
-
codes = [v.code
|
|
91
|
+
codes = [v.code]
|
|
104
92
|
else
|
|
105
93
|
raise "No codes()/code() method for class #{v.class.name}"
|
|
106
94
|
end
|
|
107
|
-
|
|
108
|
-
codes.each
|
|
109
|
-
next if c.nil?
|
|
110
|
-
c = c.gsub(/[[:space:]]+/,'').downcase
|
|
95
|
+
|
|
96
|
+
codes.each do |c|
|
|
97
|
+
next if c.nil?
|
|
98
|
+
c = c.gsub(/[[:space:]]+/,'').downcase
|
|
111
99
|
return v if c == code
|
|
112
100
|
end
|
|
113
101
|
end
|
|
114
|
-
|
|
102
|
+
|
|
115
103
|
return nil
|
|
116
104
|
end
|
|
117
|
-
|
|
105
|
+
|
|
118
106
|
def find_by_name(name)
|
|
119
|
-
name = name.gsub(/[[:space:]]+/,'').downcase
|
|
120
|
-
|
|
121
|
-
@values.each
|
|
107
|
+
name = name.gsub(/[[:space:]]+/,'').downcase
|
|
108
|
+
|
|
109
|
+
@values.each do |k,v|
|
|
122
110
|
names = nil
|
|
123
|
-
|
|
111
|
+
|
|
124
112
|
if v.respond_to?(:names)
|
|
125
113
|
names = v.names()
|
|
126
114
|
elsif v.respond_to?(:name)
|
|
127
|
-
names = [v.name
|
|
115
|
+
names = [v.name]
|
|
128
116
|
else
|
|
129
117
|
raise "No names()/name() method for class #{v.class.name}"
|
|
130
118
|
end
|
|
131
|
-
|
|
132
|
-
names.each
|
|
133
|
-
next if n.nil?
|
|
134
|
-
n = n.gsub(/[[:space:]]+/,'').downcase
|
|
119
|
+
|
|
120
|
+
names.each do |n|
|
|
121
|
+
next if n.nil?
|
|
122
|
+
n = n.gsub(/[[:space:]]+/,'').downcase
|
|
135
123
|
return v if n == name
|
|
136
124
|
end
|
|
137
125
|
end
|
|
138
|
-
|
|
126
|
+
|
|
139
127
|
return nil
|
|
140
128
|
end
|
|
141
|
-
|
|
129
|
+
|
|
142
130
|
def load_file(filepath)
|
|
143
131
|
y = YAML.load_file(filepath)
|
|
144
132
|
@values.merge!(y[@id])
|
|
145
|
-
|
|
133
|
+
|
|
146
134
|
return self
|
|
147
135
|
end
|
|
148
|
-
|
|
136
|
+
|
|
149
137
|
def save_to_file(filepath)
|
|
150
138
|
File.open(filepath,'w') do |f|
|
|
151
139
|
v = {}
|
|
@@ -153,43 +141,43 @@ module UncleKryon
|
|
|
153
141
|
YAML.dump(v,f)
|
|
154
142
|
end
|
|
155
143
|
end
|
|
156
|
-
|
|
157
|
-
def sort_keys!
|
|
144
|
+
|
|
145
|
+
def sort_keys!
|
|
158
146
|
# Old way: @values = @values.sort().to_h()
|
|
159
|
-
|
|
147
|
+
|
|
160
148
|
new_values = {}
|
|
161
|
-
|
|
162
|
-
@values.keys
|
|
149
|
+
|
|
150
|
+
@values.keys.sort.each do |code|
|
|
163
151
|
new_values[code] = @values[code]
|
|
164
152
|
end
|
|
165
|
-
|
|
153
|
+
|
|
166
154
|
@values = new_values
|
|
167
155
|
return self
|
|
168
156
|
end
|
|
169
|
-
|
|
157
|
+
|
|
170
158
|
def [](code)
|
|
171
159
|
@values[code]
|
|
172
160
|
end
|
|
173
|
-
|
|
161
|
+
|
|
174
162
|
def []=(code,value)
|
|
175
163
|
@values[code] = value
|
|
176
164
|
end
|
|
177
|
-
|
|
165
|
+
|
|
178
166
|
def self.get_class_name(class_var)
|
|
179
167
|
return class_var.class.name.split('::').last
|
|
180
168
|
end
|
|
181
|
-
|
|
169
|
+
|
|
182
170
|
def key?(code)
|
|
183
171
|
@values.key?(code)
|
|
184
172
|
end
|
|
185
|
-
|
|
186
|
-
def to_s
|
|
187
|
-
s = ''.dup
|
|
188
|
-
|
|
189
|
-
@values.each
|
|
173
|
+
|
|
174
|
+
def to_s
|
|
175
|
+
s = ''.dup
|
|
176
|
+
|
|
177
|
+
@values.each do |code,value|
|
|
190
178
|
s << "#{code}: #{value}\n"
|
|
191
179
|
end
|
|
192
|
-
|
|
180
|
+
|
|
193
181
|
return s
|
|
194
182
|
end
|
|
195
183
|
end
|
|
@@ -1,28 +1,14 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
1
|
# encoding: UTF-8
|
|
3
2
|
# frozen_string_literal: true
|
|
4
3
|
|
|
5
4
|
#--
|
|
6
5
|
# This file is part of UncleKryon-server.
|
|
7
|
-
# Copyright (c) 2018-
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
|
11
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
12
|
-
# (at your option) any later version.
|
|
13
|
-
#
|
|
14
|
-
# UncleKryon-server is distributed in the hope that it will be useful,
|
|
15
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
-
# GNU General Public License for more details.
|
|
18
|
-
#
|
|
19
|
-
# You should have received a copy of the GNU General Public License
|
|
20
|
-
# along with UncleKryon-server. If not, see <https://www.gnu.org/licenses/>.
|
|
6
|
+
# Copyright (c) 2018-2021 Jonathan Bradley Whited
|
|
7
|
+
#
|
|
8
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
21
9
|
#++
|
|
22
10
|
|
|
23
11
|
|
|
24
|
-
require 'bundler/setup'
|
|
25
|
-
|
|
26
12
|
require 'nokogiri'
|
|
27
13
|
require 'open-uri'
|
|
28
14
|
|
|
@@ -36,76 +22,77 @@ module UncleKryon
|
|
|
36
22
|
class CanProvTerr < BaseIso
|
|
37
23
|
def initialize(row=nil)
|
|
38
24
|
super()
|
|
39
|
-
|
|
25
|
+
|
|
40
26
|
if row.is_a?(Array)
|
|
41
27
|
@name = self.class.simplify_name(row[2])
|
|
42
28
|
@code = self.class.simplify_code(row[1])
|
|
43
29
|
end
|
|
44
30
|
end
|
|
45
31
|
end
|
|
46
|
-
|
|
32
|
+
|
|
47
33
|
class CanProvsTerrs < BaseIsos
|
|
48
34
|
DEFAULT_FILEPATH = "#{DEFAULT_DIR}/can_provs_terrs.yaml"
|
|
49
|
-
|
|
50
|
-
def initialize
|
|
35
|
+
|
|
36
|
+
def initialize
|
|
51
37
|
super()
|
|
52
|
-
|
|
38
|
+
|
|
53
39
|
@id = 'CAN Provinces & Territories'
|
|
54
40
|
end
|
|
55
|
-
|
|
41
|
+
|
|
56
42
|
def self.load_file(filepath=DEFAULT_FILEPATH)
|
|
57
|
-
return CanProvsTerrs.new
|
|
43
|
+
return CanProvsTerrs.new.load_file(filepath)
|
|
58
44
|
end
|
|
59
|
-
|
|
60
|
-
# @param parse_filepath [String] use web browser's developer tools to copy & paste table HTML
|
|
45
|
+
|
|
46
|
+
# @param parse_filepath [String] use web browser's developer tools to copy & paste table HTML
|
|
47
|
+
# into local file
|
|
61
48
|
# @param save_filepath [String] local file to save YAML to
|
|
62
49
|
# @see https://www.iso.org/obp/ui/#iso:code:3166:CA
|
|
63
50
|
def self.parse_and_save_to_file(parse_filepath,save_filepath=DEFAULT_FILEPATH)
|
|
64
|
-
doc = Nokogiri::HTML(
|
|
51
|
+
doc = Nokogiri::HTML(URI(parse_filepath).open,nil,'utf-8')
|
|
65
52
|
trs = doc.css('tr')
|
|
66
|
-
|
|
67
|
-
provs_terrs = CanProvsTerrs.new
|
|
68
|
-
|
|
69
|
-
trs.each
|
|
53
|
+
|
|
54
|
+
provs_terrs = CanProvsTerrs.new
|
|
55
|
+
|
|
56
|
+
trs.each do |tr|
|
|
70
57
|
tds = tr.css('td')
|
|
71
|
-
|
|
58
|
+
|
|
72
59
|
# Skip French; we just want English
|
|
73
|
-
next if tds[4].content.gsub(/[[:space:]]+/,' ').strip
|
|
74
|
-
|
|
60
|
+
next if tds[4].content.gsub(/[[:space:]]+/,' ').strip.downcase == 'fr'
|
|
61
|
+
|
|
75
62
|
i = 0
|
|
76
63
|
tr = []
|
|
77
|
-
|
|
78
|
-
tds.each
|
|
64
|
+
|
|
65
|
+
tds.each do |td|
|
|
79
66
|
c = td.content
|
|
80
67
|
c.gsub!(/[[:space:]]+/,' ')
|
|
81
|
-
c.strip!
|
|
68
|
+
c.strip!
|
|
82
69
|
tr.push(c)
|
|
83
|
-
|
|
70
|
+
|
|
84
71
|
if (i += 1) >= 7
|
|
85
72
|
#puts tr.inspect()
|
|
86
73
|
prov_terr = CanProvTerr.new(tr)
|
|
87
|
-
raise "CAN prov/terr already exists: #{prov_terr.inspect
|
|
88
|
-
|
|
89
|
-
provs_terrs.values.each_value
|
|
74
|
+
raise "CAN prov/terr already exists: #{prov_terr.inspect}" if provs_terrs.key?(prov_terr.code)
|
|
75
|
+
|
|
76
|
+
provs_terrs.values.each_value do |v|
|
|
90
77
|
puts "Duplicate CAN prov/terr names: #{v.name}" if v.name == prov_terr.name
|
|
91
78
|
end
|
|
92
|
-
|
|
79
|
+
|
|
93
80
|
provs_terrs[prov_terr.code] = prov_terr
|
|
94
|
-
tr.clear
|
|
81
|
+
tr.clear
|
|
95
82
|
i = 0
|
|
96
83
|
end
|
|
97
84
|
end
|
|
98
85
|
end
|
|
99
|
-
|
|
100
|
-
provs_terrs.sort_keys!
|
|
86
|
+
|
|
87
|
+
provs_terrs.sort_keys!
|
|
101
88
|
provs_terrs.save_to_file(save_filepath)
|
|
102
89
|
end
|
|
103
90
|
end
|
|
104
91
|
end
|
|
105
92
|
|
|
106
|
-
if $
|
|
93
|
+
if $PROGRAM_NAME == __FILE__
|
|
107
94
|
if ARGV.length < 1
|
|
108
|
-
puts UncleKryon::CanProvsTerrs.load_file
|
|
95
|
+
puts UncleKryon::CanProvsTerrs.load_file.to_s
|
|
109
96
|
else
|
|
110
97
|
UncleKryon::CanProvsTerrs.parse_and_save_to_file(ARGV[0],(ARGV.length >= 2) ? ARGV[1] :
|
|
111
98
|
UncleKryon::CanProvsTerrs::DEFAULT_FILEPATH)
|
|
@@ -1,28 +1,14 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
1
|
# encoding: UTF-8
|
|
3
2
|
# frozen_string_literal: true
|
|
4
3
|
|
|
5
4
|
#--
|
|
6
5
|
# This file is part of UncleKryon-server.
|
|
7
|
-
# Copyright (c) 2018-
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
|
11
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
12
|
-
# (at your option) any later version.
|
|
13
|
-
#
|
|
14
|
-
# UncleKryon-server is distributed in the hope that it will be useful,
|
|
15
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
-
# GNU General Public License for more details.
|
|
18
|
-
#
|
|
19
|
-
# You should have received a copy of the GNU General Public License
|
|
20
|
-
# along with UncleKryon-server. If not, see <https://www.gnu.org/licenses/>.
|
|
6
|
+
# Copyright (c) 2018-2022 Jonathan Bradley Whited
|
|
7
|
+
#
|
|
8
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
21
9
|
#++
|
|
22
10
|
|
|
23
11
|
|
|
24
|
-
require 'bundler/setup'
|
|
25
|
-
|
|
26
12
|
require 'nokogiri'
|
|
27
13
|
require 'open-uri'
|
|
28
14
|
require 'yaml'
|
|
@@ -42,90 +28,87 @@ module UncleKryon
|
|
|
42
28
|
attr_reader :alpha2_code
|
|
43
29
|
attr_reader :alpha3_code
|
|
44
30
|
attr_reader :region
|
|
45
|
-
|
|
31
|
+
|
|
46
32
|
def initialize(row=nil)
|
|
47
33
|
super()
|
|
48
|
-
|
|
34
|
+
|
|
49
35
|
@names = nil
|
|
50
36
|
@codes = nil
|
|
51
37
|
@alpha2_code = nil
|
|
52
38
|
@alpha3_code = nil
|
|
53
39
|
@region = nil
|
|
54
|
-
|
|
40
|
+
|
|
55
41
|
if row.is_a?(Array)
|
|
56
42
|
@name = self.class.simplify_name(row[0])
|
|
57
43
|
@alpha2_code = row[2]
|
|
58
44
|
@alpha3_code = row[3]
|
|
59
|
-
|
|
45
|
+
|
|
60
46
|
@names = @name
|
|
61
47
|
@code = @alpha3_code
|
|
62
|
-
@codes = [@alpha3_code,@alpha2_code].compact
|
|
48
|
+
@codes = [@alpha3_code,@alpha2_code].compact.uniq
|
|
63
49
|
end
|
|
64
50
|
end
|
|
65
|
-
|
|
66
|
-
def to_s
|
|
67
|
-
s = '['.dup
|
|
51
|
+
|
|
52
|
+
def to_s
|
|
53
|
+
s = '['.dup
|
|
68
54
|
s << %Q("#{@name}","#{@names.join(';')}")
|
|
69
55
|
s << %Q(,#{@code},"#{@codes.join(';')}",#{@alpha2_code},#{@alpha3_code})
|
|
70
|
-
s <<
|
|
56
|
+
s << ",#{@region}"
|
|
71
57
|
s << ']'
|
|
72
|
-
|
|
58
|
+
|
|
73
59
|
return s
|
|
74
60
|
end
|
|
75
61
|
end
|
|
76
|
-
|
|
62
|
+
|
|
77
63
|
class Countries < BaseIsos
|
|
78
64
|
DEFAULT_FILEPATH = "#{DEFAULT_DIR}/countries.yaml"
|
|
79
|
-
|
|
80
|
-
def initialize()
|
|
81
|
-
super()
|
|
82
|
-
end
|
|
83
|
-
|
|
65
|
+
|
|
84
66
|
def self.load_file(filepath=DEFAULT_FILEPATH)
|
|
85
|
-
return Countries.new
|
|
67
|
+
return Countries.new.load_file(filepath)
|
|
86
68
|
end
|
|
87
|
-
|
|
88
|
-
# @param parse_filepath [String] use web browser's developer tools to copy & paste table HTML
|
|
69
|
+
|
|
70
|
+
# @param parse_filepath [String] use web browser's developer tools to copy & paste table HTML
|
|
71
|
+
# into local file
|
|
89
72
|
# @param save_filepath [String] local file to save YAML to
|
|
90
73
|
# @see https://www.iso.org/obp/ui/#search/code/
|
|
91
74
|
def self.parse_and_save_to_file(parse_filepath,save_filepath=DEFAULT_FILEPATH)
|
|
92
|
-
doc = Nokogiri::HTML(
|
|
75
|
+
doc = Nokogiri::HTML(URI(parse_filepath).open,nil,'utf-8')
|
|
93
76
|
tds = doc.css('td')
|
|
94
|
-
|
|
95
|
-
countries = Countries.new
|
|
77
|
+
|
|
78
|
+
countries = Countries.new
|
|
96
79
|
i = 0
|
|
97
80
|
tr = []
|
|
98
|
-
|
|
81
|
+
|
|
99
82
|
tds.each do |td|
|
|
100
83
|
c = td.content
|
|
101
84
|
c.gsub!(/[[:space:]]+/,' ')
|
|
102
|
-
c.strip!
|
|
85
|
+
c.strip!
|
|
103
86
|
tr.push(c)
|
|
104
|
-
|
|
87
|
+
|
|
105
88
|
if (i += 1) >= 5
|
|
106
89
|
#puts tr.inspect()
|
|
107
90
|
country = Country.new(tr)
|
|
108
|
-
raise "Country already exists: #{country.inspect
|
|
109
|
-
|
|
110
|
-
countries.values.each_value
|
|
91
|
+
raise "Country already exists: #{country.inspect}" if countries.key?(country.code)
|
|
92
|
+
|
|
93
|
+
countries.values.each_value do |v|
|
|
111
94
|
puts "Duplicate country names: #{v.name}" if v.name == country.name
|
|
112
95
|
end
|
|
113
|
-
|
|
96
|
+
|
|
114
97
|
countries[country.code] = country
|
|
115
|
-
tr.clear
|
|
98
|
+
tr.clear
|
|
116
99
|
i = 0
|
|
117
100
|
end
|
|
118
101
|
end
|
|
119
|
-
|
|
120
|
-
countries.sort_keys!
|
|
102
|
+
|
|
103
|
+
countries.sort_keys!
|
|
121
104
|
countries.save_to_file(save_filepath)
|
|
122
105
|
end
|
|
123
106
|
end
|
|
124
107
|
end
|
|
125
108
|
|
|
126
|
-
if $
|
|
109
|
+
if $PROGRAM_NAME == __FILE__
|
|
127
110
|
if ARGV.length < 1
|
|
128
|
-
puts UncleKryon::Countries.load_file
|
|
111
|
+
puts UncleKryon::Countries.load_file.to_s
|
|
129
112
|
else
|
|
130
113
|
UncleKryon::Countries.parse_and_save_to_file(ARGV[0],(ARGV.length >= 2) ? ARGV[1] :
|
|
131
114
|
UncleKryon::Countries::DEFAULT_FILEPATH)
|