/
countrylist.rb
40 lines (32 loc) · 971 Bytes
/
countrylist.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Copyright 2011 Marco Dinacci <marco.dinacci@gmail.com> / www.intransitione.com
#
# Hi, this program reads jobs listings from the careers.stackoverflow.com website and
# dump it on a file. It then read back the data and output JSON files ready to be
# used with the Google Visualization API.
#
# You are free to do what you want with it except pretend that you wrote it.
# If you redistribute it, keep the copyright line above.
module CountryList
def loadFromFile countries_file
f = File.new countries_file
countries = {}
f.each do |line|
country, code = line.split(';').collect(|word| word.upcase)
countries[country] = code[0...-2] #discard \r\n
end
f.close
return countries
end
class CountryList
def initialize countries_file
@countries_file = countries_file
@countries = {}
end
def contains country_name
if @countries.empty?
@countries = loadFromFile @countries_file
end
return @countries.keys.include? country_name
end
end
end