factbook-fields 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1cf701b0c031d69ad0ebd0c7828368301135a1346cb5fe2552b4f88682c1c8c5
4
+ data.tar.gz: a7e0085fb8a08fb2b2de12dd2b86455fcc30b2dabf0021a4615ff347b3391eea
5
+ SHA512:
6
+ metadata.gz: 82769d5b529d51aebc6c61894ec1ada6ac408dabc5af37d9ea091a4b952349ee63a848f2dd252c28ab34f44a549c303da854efc1092c3bb1e20e776870b8c2ac
7
+ data.tar.gz: 7aece81108b6f4f36eecc4cba8c953063829e172a80e5a1303d61b5585f7ec7bf4d53a92c3d459197428c1c16f25ee2f7fb1bd7e4a4a79ad17b5a16053138b1f
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ### 0.1.0 / 2021-03-05
2
+
3
+ * Everything is new. First release.
data/Manifest.txt ADDED
@@ -0,0 +1,20 @@
1
+ CHANGELOG.md
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ data/categories.csv
6
+ data/comparisons.csv
7
+ lib/factbook-fields.rb
8
+ lib/factbook-fields/builder.rb
9
+ lib/factbook-fields/category.rb
10
+ lib/factbook-fields/comparisons.rb
11
+ lib/factbook-fields/field.rb
12
+ lib/factbook-fields/normalize.rb
13
+ lib/factbook-fields/profile.rb
14
+ lib/factbook-fields/version.rb
15
+ lib/factbook/fields.rb
16
+ test/helper.rb
17
+ test/test_builder.rb
18
+ test/test_comparisons.rb
19
+ test/test_fields.rb
20
+ test/test_normalize.rb
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # factbook-fields - world factbook country profile meta data - categories, fields, subfields, and more
2
+
3
+
4
+ * home :: [github.com/factbook/factbook](https://github.com/factbook/factbook)
5
+ * bugs :: [github.com/factbook/factbook/issues](https://github.com/factbook/factbook/issues)
6
+ * gem :: [rubygems.org/gems/factbook-fields](https://rubygems.org/gems/factbook-fields)
7
+ * rdoc :: [rubydoc.info/gems/factbook-fields](http://rubydoc.info/gems/factbook-fields)
8
+ * forum :: [groups.google.com/group/openmundi](https://groups.google.com/group/openmundi)
9
+
10
+
11
+ ## What's the World Factbook?
12
+
13
+ See [factbook/factbook.json »](https://github.com/factbook/factbook.json)
14
+
15
+
16
+
17
+ ## Usage
18
+
19
+ to be done
20
+
21
+
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require 'hoe'
2
+ require './lib/factbook-fields/version.rb'
3
+
4
+
5
+ Hoe.spec 'factbook-fields' do
6
+
7
+ self.version = Factbook::Module::Fields::VERSION
8
+
9
+ self.summary = 'factbook-fields - world factbook country profile meta data - categories, fields, subfields, and more'
10
+ self.description = summary
11
+
12
+ self.urls = { home: 'https://github.com/factbook/factbook' }
13
+
14
+ self.author = 'Gerald Bauer'
15
+ self.email = 'openmundi@googlegroups.com'
16
+
17
+ # switch extension to .markdown for gihub formatting
18
+ self.readme_file = 'README.md'
19
+ self.history_file = 'CHANGELOG.md'
20
+
21
+ self.extra_deps = [
22
+ ['factbook-codes' ],
23
+ ]
24
+
25
+ self.licenses = ['Public Domain']
26
+
27
+ self.spec_extras = {
28
+ required_ruby_version: '>= 2.2.2'
29
+ }
30
+
31
+ end
@@ -0,0 +1,164 @@
1
+ Num,Category,Name,Notes
2
+ ,Introduction,Background,
3
+ ,Geography,Location,
4
+ ,Geography,Geographic coordinates,
5
+ ,Geography,Map references,
6
+ ,Geography,Area,
7
+ ,Geography,Area - comparative,
8
+ ,Geography,Land boundaries,
9
+ ,Geography,Coastline,
10
+ ,Geography,Maritime claims,
11
+ ,Geography,Climate,
12
+ ,Geography,Terrain,
13
+ ,Geography,Elevation extremes,
14
+ ,Geography,Natural resources,
15
+ ,Geography,Land use,
16
+ ,Geography,Irrigated land,
17
+ ,Geography,Total renewable water resources,
18
+ ,Geography,Freshwater withdrawal (domestic/industrial/agricultural),
19
+ ,Geography,Natural hazards,
20
+ ,Geography,Environment - current issues,
21
+ ,Geography,Environment - international agreements,
22
+ ,Geography,Geography - note,
23
+ ,People and Society,Nationality,
24
+ ,People and Society,Ethnic groups,
25
+ ,People and Society,Languages,
26
+ ,People and Society,Religions,
27
+ ,People and Society,Population,
28
+ ,People and Society,Age structure,
29
+ ,People and Society,Dependency ratios,
30
+ ,People and Society,Median age,
31
+ ,People and Society,Population growth rate,
32
+ ,People and Society,Birth rate,
33
+ ,People and Society,Death rate,
34
+ ,People and Society,Net migration rate,
35
+ ,People and Society,Urbanization,
36
+ ,People and Society,Major urban areas - population,
37
+ ,People and Society,Sex ratio,
38
+ ,People and Society,Infant mortality rate,
39
+ ,People and Society,Life expectancy at birth,
40
+ ,People and Society,Total fertility rate,
41
+ ,People and Society,Contraceptive prevalence rate,
42
+ ,People and Society,Health expenditures,
43
+ ,People and Society,Physicians density,
44
+ ,People and Society,Hospital bed density,
45
+ ,People and Society,Drinking water source,
46
+ ,People and Society,Sanitation facility access,
47
+ ,People and Society,HIV/AIDS - adult prevalence rate,
48
+ ,People and Society,HIV/AIDS - people living with HIV/AIDS,
49
+ ,People and Society,HIV/AIDS - deaths,
50
+ ,People and Society,Obesity - adult prevalence rate,
51
+ ,People and Society,Education expenditures,
52
+ ,People and Society,School life expectancy (primary to tertiary education),
53
+ ,People and Society,"Unemployment, youth ages 15-24",
54
+ ,Government,Country name,
55
+ ,Government,Government type,
56
+ ,Government,Capital,
57
+ ,Government,Administrative divisions,
58
+ ,Government,Independence,
59
+ ,Government,National holiday,
60
+ ,Government,Constitution,
61
+ ,Government,Legal system,
62
+ ,Government,International law organization participation,
63
+ ,Government,Suffrage,
64
+ ,Government,Executive branch,
65
+ ,Government,Legislative branch,
66
+ ,Government,Judicial branch,
67
+ ,Government,Political parties and leaders,
68
+ ,Government,Political pressure groups and leaders,
69
+ ,Government,International organization participation,
70
+ ,Government,Diplomatic representation in the US,
71
+ ,Government,Diplomatic representation from the US,
72
+ ,Government,Flag description,
73
+ ,Government,National symbol(s),
74
+ ,Government,National anthem,
75
+ ,Economy,Economy - overview,
76
+ ,Economy,GDP (purchasing power parity),
77
+ ,Economy,GDP (official exchange rate),
78
+ ,Economy,GDP - real growth rate,
79
+ ,Economy,GDP - per capita (PPP),
80
+ ,Economy,Gross national saving,
81
+ ,Economy,"GDP - composition, by end use",
82
+ ,Economy,"GDP - composition, by sector of origin",
83
+ ,Economy,Agriculture - products,
84
+ ,Economy,Industries,
85
+ ,Economy,Industrial production growth rate,
86
+ ,Economy,Labor force,
87
+ ,Economy,Labor force - by occupation,
88
+ ,Economy,Unemployment rate,
89
+ ,Economy,Population below poverty line,
90
+ ,Economy,Household income or consumption by percentage share,
91
+ ,Economy,Distribution of family income - Gini index,
92
+ ,Economy,Budget,
93
+ ,Economy,Taxes and other revenues,
94
+ ,Economy,Budget surplus (+) or deficit (-),
95
+ ,Economy,Public debt,
96
+ ,Economy,Fiscal year,
97
+ ,Economy,Inflation rate (consumer prices),
98
+ ,Economy,Commercial bank prime lending rate,
99
+ ,Economy,Stock of narrow money,
100
+ ,Economy,Stock of broad money,
101
+ ,Economy,Stock of domestic credit,
102
+ ,Economy,Market value of publicly traded shares,
103
+ ,Economy,Current account balance,
104
+ ,Economy,Exports,
105
+ ,Economy,Exports - commodities,
106
+ ,Economy,Exports - partners,
107
+ ,Economy,Imports,
108
+ ,Economy,Imports - commodities,
109
+ ,Economy,Imports - partners,
110
+ ,Economy,Reserves of foreign exchange and gold,
111
+ ,Economy,Debt - external,
112
+ ,Economy,Stock of direct foreign investment - at home,
113
+ ,Economy,Stock of direct foreign investment - abroad,
114
+ ,Economy,Exchange rates,
115
+ ,Energy,Electricity - production,
116
+ ,Energy,Electricity - consumption,
117
+ ,Energy,Electricity - exports,
118
+ ,Energy,Electricity - imports,
119
+ ,Energy,Electricity - installed generating capacity,
120
+ ,Energy,Electricity - from fossil fuels,
121
+ ,Energy,Electricity - from nuclear fuels,
122
+ ,Energy,Electricity - from hydroelectric plants,
123
+ ,Energy,Electricity - from other renewable sources,
124
+ ,Energy,Crude oil - production,
125
+ ,Energy,Crude oil - exports,
126
+ ,Energy,Crude oil - imports,
127
+ ,Energy,Crude oil - proved reserves,
128
+ ,Energy,Refined petroleum products - production,
129
+ ,Energy,Refined petroleum products - consumption,
130
+ ,Energy,Refined petroleum products - exports,
131
+ ,Energy,Refined petroleum products - imports,
132
+ ,Energy,Natural gas - production,
133
+ ,Energy,Natural gas - consumption,
134
+ ,Energy,Natural gas - exports,
135
+ ,Energy,Natural gas - imports,
136
+ ,Energy,Natural gas - proved reserves,
137
+ ,Energy,Carbon dioxide emissions from consumption of energy,
138
+ ,Communications,Telephones - fixed lines,
139
+ ,Communications,Telephones - mobile cellular,
140
+ ,Communications,Telephone system,
141
+ ,Communications,Broadcast media,
142
+ ,Communications,Radio broadcast stations,
143
+ ,Communications,Television broadcast stations,
144
+ ,Communications,Internet country code,
145
+ ,Communications,Internet users,
146
+ ,Transportation,Airports,
147
+ ,Transportation,Airports - with paved runways,
148
+ ,Transportation,Airports - with unpaved runways,
149
+ ,Transportation,Heliports,
150
+ ,Transportation,Pipelines,
151
+ ,Transportation,Railways,
152
+ ,Transportation,Roadways,
153
+ ,Transportation,Waterways,
154
+ ,Transportation,Merchant marine,
155
+ ,Transportation,Ports and terminals,
156
+ ,Military,Military branches,
157
+ ,Military,Military service age and obligation,
158
+ ,Military,Manpower available for military service,
159
+ ,Military,Manpower fit for military service,
160
+ ,Military,Manpower reaching militarily significant age annually,
161
+ ,Military,Military expenditures,
162
+ ,Transnational Issues,Disputes - international,
163
+ ,Transnational Issues,Refugees and internally displaced persons,
164
+ ,Transnational Issues,Illicit drugs,
@@ -0,0 +1,75 @@
1
+ Num,Category,Name
2
+ 2147,Geography,Area
3
+ 2119,People and Society,Population
4
+ 2002,People and Society,Population growth rate
5
+ 2054,People and Society,Birth rate
6
+ 2066,People and Society,Death rate
7
+ 2112,People and Society,Net migration rate
8
+ 2223,People and Society,Maternal mortality rate
9
+ 2091,People and Society,Infant mortality rate
10
+ 2102,People and Society,Life expectancy at birth
11
+ 2127,People and Society,Total fertility rate
12
+ 2225,People and Society,Health expenditures
13
+ 2155,People and Society,HIV/AIDS - adult prevalence rate
14
+ 2156,People and Society,HIV/AIDS - people living with HIV/AIDS
15
+ 2157,People and Society,HIV/AIDS - deaths
16
+ 2228,People and Society,Obesity - adult prevalence rate
17
+ 2224,People and Society,Children under the age of 5 years underweight
18
+ 2206,People and Society,Education expenditures
19
+ 2229,People and Society,"Unemployment, youth ages 15-24"
20
+ 2001,Economy,GDP (purchasing power parity)
21
+ 2003,Economy,GDP - real growth rate
22
+ 2004,Economy,GDP - per capita (PPP)
23
+ 2260,Economy,Gross national saving
24
+ 2089,Economy,Industrial production growth rate
25
+ 2095,Economy,Labor force
26
+ 2129,Economy,Unemployment rate
27
+ 2172,Economy,Distribution of family income - Gini index
28
+ 2221,Economy,Taxes and other revenues
29
+ 2222,Economy,Budget surplus (+) or deficit (-)
30
+ 2186,Economy,Public debt
31
+ 2092,Economy,Inflation rate (consumer prices)
32
+ 2207,Economy,Central bank discount rate
33
+ 2208,Economy,Commercial bank prime lending rate
34
+ 2214,Economy,Stock of narrow money
35
+ 2215,Economy,Stock of broad money
36
+ 2211,Economy,Stock of domestic credit
37
+ 2200,Economy,Market value of publicly traded shares
38
+ 2187,Economy,Current account balance
39
+ 2078,Economy,Exports
40
+ 2087,Economy,Imports
41
+ 2188,Economy,Reserves of foreign exchange and gold
42
+ 2079,Economy,Debt - external
43
+ 2198,Economy,Stock of direct foreign investment - at home
44
+ 2199,Economy,Stock of direct foreign investment - abroad
45
+ 2232,Energy,Electricity - production
46
+ 2233,Energy,Electricity - consumption
47
+ 2234,Energy,Electricity - exports
48
+ 2235,Energy,Electricity - imports
49
+ 2236,Energy,Electricity - installed generating capacity
50
+ 2237,Energy,Electricity - from fossil fuels
51
+ 2239,Energy,Electricity - from nuclear fuels
52
+ 2238,Energy,Electricity - from hydroelectric plants
53
+ 2240,Energy,Electricity - from other renewable sources
54
+ 2241,Energy,Crude oil - production
55
+ 2242,Energy,Crude oil - exports
56
+ 2243,Energy,Crude oil - imports
57
+ 2244,Energy,Crude oil - proved reserves
58
+ 2245,Energy,Refined petroleum products - production
59
+ 2246,Energy,Refined petroleum products - consumption
60
+ 2247,Energy,Refined petroleum products - exports
61
+ 2248,Energy,Refined petroleum products - imports
62
+ 2249,Energy,Natural gas - production
63
+ 2250,Energy,Natural gas - consumption
64
+ 2251,Energy,Natural gas - exports
65
+ 2252,Energy,Natural gas - imports
66
+ 2253,Energy,Natural gas - proved reserves
67
+ 2150,Communications,Telephones - fixed lines
68
+ 2151,Communications,Telephones - mobile cellular
69
+ 2153,Communications,Internet users
70
+ 2053,Transportation,Airports
71
+ 2121,Transportation,Railways
72
+ 2085,Transportation,Roadways
73
+ 2093,Transportation,Waterways
74
+ 2108,Transportation,Merchant marine
75
+ 2034,Military,Military expenditures
@@ -0,0 +1,30 @@
1
+
2
+
3
+ require 'factbook/codes'
4
+
5
+
6
+ # our own code
7
+ require 'factbook-fields/version' # let it always go first
8
+
9
+ require 'factbook-fields/category'
10
+ require 'factbook-fields/field'
11
+ require 'factbook-fields/profile'
12
+
13
+ require 'factbook-fields/normalize'
14
+ require 'factbook-fields/builder'
15
+
16
+ require 'factbook-fields/comparisons'
17
+
18
+ ## note: make codes, comparisons available
19
+ module Factbook
20
+ ## note: load on demand only builtin codes, comparisons, etc.
21
+ ## for now
22
+ def self.comparisons
23
+ @@comparisons ||= Comparisons.read_csv( "#{Factbook::Module::Fields.root}/data/comparisons.csv" )
24
+ end
25
+ end # module Factbook
26
+
27
+
28
+
29
+
30
+ puts Factbook::Module::Fields.banner
@@ -0,0 +1,67 @@
1
+
2
+ module Factbook
3
+
4
+
5
+ ######
6
+ # builder -- lets us rebuild a profile from "dumped" hash
7
+
8
+ class ProfileBuilder ## change to DataBuilder or such - why? why not?
9
+ include LogUtils::Logging
10
+ include NormalizeHelper ## e.g. normalize_category
11
+
12
+
13
+ attr_reader :profile,
14
+ :errors ## not used yet -- encoding erros etc.
15
+
16
+
17
+
18
+
19
+
20
+ def initialize( text_or_data )
21
+
22
+ data = if text_or_data.is_a?( String )
23
+ text = text_or_data
24
+ JSON.parse( text )
25
+ else ## assume it's already a hash
26
+ text_or_data
27
+ end
28
+
29
+
30
+ @profile = Profile.new
31
+ @errors = [] ## fix/todo: sorry - for now no errors possible/tracked
32
+
33
+ data.each do |k1,v1|
34
+ category_title = k1
35
+ category_data = v1
36
+
37
+ category = Category.new( category_title )
38
+
39
+ ## get fields
40
+ category_data.each do |k2,v2|
41
+ field_title = k2
42
+ field_data = v2
43
+
44
+ field = Field.new( field_title )
45
+
46
+ #####
47
+ ## note: run data hash through normalize_title (again)
48
+ if field_data.is_a?( Hash )
49
+ new_field_data = {}
50
+ field_data.each do |k3,v3|
51
+ new_field_data[ normalize_title(k3) ] = v3
52
+ end
53
+ field_data = new_field_data
54
+ end
55
+
56
+ field.data = field_data
57
+
58
+ category << field
59
+ end
60
+ @profile << category
61
+ end
62
+ end
63
+
64
+ end # class ProfileBuilder
65
+
66
+
67
+ end # module Factbook
@@ -0,0 +1,41 @@
1
+
2
+ module Factbook
3
+
4
+
5
+ class Category
6
+ include LogUtils::Logging
7
+
8
+ attr_reader :title ## use name instead of title - why? why not?
9
+
10
+ def initialize( title )
11
+ @title = title
12
+ @fields = {}
13
+ end
14
+
15
+ def add( field )
16
+ @fields[ field.title ] = field
17
+ end
18
+ alias_method :<<, :add
19
+
20
+
21
+ def [](key) ### convenience shortcut
22
+ @fields[ key ]
23
+ end
24
+
25
+ def size() @fields.size; end
26
+
27
+
28
+
29
+ def data ## convert to hash
30
+ ## todo/fix: how to know when to rebuild?
31
+ ## for now @data MUST be reset to nil manually
32
+ data = {}
33
+ @fields.each do |_,field|
34
+ data[ field.title ] = field.data
35
+ end
36
+ data
37
+ end
38
+
39
+ end # class Category
40
+
41
+ end # module Factbook
@@ -0,0 +1,49 @@
1
+
2
+ module Factbook
3
+
4
+ class Comparisons
5
+
6
+ Comparison = Struct.new( :num, ### todo: use no or id or something - why? why not?
7
+ :category, ## e.g. Geography, People, Economy, etc.
8
+ :name,
9
+ )
10
+
11
+ def self.read_csv( path )
12
+
13
+ rows = CsvHash.read( path )
14
+
15
+ pp rows
16
+
17
+ recs = []
18
+ rows.each do |row|
19
+ pp row
20
+ rec = Comparison.new
21
+ rec.num = row['Num'].strip.to_i ## remove leading n trailing whitespaces
22
+ rec.category = row['Category'].strip
23
+ rec.name = row['Name'].strip
24
+
25
+ pp rec
26
+ recs << rec
27
+ end
28
+
29
+ new( recs )
30
+ end
31
+
32
+ def initialize( comps )
33
+ @comps = comps
34
+ end
35
+
36
+ def size() @comps.size; end
37
+
38
+ def each
39
+ @comps.each {|comp| yield( comp ) }
40
+ end
41
+
42
+ def to_a
43
+ @comps.collect {|comp| comp.num } ## return array of nums -- return something else - why? why not?
44
+ end
45
+
46
+ end # class Comparison
47
+
48
+ end # module Factbook
49
+
@@ -0,0 +1,23 @@
1
+
2
+ module Factbook
3
+
4
+
5
+ class Field
6
+ include LogUtils::Logging
7
+
8
+ attr_reader :title ## use name instead of title - why? why not?
9
+
10
+ attr_accessor :data ## hash holding data e.g. { 'text' => '...' etc. }
11
+
12
+ def initialize( title )
13
+ @title = title
14
+ @data = {}
15
+ end
16
+
17
+ def [](key) ### convenience shortcut
18
+ @data[ key ]
19
+ end
20
+
21
+ end # class Field
22
+
23
+ end # module Factbook
@@ -0,0 +1,42 @@
1
+
2
+ module Factbook
3
+ module NormalizeHelper
4
+
5
+
6
+ def normalize_title( text )
7
+
8
+ ## note: fix typos/errors with double colons e.g. note:: (instead of note:)
9
+
10
+ text = text.strip
11
+ text = text.sub( /:+\z/, '' ) # remove trailing : if present -- note: allow (fix) note:: too, thus, use :+
12
+ text = text.strip
13
+
14
+ #######################################
15
+ ### special cases
16
+
17
+ ## typos e.g ntoe => use note
18
+ text = 'note' if text == 'ntoe'
19
+ text = 'investment in fixed capital' if text == 'investment if fixed capital'
20
+
21
+ ## downcase
22
+ text = 'lowest point' if text == 'Lowest point'
23
+ text = 'chief of state' if text == 'Chief of state'
24
+
25
+ ## spelling variant (use more popular one)
26
+ text = 'signed, but not ratified' if text == 'signed but not ratified'
27
+ text = 'vectorborne diseases' if text == 'vectorborne disease'
28
+ text = 'water contact disease' if text == 'water contact diseases'
29
+ text = 'food or waterborne diseases' if text == 'food or waterborne disease'
30
+ text = 'geographic coordinates' if text == 'geographical coordinates'
31
+ text = 'note' if text == 'notes'
32
+ text = 'refugees (country of origin)' if text == 'refugees (countries of origin)'
33
+
34
+ ## border countries (8): -- remove (x) counter
35
+ text = 'border countries' if text.start_with?( 'border countries')
36
+
37
+ text
38
+ end
39
+
40
+
41
+ end # module NormalizeHelper
42
+ end # module Factbook
@@ -0,0 +1,57 @@
1
+
2
+ module Factbook
3
+
4
+
5
+ class Profile
6
+ include LogUtils::Logging
7
+
8
+ ## attr_reader :categories ## "structured" access e.g. categories/fields/etc.
9
+ ## use each for access by default for categories - why? why not?
10
+
11
+
12
+ def self.read( path ) ## convenience helper
13
+ text = File.open( path, 'r:utf-8' ) { |f| f.read }
14
+ b = ProfileBuilder.new( text )
15
+ b.profile
16
+ end
17
+
18
+
19
+ def initialize
20
+ @categories = {}
21
+ end
22
+
23
+ def add( category )
24
+ @categories[ category.title ] = category
25
+ end
26
+ alias_method :<<, :add
27
+
28
+ def [](key) ### convenience shortcut
29
+ if key.is_a?( Integer ) ## allow access by 0,1,2, etc.
30
+ @categories.values[ key ]
31
+ else
32
+ @categories[key]
33
+ end
34
+ end
35
+
36
+ def size() @categories.size; end
37
+
38
+
39
+
40
+ def to_h
41
+ data = {}
42
+ @categories.each do |_,category|
43
+ data[ category.title ] = category.data
44
+ end
45
+ data
46
+ end
47
+
48
+ def to_json( minify: false ) ## convenience helper for data.to_json; note: pretty print by default!
49
+ if minify
50
+ to_h.to_json
51
+ else ## note: pretty print by default!
52
+ JSON.pretty_generate( to_h )
53
+ end
54
+ end
55
+
56
+ end # class Profile
57
+ end # module Factbook
@@ -0,0 +1,24 @@
1
+
2
+ module Factbook
3
+ module Module
4
+ module Fields
5
+ MAJOR = 0
6
+ MINOR = 1
7
+ PATCH = 0
8
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
9
+
10
+ def self.version
11
+ VERSION
12
+ end
13
+
14
+ def self.banner
15
+ "factbook-fields/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
16
+ end
17
+
18
+ def self.root
19
+ File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
20
+ end
21
+
22
+ end # module Fields
23
+ end # module Module
24
+ end # module Factbook
@@ -0,0 +1,6 @@
1
+ # note: allow require 'factbook/fields' too
2
+ # (in addition to require 'factbook-fields')
3
+
4
+ require_relative '../factbook-fields'
5
+
6
+
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift( "../factbook-codes/lib" )
2
+
3
+ ## minitest setup
4
+ require 'minitest/autorun'
5
+
6
+
7
+ ## our own code
8
+ require 'factbook/fields'
9
+
10
+
@@ -0,0 +1,30 @@
1
+ ###
2
+ # to run use
3
+ # ruby -I ./lib -I ./test test/test_builder.rb
4
+
5
+
6
+ require 'helper'
7
+
8
+
9
+ class TestBuilder < MiniTest::Test
10
+
11
+ def test_read
12
+ code = 'au'
13
+ path = "#{Factbook::Module::Fields.root}/../testdata/json/#{code}.json"
14
+ profile = Factbook::Profile.read( path )
15
+
16
+ assert_equal 11, profile.size
17
+ assert_equal 1, profile[0].size ## e.g. Introduction/Background
18
+ assert_equal 1, profile['Introduction'].size ## e.g. Introduction/Background
19
+
20
+ assert_equal 'Central Europe, north of Italy and Slovenia',
21
+ profile['Geography']['Location']['text']
22
+ assert_equal '83,871 sq km',
23
+ profile['Geography']['Area']['total']['text']
24
+
25
+
26
+ assert true ## assume everthing ok
27
+ end
28
+
29
+ end # class TestBuilder
30
+
@@ -0,0 +1,16 @@
1
+ ###
2
+ # to run use
3
+ # ruby -I ./lib -I ./test test/test_comparisons.rb
4
+
5
+
6
+ require 'helper'
7
+
8
+
9
+ class TestComparisons < MiniTest::Test
10
+
11
+ def test_comparisons
12
+ assert_equal 74, Factbook.comparisons.size
13
+ assert_equal 74, Factbook.comparisons.to_a.size
14
+ end
15
+
16
+ end # class TestComparisons
@@ -0,0 +1,59 @@
1
+ ###
2
+ # to run use
3
+ # ruby -I ./lib -I ./test test/test_fields.rb
4
+
5
+
6
+ require 'helper'
7
+
8
+
9
+ class TestFields < MiniTest::Test
10
+
11
+ def test_fields_new
12
+
13
+ field0 = Factbook::Field.new( 'Location' )
14
+ field0.data = { 'text' => 'Central Europe, north of Italy and Slovenia' }
15
+
16
+ field1 = Factbook::Field.new( 'Geographic coordinates' )
17
+ field1.data = { 'text' => '47 20 N, 13 20 E' }
18
+
19
+ category = Factbook::Category.new( 'Geography' )
20
+ category << field0
21
+ category << field1
22
+
23
+ profile = Factbook::Profile.new
24
+ profile << category
25
+
26
+
27
+ assert_equal 'Central Europe, north of Italy and Slovenia',
28
+ profile[ 'Geography' ][ 'Location' ][ 'text' ]
29
+
30
+ assert_equal '47 20 N, 13 20 E',
31
+ profile[ 'Geography' ][ 'Geographic coordinates' ][ 'text' ]
32
+
33
+ pp profile
34
+
35
+ puts
36
+ puts "json:"
37
+ puts profile.to_json
38
+ end
39
+
40
+
41
+ def test_fields_au
42
+ # note: use builtin test page (do NOT fetch via internet)
43
+ code = 'au'
44
+ path = "#{Factbook::Module::Fields.root}/../testdata/json/#{code}.json"
45
+ profile = Factbook::Profile.read( path )
46
+
47
+ assert_equal '-0.7% (of GDP) (2017 est.)',
48
+ profile['Economy']['Budget surplus (+) or deficit (-)']['text']
49
+ assert_equal '0.7%',
50
+ profile['Economy']['Labor force - by occupation']['agriculture']['text']
51
+
52
+ assert_equal 'Enns, Krems, Linz, Vienna (Danube)',
53
+ profile['Transportation']['Ports and terminals']['river port(s)']['text']
54
+ end
55
+
56
+
57
+
58
+ end # class TestFields
59
+
@@ -0,0 +1,21 @@
1
+ ###
2
+ # to run use
3
+ # ruby -I ./lib -I ./test test/test_normalize.rb
4
+
5
+
6
+ require 'helper'
7
+
8
+
9
+ class TestNormalizer < MiniTest::Test
10
+
11
+ include Factbook::NormalizeHelper
12
+
13
+ def test_normalize
14
+ assert_equal 'border countries', normalize_title( 'border countries:' )
15
+ assert_equal 'border countries', normalize_title( 'border countries: ' )
16
+ assert_equal 'border countries', normalize_title( 'border countries (8):' )
17
+ assert_equal 'border countries', normalize_title( 'border countries (10): ' )
18
+ end
19
+
20
+ end # class TestNormalizer
21
+
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: factbook-fields
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gerald Bauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: factbook-codes
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '7'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '4.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '7'
47
+ - !ruby/object:Gem::Dependency
48
+ name: hoe
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.22'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.22'
61
+ description: factbook-fields - world factbook country profile meta data - categories,
62
+ fields, subfields, and more
63
+ email: openmundi@googlegroups.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files:
67
+ - CHANGELOG.md
68
+ - Manifest.txt
69
+ - README.md
70
+ files:
71
+ - CHANGELOG.md
72
+ - Manifest.txt
73
+ - README.md
74
+ - Rakefile
75
+ - data/categories.csv
76
+ - data/comparisons.csv
77
+ - lib/factbook-fields.rb
78
+ - lib/factbook-fields/builder.rb
79
+ - lib/factbook-fields/category.rb
80
+ - lib/factbook-fields/comparisons.rb
81
+ - lib/factbook-fields/field.rb
82
+ - lib/factbook-fields/normalize.rb
83
+ - lib/factbook-fields/profile.rb
84
+ - lib/factbook-fields/version.rb
85
+ - lib/factbook/fields.rb
86
+ - test/helper.rb
87
+ - test/test_builder.rb
88
+ - test/test_comparisons.rb
89
+ - test/test_fields.rb
90
+ - test/test_normalize.rb
91
+ homepage: https://github.com/factbook/factbook
92
+ licenses:
93
+ - Public Domain
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options:
97
+ - "--main"
98
+ - README.md
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: 2.2.2
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubygems_version: 3.1.4
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: factbook-fields - world factbook country profile meta data - categories,
116
+ fields, subfields, and more
117
+ test_files: []