unclekryon 0.4.10 → 0.4.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -19
  3. data/Gemfile.lock +19 -23
  4. data/README.md +3 -2
  5. data/Rakefile +11 -30
  6. data/bin/unclekryon +4 -15
  7. data/hax/kryon.yaml +28 -0
  8. data/hax/kryon_aums_2002-2005.yaml +460 -0
  9. data/hax/kryon_aums_2006.yaml +601 -0
  10. data/hax/kryon_aums_2007.yaml +1024 -0
  11. data/hax/kryon_aums_2008.yaml +950 -0
  12. data/hax/kryon_aums_2009.yaml +496 -0
  13. data/hax/kryon_aums_2010.yaml +1443 -0
  14. data/hax/kryon_aums_2011.yaml +1458 -0
  15. data/hax/kryon_aums_2012.yaml +2123 -0
  16. data/hax/kryon_aums_2013.yaml +1647 -0
  17. data/hax/kryon_aums_2014.yaml +2478 -0
  18. data/hax/kryon_aums_2015.yaml +3386 -0
  19. data/hax/kryon_aums_2016.yaml +3476 -0
  20. data/hax/kryon_aums_2017.yaml +3712 -0
  21. data/hax/kryon_aums_2018.yaml +3654 -0
  22. data/lib/unclekryon.rb +165 -165
  23. data/lib/unclekryon/data/album_data.rb +74 -82
  24. data/lib/unclekryon/data/artist_data.rb +24 -36
  25. data/lib/unclekryon/data/artist_data_data.rb +29 -41
  26. data/lib/unclekryon/data/aum_data.rb +20 -32
  27. data/lib/unclekryon/data/base_data.rb +27 -39
  28. data/lib/unclekryon/data/pic_data.rb +25 -37
  29. data/lib/unclekryon/data/release_data.rb +14 -26
  30. data/lib/unclekryon/data/social_data.rb +6 -18
  31. data/lib/unclekryon/data/timespan_data.rb +16 -28
  32. data/lib/unclekryon/dev_opts.rb +7 -19
  33. data/lib/unclekryon/hacker.rb +119 -133
  34. data/lib/unclekryon/iso.rb +128 -138
  35. data/lib/unclekryon/iso/base_iso.rb +69 -81
  36. data/lib/unclekryon/iso/can_prov_terr.rb +34 -47
  37. data/lib/unclekryon/iso/country.rb +36 -49
  38. data/lib/unclekryon/iso/language.rb +86 -96
  39. data/lib/unclekryon/iso/region.rb +11 -25
  40. data/lib/unclekryon/iso/subregion.rb +11 -25
  41. data/lib/unclekryon/iso/usa_state.rb +28 -41
  42. data/lib/unclekryon/jsoner.rb +31 -50
  43. data/lib/unclekryon/log.rb +34 -46
  44. data/lib/unclekryon/parsers/kryon_aum_year_album_parser.rb +163 -167
  45. data/lib/unclekryon/parsers/kryon_aum_year_parser.rb +122 -127
  46. data/lib/unclekryon/server.rb +8 -17
  47. data/lib/unclekryon/trainer.rb +69 -83
  48. data/lib/unclekryon/uploader.rb +8 -17
  49. data/lib/unclekryon/util.rb +80 -92
  50. data/lib/unclekryon/version.rb +4 -16
  51. data/train/kryon.yaml +6077 -0
  52. data/unclekryon.gemspec +44 -42
  53. metadata +59 -16
@@ -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-2019 Jonathan Bradley Whited (@esotericpig)
8
- #
9
- # UncleKryon-server is free software: you can redistribute it and/or modify
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 'yaml'
27
13
 
28
14
  require 'unclekryon/dev_opts'
@@ -43,7 +29,7 @@ module UncleKryon
43
29
  class Iso
44
30
  DEFAULT_FILEPATH = "#{BaseIsos::DEFAULT_DIR}/iso.yaml"
45
31
  ID = 'ISO'
46
-
32
+
47
33
  @@can_provs_terrs = nil
48
34
  @@countries = nil
49
35
  @@iso = nil
@@ -51,42 +37,43 @@ module UncleKryon
51
37
  @@regions = nil
52
38
  @@subregions = nil
53
39
  @@usa_states = nil
54
-
40
+
55
41
  attr_accessor :updated_can_provs_terrs_on
56
42
  attr_accessor :updated_countries_on
57
43
  attr_accessor :updated_languages_on
58
44
  attr_accessor :updated_regions_on
59
45
  attr_accessor :updated_subregions_on
60
46
  attr_accessor :updated_usa_states_on
61
-
62
- def initialize()
47
+
48
+ def initialize
63
49
  super()
64
-
65
- update_all()
50
+
51
+ update_all
66
52
  end
67
-
68
- def self.can_provs_terrs()
53
+
54
+ def self.can_provs_terrs
69
55
  if !@@can_provs_terrs
70
- @@can_provs_terrs = CanProvsTerrs.load_file()
56
+ @@can_provs_terrs = CanProvsTerrs.load_file
71
57
  end
72
58
  return @@can_provs_terrs
73
59
  end
74
-
75
- def self.countries()
60
+
61
+ def self.countries
76
62
  if !@@countries
77
- @@countries = Countries.load_file()
63
+ @@countries = Countries.load_file
78
64
  end
79
65
  return @@countries
80
66
  end
81
-
67
+
82
68
  def self.find_kryon_locations(text)
83
69
  locs = []
84
-
70
+
85
71
  # Fix bad data
86
- text = text.gsub(/\A[[:space:]]*SASKATOON\-CALGARY[[:space:]]*\z/,'SASKATOON, SASKATCHEWAN, CANADA / CALGARY, ALBERTA, CANADA')
87
-
72
+ text = text.gsub(/\A[[:space:]]*SASKATOON\-CALGARY[[:space:]]*\z/,
73
+ 'SASKATOON, SASKATCHEWAN, CANADA / CALGARY, ALBERTA, CANADA')
74
+
88
75
  # Multiple countries are separated by '/' or '&'
89
- text.split(/[[:space:]]*[\/\&][[:space:]]*/).each() do |t|
76
+ text.split(%r{[[:space:]]*[/\&][[:space:]]*}).each do |t|
90
77
  # Fix misspellings and/or weird shortenings
91
78
  t = t.gsub(/Kansas[[:space:]]*\,[[:space:]]*City/i,'Kansas City')
92
79
  t = t.gsub(/[\+\*]+/,'') # Means more countries, but won't worry about it (since not listed)
@@ -95,9 +82,12 @@ module UncleKryon
95
82
  t = t.gsub(/\A[[:space:]]*NEWPORT[[:space:]]+BEACH[[:space:]]*\z/,'Newport Beach, California')
96
83
  t = t.gsub(/\A[[:space:]]*SAN[[:space:]]+RAFAEL[[:space:]]*\z/,'San Rafael, California')
97
84
  t = t.gsub(/\A[[:space:]]*MILANO\,[[:space:]]*MARITTIMA[[:space:]]*\z/,'MILANO MARITTIMA, ITALY')
98
- t = t.gsub(/\A[[:space:]]*MAR[[:space:]]+DEL[[:space:]]+PLATA[[:space:]]*\z/,'MAR DEL PLATA, ARGENTINA')
99
- t = t.gsub(/\A[[:space:]]*PATAGONIA[[:space:]]+CRUISE[[:space:]]+2012[[:space:]]*\z/,'Patagonia, South America')
100
- t = t.gsub(/\A[[:space:]]*PHILADELPHIA,[[:space:]]+PENNSYLVANNIA[[:space:]]*\z/,'Philadelphia, Pennsylvania')
85
+ t = t.gsub(/\A[[:space:]]*MAR[[:space:]]+DEL[[:space:]]+PLATA[[:space:]]*\z/,
86
+ 'MAR DEL PLATA, ARGENTINA')
87
+ t = t.gsub(/\A[[:space:]]*PATAGONIA[[:space:]]+CRUISE[[:space:]]+2012[[:space:]]*\z/,
88
+ 'Patagonia, South America')
89
+ t = t.gsub(/\A[[:space:]]*PHILADELPHIA,[[:space:]]+PENNSYLVANNIA[[:space:]]*\z/,
90
+ 'Philadelphia, Pennsylvania')
101
91
  t = t.gsub(/\ATHE[[:space:]]+AWAKENING[[:space:]]+ZONE.COM\z/,'World')
102
92
  t = t.gsub(/\ASEDONA, AZ - Summer Light Conference\z/,'Sedona, AZ')
103
93
  t = t.gsub(/\AHAWAII CRUISE 11\z/,'Hawaii')
@@ -113,72 +103,72 @@ module UncleKryon
113
103
  t = t.gsub(/\AHAWAI\'I\s+CRUISE\s+[[:digit:]]+\z/i,'Hawaii')
114
104
  t = t.gsub(/\AALASKA\s+CRUISE\s+[[:digit:]]+\z/i,'Alaska')
115
105
  t = t.gsub(/\AGLASS\s+HOUSE\s+MT\.\s+\(AU\)\z/i,'Glass House Mountains, Australia')
116
-
106
+
117
107
  parts = t.split(/[[:space:]\,\-]+/)
118
108
  last = parts.last
119
- last2 = (parts.length() >= 2) ? (parts[-2] + last) : nil
120
-
109
+ last2 = (parts.length >= 2) ? (parts[-2] + last) : nil
110
+
121
111
  city = nil
122
112
  state = nil
123
- country = countries().find_by_name(last) # By name because e.g. code CO is Colorado and Colombia
113
+ country = countries.find_by_name(last) # By name because e.g. code CO is Colorado and Colombia
124
114
  subregion = nil
125
115
  region = nil
126
-
116
+
127
117
  parse_state = true
128
- state_i = parts.length() - 1
129
-
118
+ state_i = parts.length - 1
119
+
130
120
  # USA state?
131
- if country.nil?()
121
+ if country.nil?
132
122
  parse_state = false
133
- state = usa_states().find(last)
134
-
135
- if state.nil?() && !last2.nil?()
136
- state = usa_states().find_by_name(last2)
137
- state_i = parts.length() - 2 unless state.nil?()
123
+ state = usa_states.find(last)
124
+
125
+ if state.nil? && !last2.nil?
126
+ state = usa_states.find_by_name(last2)
127
+ state_i = parts.length - 2 unless state.nil?
138
128
  end
139
-
140
- if state.nil?()
129
+
130
+ if state.nil?
141
131
  # CAN prov/terr? (use state var)
142
- state = can_provs_terrs().find(last)
143
-
144
- if state.nil?() && !last2.nil?()
145
- state = can_provs_terrs().find_by_name(last2)
146
- state_i = parts.length() - 2 unless state.nil?()
132
+ state = can_provs_terrs.find(last)
133
+
134
+ if state.nil? && !last2.nil?
135
+ state = can_provs_terrs.find_by_name(last2)
136
+ state_i = parts.length - 2 unless state.nil?
147
137
  end
148
-
149
- if state.nil?()
138
+
139
+ if state.nil?
150
140
  # Try country code
151
- country = countries().find_by_code(last) # Try by code; e.g., CAN for Canada
152
-
153
- if country.nil?()
154
- country = countries().find_by_name(t)
155
- state_i = 0 unless country.nil?()
141
+ country = countries.find_by_code(last) # Try by code; e.g., CAN for Canada
142
+
143
+ if country.nil?
144
+ country = countries.find_by_name(t)
145
+ state_i = 0 unless country.nil?
156
146
  end
157
- if country.nil?() && !last2.nil?()
158
- country = countries().find_by_name(last2)
159
- state_i = 0 unless country.nil?()
147
+ if country.nil? && !last2.nil?
148
+ country = countries.find_by_name(last2)
149
+ state_i = 0 unless country.nil?
160
150
  end
161
-
162
- if country.nil?()
151
+
152
+ if country.nil?
163
153
  # Subregion?
164
- subregion = subregions().find_by_name(t)
165
-
166
- if subregion.nil?() && !last2.nil?()
167
- subregion = subregions().find_by_name(last2)
154
+ subregion = subregions.find_by_name(t)
155
+
156
+ if subregion.nil? && !last2.nil?
157
+ subregion = subregions.find_by_name(last2)
168
158
  end
169
-
170
- if subregion.nil?()
159
+
160
+ if subregion.nil?
171
161
  # Region?
172
- region = regions().find_by_name(t)
173
-
174
- if region.nil?() && !last2.nil?()
175
- region = regions().find_by_name(last2)
162
+ region = regions.find_by_name(t)
163
+
164
+ if region.nil? && !last2.nil?
165
+ region = regions.find_by_name(last2)
176
166
  end
177
-
178
- if region.nil?()
167
+
168
+ if region.nil?
179
169
  msg = %Q(No state/country/region: "#{text}","#{t}","#{last}")
180
-
181
- if DevOpts.instance.dev?()
170
+
171
+ if DevOpts.instance.dev?
182
172
  raise msg
183
173
  else
184
174
  log.warn(msg)
@@ -197,111 +187,111 @@ module UncleKryon
197
187
  end
198
188
  else
199
189
  state = state.code
200
- country = countries().find_by_code('CAN').code
190
+ country = countries.find_by_code('CAN').code
201
191
  end
202
192
  else
203
193
  state = state.code
204
- country = countries().find_by_code('USA').code
194
+ country = countries.find_by_code('USA').code
205
195
  end
206
196
  else
207
197
  country = country.code
208
198
  end
209
-
210
- if region.nil?() || subregion.nil?()
199
+
200
+ if region.nil? || subregion.nil?
211
201
  # Not USA
212
202
  if parse_state
213
- if parts.length() >= 2
214
- state = parts[-2].gsub(/[[:space:]]+/,' ').strip()
215
-
203
+ if parts.length >= 2
204
+ state = parts[-2].gsub(/[[:space:]]+/,' ').strip
205
+
216
206
  # CAN prov/terr? (use state var)
217
- if country == countries().find_by_code('CAN').code
218
- state = can_provs_terrs().find(state)
219
-
220
- if state.nil?()
221
- if parts.length() >= 3
222
- state = can_provs_terrs().find_by_name(parts[-3] + parts[-2])
223
- state_i = parts.length() - 3 unless state.nil?()
207
+ if country == countries.find_by_code('CAN').code
208
+ state = can_provs_terrs.find(state)
209
+
210
+ if state.nil?
211
+ if parts.length >= 3
212
+ state = can_provs_terrs.find_by_name(parts[-3] + parts[-2])
213
+ state_i = parts.length - 3 unless state.nil?
224
214
  end
225
215
  else
226
216
  state = state.code
227
- state_i = parts.length() - 2
217
+ state_i = parts.length - 2
228
218
  end
229
219
  else
230
- if state.length() == 2
231
- state = state.upcase()
232
- state_i = parts.length() - 2
220
+ if state.length == 2
221
+ state = state.upcase
222
+ state_i = parts.length - 2
233
223
  else
234
224
  state = nil
235
225
  end
236
226
  end
237
227
  end
238
228
  end
239
-
229
+
240
230
  # City
241
231
  city = []
242
- for i in 0...state_i
243
- c = parts[i].gsub(/[[:space:]]+/,' ').strip()
244
- city.push(c) unless c.empty?()
232
+ (0...state_i).each do |i|
233
+ c = parts[i].gsub(/[[:space:]]+/,' ').strip
234
+ city.push(c) unless c.empty?
245
235
  end
246
- city = city.compact()
247
- city = city.empty?() ? nil : city.map(&:capitalize).join(' ')
248
-
236
+ city = city.compact
237
+ city = city.empty? ? nil : city.map(&:capitalize).join(' ')
238
+
249
239
  # Region
250
- if !country.nil?()
251
- region = countries().find_by_code(country).region
240
+ if !country.nil?
241
+ region = countries.find_by_code(country).region
252
242
  end
253
243
  end
254
-
244
+
255
245
  # Location
256
246
  loc = [city,state,country,subregion,region] # Don't do compact(); we want all 4 ','
257
- locs.push(loc.join(',')) unless loc.compact().empty?()
247
+ locs.push(loc.join(',')) unless loc.compact.empty?
258
248
  end
259
-
260
- return locs.empty?() ? nil : locs
249
+
250
+ return locs.empty? ? nil : locs
261
251
  end
262
-
263
- def self.iso()
252
+
253
+ def self.iso
264
254
  if !@@iso
265
- @@iso = Iso.load_file()
255
+ @@iso = Iso.load_file
266
256
  end
267
257
  return @@iso
268
258
  end
269
-
270
- def self.languages()
259
+
260
+ def self.languages
271
261
  if !@@languages
272
- @@languages = Languages.load_file()
262
+ @@languages = Languages.load_file
273
263
  end
274
264
  return @@languages
275
265
  end
276
-
266
+
277
267
  def self.load_file(filepath=DEFAULT_FILEPATH)
278
268
  y = YAML.load_file(filepath)
279
269
  iso = y[ID]
280
270
  return iso
281
271
  end
282
-
283
- def self.regions()
272
+
273
+ def self.regions
284
274
  if !@@regions
285
- @@regions = Regions.load_file()
275
+ @@regions = Regions.load_file
286
276
  end
287
277
  return @@regions
288
278
  end
289
-
279
+
290
280
  def save_to_file(filepath=DEFAULT_FILEPATH)
291
281
  File.open(filepath,'w') do |f|
292
- iso = {ID=>self}
282
+ iso = {ID => self}
293
283
  YAML.dump(iso,f)
294
284
  end
295
285
  end
296
-
297
- def self.subregions()
286
+
287
+ def self.subregions
298
288
  if !@@subregions
299
- @@subregions = Subregions.load_file()
289
+ @@subregions = Subregions.load_file
300
290
  end
301
291
  return @@subregions
302
292
  end
303
-
304
- def update_all()
293
+
294
+ def update_all
305
295
  @updated_can_provs_terrs_on = BaseData.max_updated_on_s(self.class.can_provs_terrs.values)
306
296
  @updated_countries_on = BaseData.max_updated_on_s(self.class.countries.values)
307
297
  @updated_languages_on = BaseData.max_updated_on_s(self.class.languages.values)
@@ -309,16 +299,16 @@ module UncleKryon
309
299
  @updated_subregions_on = BaseData.max_updated_on_s(self.class.subregions.values)
310
300
  @updated_usa_states_on = BaseData.max_updated_on_s(self.class.usa_states.values)
311
301
  end
312
-
313
- def self.usa_states()
302
+
303
+ def self.usa_states
314
304
  if !@@usa_states
315
- @@usa_states = UsaStates.load_file()
305
+ @@usa_states = UsaStates.load_file
316
306
  end
317
307
  return @@usa_states
318
308
  end
319
-
320
- def to_s()
321
- s = 'Updated On:'.dup()
309
+
310
+ def to_s
311
+ s = 'Updated On:'.dup
322
312
  s << "\n- CAN Provs/Terrs: #{@updated_can_provs_terrs_on}"
323
313
  s << "\n- Countries: #{@updated_countries_on}"
324
314
  s << "\n- Languages: #{@updated_languages_on}"
@@ -330,7 +320,7 @@ module UncleKryon
330
320
  end
331
321
  end
332
322
 
333
- if $0 == __FILE__
323
+ if $PROGRAM_NAME == __FILE__
334
324
  puts UncleKryon::Iso.can_provs_terrs['ON']
335
325
  puts UncleKryon::Iso.countries['USA']
336
326
  puts UncleKryon::Iso.languages['eng']
@@ -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-2019 Jonathan Bradley Whited (@esotericpig)
8
- #
9
- # UncleKryon-server is free software: you can redistribute it and/or modify
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 self.flip_word_order(self.simplify_name(name))
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 ==(y)
63
- return @name == y.name && @code == y.code
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() do |k,v|
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() do |c|
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() do |k,v|
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() do |n|
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().sort().each() do |code|
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() do |code,value|
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