class UncleKryon::Countries
Constants
- DEFAULT_FILEPATH
Public Class Methods
load_file(filepath=DEFAULT_FILEPATH)
click to toggle source
# File lib/unclekryon/iso/country.rb, line 70 def self.load_file(filepath=DEFAULT_FILEPATH) return Countries.new.load_file(filepath) end
new()
click to toggle source
Calls superclass method
UncleKryon::BaseIsos::new
# File lib/unclekryon/iso/country.rb, line 66 def initialize super() end
parse_and_save_to_file(parse_filepath,save_filepath=DEFAULT_FILEPATH)
click to toggle source
@param parse_filepath [String] use web browser's developer tools to copy & paste table HTML
into local file
@param save_filepath [String] local file to save YAML to @see www.iso.org/obp/ui/#search/code/
# File lib/unclekryon/iso/country.rb, line 78 def self.parse_and_save_to_file(parse_filepath,save_filepath=DEFAULT_FILEPATH) doc = Nokogiri::HTML(URI(parse_filepath).open,nil,'utf-8') tds = doc.css('td') countries = Countries.new i = 0 tr = [] tds.each do |td| c = td.content c.gsub!(/[[:space:]]+/,' ') c.strip! tr.push(c) if (i += 1) >= 5 #puts tr.inspect() country = Country.new(tr) raise "Country already exists: #{country.inspect}" if countries.key?(country.code) countries.values.each_value do |v| puts "Duplicate country names: #{v.name}" if v.name == country.name end countries[country.code] = country tr.clear i = 0 end end countries.sort_keys! countries.save_to_file(save_filepath) end