Class: UncleKryon::Iso
- Inherits:
-
Object
- Object
- UncleKryon::Iso
- Defined in:
- lib/unclekryon/iso.rb
Constant Summary collapse
- DEFAULT_FILEPATH =
"#{BaseIsos::DEFAULT_DIR}/iso.yaml"
- ID =
'ISO'
- @@can_provs_terrs =
nil
- @@countries =
nil
- @@iso =
nil
- @@languages =
nil
- @@regions =
nil
- @@subregions =
nil
- @@usa_states =
nil
Instance Attribute Summary collapse
-
#updated_can_provs_terrs_on ⇒ Object
Returns the value of attribute updated_can_provs_terrs_on.
-
#updated_countries_on ⇒ Object
Returns the value of attribute updated_countries_on.
-
#updated_languages_on ⇒ Object
Returns the value of attribute updated_languages_on.
-
#updated_regions_on ⇒ Object
Returns the value of attribute updated_regions_on.
-
#updated_subregions_on ⇒ Object
Returns the value of attribute updated_subregions_on.
-
#updated_usa_states_on ⇒ Object
Returns the value of attribute updated_usa_states_on.
Class Method Summary collapse
- .can_provs_terrs ⇒ Object
- .countries ⇒ Object
- .find_kryon_locations(text) ⇒ Object
- .iso ⇒ Object
- .languages ⇒ Object
- .load_file(filepath = DEFAULT_FILEPATH) ⇒ Object
- .regions ⇒ Object
- .subregions ⇒ Object
- .usa_states ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Iso
constructor
A new instance of Iso.
- #save_to_file(filepath = DEFAULT_FILEPATH) ⇒ Object
- #to_s ⇒ Object
- #update_all ⇒ Object
Constructor Details
#initialize ⇒ Iso
Returns a new instance of Iso.
48 49 50 51 52 |
# File 'lib/unclekryon/iso.rb', line 48 def initialize super() update_all end |
Instance Attribute Details
#updated_can_provs_terrs_on ⇒ Object
Returns the value of attribute updated_can_provs_terrs_on.
41 42 43 |
# File 'lib/unclekryon/iso.rb', line 41 def updated_can_provs_terrs_on @updated_can_provs_terrs_on end |
#updated_countries_on ⇒ Object
Returns the value of attribute updated_countries_on.
42 43 44 |
# File 'lib/unclekryon/iso.rb', line 42 def updated_countries_on @updated_countries_on end |
#updated_languages_on ⇒ Object
Returns the value of attribute updated_languages_on.
43 44 45 |
# File 'lib/unclekryon/iso.rb', line 43 def updated_languages_on @updated_languages_on end |
#updated_regions_on ⇒ Object
Returns the value of attribute updated_regions_on.
44 45 46 |
# File 'lib/unclekryon/iso.rb', line 44 def updated_regions_on @updated_regions_on end |
#updated_subregions_on ⇒ Object
Returns the value of attribute updated_subregions_on.
45 46 47 |
# File 'lib/unclekryon/iso.rb', line 45 def updated_subregions_on @updated_subregions_on end |
#updated_usa_states_on ⇒ Object
Returns the value of attribute updated_usa_states_on.
46 47 48 |
# File 'lib/unclekryon/iso.rb', line 46 def updated_usa_states_on @updated_usa_states_on end |
Class Method Details
.can_provs_terrs ⇒ Object
54 55 56 57 58 59 |
# File 'lib/unclekryon/iso.rb', line 54 def self.can_provs_terrs if !@@can_provs_terrs @@can_provs_terrs = CanProvsTerrs.load_file end return @@can_provs_terrs end |
.countries ⇒ Object
61 62 63 64 65 66 |
# File 'lib/unclekryon/iso.rb', line 61 def self.countries if !@@countries @@countries = Countries.load_file end return @@countries end |
.find_kryon_locations(text) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/unclekryon/iso.rb', line 68 def self.find_kryon_locations(text) locs = [] # Fix bad data text = text.gsub(/\A[[:space:]]*SASKATOON\-CALGARY[[:space:]]*\z/, 'SASKATOON, SASKATCHEWAN, CANADA / CALGARY, ALBERTA, CANADA') # Multiple countries are separated by '/' or '&' text.split(%r{[[:space:]]*[/\&][[:space:]]*}).each do |t| # Fix misspellings and/or weird shortenings t = t.gsub(/Kansas[[:space:]]*\,[[:space:]]*City/i,'Kansas City') t = t.gsub(/[\+\*]+/,'') # Means more countries, but won't worry about it (since not listed) t = t.gsub(/Berkeley[[:space:]]+Spings/i,'Berkeley Springs, WV') t = t.gsub(/SWITZ[[:space:]]*\z/i,'Switzerland') t = t.gsub(/\A[[:space:]]*NEWPORT[[:space:]]+BEACH[[:space:]]*\z/,'Newport Beach, California') t = t.gsub(/\A[[:space:]]*SAN[[:space:]]+RAFAEL[[:space:]]*\z/,'San Rafael, California') t = t.gsub(/\A[[:space:]]*MILANO\,[[:space:]]*MARITTIMA[[:space:]]*\z/,'MILANO MARITTIMA, ITALY') t = t.gsub(/\A[[:space:]]*MAR[[:space:]]+DEL[[:space:]]+PLATA[[:space:]]*\z/, 'MAR DEL PLATA, ARGENTINA') t = t.gsub(/\A[[:space:]]*PATAGONIA[[:space:]]+CRUISE[[:space:]]+2012[[:space:]]*\z/, 'Patagonia, South America') t = t.gsub(/\A[[:space:]]*PHILADELPHIA,[[:space:]]+PENNSYLVANNIA[[:space:]]*\z/, 'Philadelphia, Pennsylvania') t = t.gsub(/\ATHE[[:space:]]+AWAKENING[[:space:]]+ZONE.COM\z/,'World') t = t.gsub(/\ASEDONA, AZ - Summer Light Conference\z/,'Sedona, AZ') t = t.gsub(/\AHAWAII CRUISE 11\z/,'Hawaii') t = t.gsub(/\A28 AUDIO FILES - 6 COUNTRIES\z/,'World') t = t.gsub(/\ABLOGTALKRADIO\.COM\z/,'World') t = t.gsub(/\AAWAKENINGZONE\.COM\z/,'World') t = t.gsub(/\AGEMATRIA\s+SEMINAR\z/,'Sedona, Arizona') t = t.gsub(/\AKONA\,\s+HAWAI\'I\z/,'Kona, Hawaii') t = t.gsub(/\ATALKSHOE\.COM\z/,'World') t = t.gsub(/\AConnor\'s\s+Corner\z/,'World') t = t.gsub(/\AUNITED\s+NATIONS,\s+NEW\s+YORK\s+CITY\z/i,'United Nations, New York City, NY') t = t.gsub(/\AMEDITERRANEAN\s+CRUISE\s+[[:digit:]]+\z/i,'Western Mediterranean') t = t.gsub(/\AHAWAI\'I\s+CRUISE\s+[[:digit:]]+\z/i,'Hawaii') t = t.gsub(/\AALASKA\s+CRUISE\s+[[:digit:]]+\z/i,'Alaska') t = t.gsub(/\AGLASS\s+HOUSE\s+MT\.\s+\(AU\)\z/i,'Glass House Mountains, Australia') parts = t.split(/[[:space:]\,\-]+/) last = parts.last last2 = (parts.length >= 2) ? (parts[-2] + last) : nil city = nil state = nil country = countries.find_by_name(last) # By name because e.g. code CO is Colorado and Colombia subregion = nil region = nil parse_state = true state_i = parts.length - 1 # USA state? if country.nil? parse_state = false state = usa_states.find(last) if state.nil? && !last2.nil? state = usa_states.find_by_name(last2) state_i = parts.length - 2 unless state.nil? end if state.nil? # CAN prov/terr? (use state var) state = can_provs_terrs.find(last) if state.nil? && !last2.nil? state = can_provs_terrs.find_by_name(last2) state_i = parts.length - 2 unless state.nil? end if state.nil? # Try country code country = countries.find_by_code(last) # Try by code; e.g., CAN for Canada if country.nil? country = countries.find_by_name(t) state_i = 0 unless country.nil? end if country.nil? && !last2.nil? country = countries.find_by_name(last2) state_i = 0 unless country.nil? end if country.nil? # Subregion? subregion = subregions.find_by_name(t) if subregion.nil? && !last2.nil? subregion = subregions.find_by_name(last2) end if subregion.nil? # Region? region = regions.find_by_name(t) if region.nil? && !last2.nil? region = regions.find_by_name(last2) end if region.nil? msg = %Q(No state/country/region: "#{text}","#{t}","#{last}") if DevOpts.instance.dev? raise msg else log.warn(msg) end else region = region.code state_i = 0 end else subregion = subregion.code state_i = 0 end else country = country.code parse_state = true unless state_i == 0 end else state = state.code country = countries.find_by_code('CAN').code end else state = state.code country = countries.find_by_code('USA').code end else country = country.code end if region.nil? || subregion.nil? # Not USA if parse_state if parts.length >= 2 state = parts[-2].gsub(/[[:space:]]+/,' ').strip # CAN prov/terr? (use state var) if country == countries.find_by_code('CAN').code state = can_provs_terrs.find(state) if state.nil? if parts.length >= 3 state = can_provs_terrs.find_by_name(parts[-3] + parts[-2]) state_i = parts.length - 3 unless state.nil? end else state = state.code state_i = parts.length - 2 end else if state.length == 2 state = state.upcase state_i = parts.length - 2 else state = nil end end end end # City city = [] (0...state_i).each do |i| c = parts[i].gsub(/[[:space:]]+/,' ').strip city.push(c) unless c.empty? end city = city.compact city = city.empty? ? nil : city.map(&:capitalize).join(' ') # Region if !country.nil? region = countries.find_by_code(country).region end end # Location loc = [city,state,country,subregion,region] # Don't do compact(); we want all 4 ',' locs.push(loc.join(',')) unless loc.compact.empty? end return locs.empty? ? nil : locs end |
.iso ⇒ Object
253 254 255 256 257 258 |
# File 'lib/unclekryon/iso.rb', line 253 def self.iso if !@@iso @@iso = Iso.load_file end return @@iso end |
.languages ⇒ Object
260 261 262 263 264 265 |
# File 'lib/unclekryon/iso.rb', line 260 def self.languages if !@@languages @@languages = Languages.load_file end return @@languages end |
.load_file(filepath = DEFAULT_FILEPATH) ⇒ Object
267 268 269 270 271 |
# File 'lib/unclekryon/iso.rb', line 267 def self.load_file(filepath=DEFAULT_FILEPATH) y = YAML.load_file(filepath) iso = y[ID] return iso end |
.regions ⇒ Object
273 274 275 276 277 278 |
# File 'lib/unclekryon/iso.rb', line 273 def self.regions if !@@regions @@regions = Regions.load_file end return @@regions end |
.subregions ⇒ Object
287 288 289 290 291 292 |
# File 'lib/unclekryon/iso.rb', line 287 def self.subregions if !@@subregions @@subregions = Subregions.load_file end return @@subregions end |
Instance Method Details
#save_to_file(filepath = DEFAULT_FILEPATH) ⇒ Object
280 281 282 283 284 285 |
# File 'lib/unclekryon/iso.rb', line 280 def save_to_file(filepath=DEFAULT_FILEPATH) File.open(filepath,'w') do |f| iso = {ID => self} YAML.dump(iso,f) end end |
#to_s ⇒ Object
310 311 312 313 314 315 316 317 318 319 |
# File 'lib/unclekryon/iso.rb', line 310 def to_s s = 'Updated On:'.dup s << "\n- CAN Provs/Terrs: #{@updated_can_provs_terrs_on}" s << "\n- Countries: #{@updated_countries_on}" s << "\n- Languages: #{@updated_languages_on}" s << "\n- Regions: #{@updated_regions_on}" s << "\n- Subregions: #{@updated_subregions_on}" s << "\n- USA States: #{@updated_usa_states_on}" return s end |
#update_all ⇒ Object
294 295 296 297 298 299 300 301 |
# File 'lib/unclekryon/iso.rb', line 294 def update_all @updated_can_provs_terrs_on = BaseData.max_updated_on_s(self.class.can_provs_terrs.values) @updated_countries_on = BaseData.max_updated_on_s(self.class.countries.values) @updated_languages_on = BaseData.max_updated_on_s(self.class.languages.values) @updated_regions_on = BaseData.max_updated_on_s(self.class.regions.values) @updated_subregions_on = BaseData.max_updated_on_s(self.class.subregions.values) @updated_usa_states_on = BaseData.max_updated_on_s(self.class.usa_states.values) end |