factbook-codes 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +53 -7
- data/data/codes.csv +0 -1
- data/lib/factbook-codes.rb +19 -1
- data/lib/factbook-codes/codes.rb +32 -12
- data/lib/factbook-codes/version.rb +1 -1
- data/test/test_codes.rb +19 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f315e31562bd310f9499a67bbb535c582b8bc8813e95c01ab2a7583fd5ef5c78
|
4
|
+
data.tar.gz: 9119488f7305b7f702125b5a4d1a95bfbb63feb8f9bf474a3d7be286ac2fd308
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bef206fa344cfdced6555ec4e099dd0a3dbd6d96c5b173f7ea2affa02877e149233e8d716209643c2e28fb931538dcee9c54861c9411d6cddba74fbbeb467678
|
7
|
+
data.tar.gz: b9934611ff2d0bd73863cf80484795d9f282c112c695a073f5f87856ec14a4d2875189c28f1529c9f8c13e48cc6e3dc7109301c77757b1486963755304f1de3d
|
data/README.md
CHANGED
@@ -26,22 +26,22 @@ end
|
|
26
26
|
resulting in:
|
27
27
|
|
28
28
|
```
|
29
|
-
#<
|
29
|
+
#<Factbook::Codes::Code
|
30
30
|
code ="af",
|
31
31
|
name ="Afghanistan",
|
32
32
|
category="Countries",
|
33
33
|
region ="South Asia">
|
34
|
-
#<
|
34
|
+
#<Factbook::Codes::Code
|
35
35
|
code ="al",
|
36
36
|
name ="Albania",
|
37
37
|
category="Countries",
|
38
38
|
region ="Europe">
|
39
|
-
#<
|
39
|
+
#<Factbook::Codes::Code
|
40
40
|
code ="ag",
|
41
41
|
name ="Algeria",
|
42
42
|
category="Countries",
|
43
43
|
region ="Africa">
|
44
|
-
#<
|
44
|
+
#<Factbook::Codes::Code
|
45
45
|
code ="an",
|
46
46
|
name ="Andorra",
|
47
47
|
category="Countries",
|
@@ -55,7 +55,7 @@ and/or by region e.g. Africa, Europe, South Asia, Central America and Caribbean,
|
|
55
55
|
|
56
56
|
```ruby
|
57
57
|
|
58
|
-
assert_equal
|
58
|
+
assert_equal 260, Factbook.codes.size
|
59
59
|
|
60
60
|
## categories
|
61
61
|
assert_equal 195, Factbook.codes.countries.size
|
@@ -63,7 +63,7 @@ assert_equal 52, Factbook.codes.dependencies.size
|
|
63
63
|
assert_equal 5, Factbook.codes.oceans.size
|
64
64
|
assert_equal 1, Factbook.codes.world.size
|
65
65
|
assert_equal 2, Factbook.codes.others.size
|
66
|
-
assert_equal
|
66
|
+
assert_equal 5, Factbook.codes.misc.size
|
67
67
|
|
68
68
|
## regions
|
69
69
|
assert_equal 55, Factbook.codes.europe.size
|
@@ -71,7 +71,7 @@ assert_equal 9, Factbook.codes.south_asia.size
|
|
71
71
|
assert_equal 6, Factbook.codes.central_asia.size
|
72
72
|
assert_equal 22, Factbook.codes.east_n_souteast_asia.size
|
73
73
|
assert_equal 19, Factbook.codes.middle_east.size
|
74
|
-
assert_equal
|
74
|
+
assert_equal 55, Factbook.codes.africa.size
|
75
75
|
assert_equal 7, Factbook.codes.north_america.size
|
76
76
|
assert_equal 33, Factbook.codes.central_america_n_caribbean.size
|
77
77
|
assert_equal 14, Factbook.codes.south_america.size
|
@@ -90,6 +90,52 @@ See [`data/codes.csv`](data/codes.csv) for the built-in listing of all codes wit
|
|
90
90
|
|
91
91
|
|
92
92
|
|
93
|
+
## Frequently Asked Questions (F.A.Q.s) & Answers
|
94
|
+
|
95
|
+
Q: The World Factbook front-page
|
96
|
+
says "for 266 world entities" - but
|
97
|
+
the `Factbook.codes.size` is only 260 (thus, 6 entities short)?
|
98
|
+
What's the story?
|
99
|
+
|
100
|
+
> The World Factbook provides basic intelligence on the history,
|
101
|
+
> people, government, economy, energy, geography, communications,
|
102
|
+
> transportation, military, terrorism, and transnational issues
|
103
|
+
> for 266 world entities.
|
104
|
+
>
|
105
|
+
> (Source: [`cia.gov/the-world-factbook`](https://www.cia.gov/the-world-factbook/))
|
106
|
+
|
107
|
+
|
108
|
+
A: Since March 2006
|
109
|
+
the United States Pacific Island Wildlife Refuges (`um`)
|
110
|
+
country profile consolidates
|
111
|
+
seven profiles into a single new one
|
112
|
+
(but keeps entities count as before):
|
113
|
+
|
114
|
+
- Baker Island (`fq`)
|
115
|
+
- Howland Island (`hq`)
|
116
|
+
- Jarvis Island (`dq`)
|
117
|
+
- Johnston Atoll (`jq`)
|
118
|
+
- Kingman Reef (`kq`)
|
119
|
+
- Midway Islands (`mq`)
|
120
|
+
- Palmyra Atoll (`lq`)
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
Q: What happened to the Western Sahara (`wi`) country profile?
|
125
|
+
|
126
|
+
In December 2020 the World Factbook dropped coverage of the Western Sahara (`wi`). Why?
|
127
|
+
In a deal with Morocco the United States recognizes the claim
|
128
|
+
of Marocco over the Western Sahara and in return
|
129
|
+
Morocco starts official diplomatic relations with Israel.
|
130
|
+
|
131
|
+
```
|
132
|
+
Code, Name, Category, Region
|
133
|
+
wi, Western Sahara, Miscellaneous, Africa
|
134
|
+
```
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
93
139
|
## Install
|
94
140
|
|
95
141
|
Use
|
data/data/codes.csv
CHANGED
@@ -253,7 +253,6 @@ gz,Gaza Strip,Miscellaneous,Middle East
|
|
253
253
|
pf,Paracel Islands,Miscellaneous,East & Southeast Asia
|
254
254
|
pg,Spratly Islands,Miscellaneous,East & Southeast Asia
|
255
255
|
we,West Bank,Miscellaneous,Middle East
|
256
|
-
wi,Western Sahara,Miscellaneous,Africa
|
257
256
|
xq,Arctic Ocean,Oceans,Oceans
|
258
257
|
zh,Atlantic Ocean,Oceans,Oceans
|
259
258
|
xo,Indian Ocean,Oceans,Oceans
|
data/lib/factbook-codes.rb
CHANGED
@@ -9,6 +9,12 @@ require 'csvreader'
|
|
9
9
|
# our own code
|
10
10
|
require 'factbook-codes/version' # let it always go first
|
11
11
|
|
12
|
+
|
13
|
+
module SportDb
|
14
|
+
Logging = LogUtils::Logging ## logging machinery shortcut; use LogUtils for now
|
15
|
+
end
|
16
|
+
|
17
|
+
|
12
18
|
require 'factbook-codes/codes'
|
13
19
|
|
14
20
|
|
@@ -17,9 +23,21 @@ module Factbook
|
|
17
23
|
## note: load on demand only builtin codes, comparisons, etc.
|
18
24
|
## for now
|
19
25
|
def self.codes
|
20
|
-
@@codes
|
26
|
+
@@codes ||= Codes.read_csv( "#{Factbook::Module::Codes.root}/data/codes.csv" );
|
27
|
+
end
|
28
|
+
|
29
|
+
## let's put test configuration in its own namespace / module
|
30
|
+
class Test ## todo/check: works with module too? use a module - why? why not?
|
31
|
+
####
|
32
|
+
# todo/fix: find a better way to configure shared test datasets - why? why not?
|
33
|
+
# note: use one-up (..) directory for now as default - why? why not?
|
34
|
+
def self.data_dir() @data_dir ||= '../testdata'; end
|
35
|
+
def self.data_dir=( path ) @data_dir = path; end
|
21
36
|
end
|
22
37
|
end # module Factbook
|
23
38
|
|
24
39
|
|
40
|
+
|
41
|
+
|
42
|
+
|
25
43
|
puts Factbook::Module::Codes.banner
|
data/lib/factbook-codes/codes.rb
CHANGED
@@ -6,13 +6,33 @@
|
|
6
6
|
|
7
7
|
module Factbook
|
8
8
|
|
9
|
+
## check: move region_to_slug into a utility module / helper
|
10
|
+
## for (re)use - how, why? why not??
|
11
|
+
def self.region_to_slug( text )
|
12
|
+
## change and => n
|
13
|
+
## change & => n
|
14
|
+
## change all spaces to => -
|
15
|
+
## e.g. East & Southeast Asia => east-n-southeast-asia
|
16
|
+
## Central America and Caribbean => central-america-n-caribbean
|
17
|
+
text.downcase.gsub('and', 'n').gsub( '&', 'n' ).gsub( ' ', '-' )
|
18
|
+
end
|
19
|
+
|
9
20
|
class Codes
|
21
|
+
class Code ## nested class
|
22
|
+
attr_accessor :code, ## todo: add notes (country affiliation) - why? why not??
|
23
|
+
:name,
|
24
|
+
:category, ## e.g. Countries, Other, Oceans, World, Dependencies, etc.
|
25
|
+
:region ## e.g. Europe, Oceans, etc.
|
26
|
+
|
27
|
+
## todo/check: add aliases e.g. - why? why not?
|
28
|
+
## country_code => code
|
29
|
+
## country_name => name
|
30
|
+
## region_name => region
|
31
|
+
|
32
|
+
def region_slug() Factbook.region_to_slug( @region ); end
|
33
|
+
end # (nested) class Code
|
34
|
+
|
10
35
|
|
11
|
-
Code = Struct.new( :code, ## todo: add notes (country affiliation) - why? why not??
|
12
|
-
:name,
|
13
|
-
:category, ## e.g. Countries, Other, Oceans, World, Dependencies, etc.
|
14
|
-
:region, ## e.g. Europe, Oceans, etc.
|
15
|
-
)
|
16
36
|
|
17
37
|
def self.read_csv( path )
|
18
38
|
###
|
@@ -27,20 +47,18 @@ class Codes
|
|
27
47
|
|
28
48
|
rows = CsvHash.read( path )
|
29
49
|
|
30
|
-
pp rows
|
50
|
+
## pp rows
|
31
51
|
|
32
52
|
recs = []
|
33
53
|
rows.each do |row|
|
34
|
-
pp row
|
54
|
+
## pp row
|
35
55
|
rec = Code.new
|
36
56
|
rec.code = row['Code'].strip ## remove leading n trailing whitespaces
|
37
57
|
rec.name = row['Name'].strip
|
58
|
+
rec.category = row['Category'].strip
|
59
|
+
rec.region = row['Region'].strip
|
38
60
|
|
39
|
-
##
|
40
|
-
rec.category = row['Category'].strip if row['Category'] && row['Category'].size > 0
|
41
|
-
rec.region = row['Region'].strip if row['Region'] && row['Region'].size > 0
|
42
|
-
|
43
|
-
pp rec
|
61
|
+
## pp rec
|
44
62
|
recs << rec
|
45
63
|
end
|
46
64
|
|
@@ -61,6 +79,8 @@ class Codes
|
|
61
79
|
end
|
62
80
|
|
63
81
|
|
82
|
+
def [](key) @codes[ key ]; end
|
83
|
+
|
64
84
|
def to_a
|
65
85
|
@codes.collect {|code| code.code } ## return array of codes
|
66
86
|
end
|
data/test/test_codes.rb
CHANGED
@@ -10,8 +10,8 @@ class TestCodes < MiniTest::Test
|
|
10
10
|
|
11
11
|
|
12
12
|
def test_codes
|
13
|
-
assert_equal
|
14
|
-
assert_equal
|
13
|
+
assert_equal 260, Factbook.codes.size
|
14
|
+
assert_equal 260, Factbook.codes.to_a.size
|
15
15
|
|
16
16
|
|
17
17
|
assert_equal 195, Factbook.codes.countries.size
|
@@ -19,7 +19,7 @@ class TestCodes < MiniTest::Test
|
|
19
19
|
assert_equal 5, Factbook.codes.oceans.size
|
20
20
|
assert_equal 1, Factbook.codes.world.size
|
21
21
|
assert_equal 2, Factbook.codes.others.size
|
22
|
-
assert_equal
|
22
|
+
assert_equal 5, Factbook.codes.misc.size
|
23
23
|
|
24
24
|
assert_equal 8, Factbook.codes.dependencies_us.size
|
25
25
|
|
@@ -29,7 +29,7 @@ class TestCodes < MiniTest::Test
|
|
29
29
|
assert_equal 6, Factbook.codes.central_asia.size
|
30
30
|
assert_equal 22, Factbook.codes.east_n_souteast_asia.size
|
31
31
|
assert_equal 19, Factbook.codes.middle_east.size
|
32
|
-
assert_equal
|
32
|
+
assert_equal 55, Factbook.codes.africa.size
|
33
33
|
assert_equal 7, Factbook.codes.north_america.size
|
34
34
|
assert_equal 33, Factbook.codes.central_america_n_caribbean.size
|
35
35
|
assert_equal 14, Factbook.codes.south_america.size
|
@@ -44,14 +44,14 @@ class TestCodes < MiniTest::Test
|
|
44
44
|
assert_equal Factbook.codes.category('World').size, Factbook.codes.region('World').size
|
45
45
|
|
46
46
|
|
47
|
-
assert_equal
|
47
|
+
assert_equal 260, Factbook.codes.countries.size +
|
48
48
|
Factbook.codes.others.size +
|
49
49
|
Factbook.codes.dependencies.size +
|
50
50
|
Factbook.codes.misc.size +
|
51
51
|
Factbook.codes.oceans.size +
|
52
52
|
Factbook.codes.world.size
|
53
53
|
|
54
|
-
assert_equal
|
54
|
+
assert_equal 260, Factbook.codes.europe.size +
|
55
55
|
Factbook.codes.south_asia.size +
|
56
56
|
Factbook.codes.central_asia.size +
|
57
57
|
Factbook.codes.east_n_souteast_asia.size +
|
@@ -64,9 +64,20 @@ class TestCodes < MiniTest::Test
|
|
64
64
|
Factbook.codes.antartica.size +
|
65
65
|
Factbook.codes.region('Oceans').size +
|
66
66
|
Factbook.codes.region('World').size
|
67
|
-
|
68
67
|
end
|
69
68
|
|
70
|
-
|
69
|
+
def test_region_slug
|
70
|
+
bx = Factbook.codes[24]
|
71
|
+
#=> bx,Brunei,Countries,East & Southeast Asia
|
72
|
+
|
73
|
+
assert_equal 'East & Southeast Asia', bx.region
|
74
|
+
assert_equal 'east-n-southeast-asia', bx.region_slug
|
71
75
|
|
76
|
+
ac = Factbook.codes[5]
|
77
|
+
#=> ac,Antigua and Barbuda,Countries,Central America and Caribbean
|
78
|
+
|
79
|
+
assert_equal 'Central America and Caribbean', ac.region
|
80
|
+
assert_equal 'central-america-n-caribbean', ac.region_slug
|
81
|
+
end
|
82
|
+
end # class TestCodes
|
72
83
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factbook-codes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logutils
|