factbook-readers 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +0 -16
- data/README.md +13 -14
- data/data/codes.csv +1 -1
- data/lib/factbook-readers.rb +11 -12
- data/lib/factbook-readers/builder.rb +28 -53
- data/lib/factbook-readers/builder_json.rb +9 -20
- data/lib/factbook-readers/codes.rb +3 -2
- data/lib/factbook-readers/comparisons.rb +2 -2
- data/lib/factbook-readers/page.rb +59 -85
- data/lib/factbook-readers/sanitizer.rb +13 -34
- data/lib/factbook-readers/version.rb +2 -2
- data/test/helper.rb +1 -5
- data/test/test_builder.rb +1 -6
- data/test/test_codes.rb +5 -9
- data/test/test_comparisons.rb +2 -5
- data/test/test_counter.rb +4 -6
- data/test/test_fields.rb +0 -2
- data/test/test_item_builder.rb +7 -9
- data/test/test_json.rb +1 -3
- data/test/test_json_builder.rb +1 -3
- data/test/test_normalize.rb +0 -2
- data/test/test_page.rb +2 -4
- data/test/test_sanitizer.rb +2 -5
- data/test/test_sanitizer_regex.rb +0 -2
- metadata +2 -18
- data/data/attributes.yml +0 -337
- data/lib/factbook-readers/attributes.rb +0 -74
- data/test/data/au.html +0 -579
- data/test/data/au.yml +0 -8
- data/test/data/be.html +0 -596
- data/test/data/be.yml +0 -8
- data/test/data/json/au.json +0 -892
- data/test/data/src/ag.html +0 -716
- data/test/data/src/au-2015-09-24.html +0 -2006
- data/test/data/src/au.html +0 -658
- data/test/data/src/be-2015-09-24.html +0 -2011
- data/test/data/src/be.html +0 -648
- data/test/test_attribs.rb +0 -87
- data/test/test_attribs_def.rb +0 -20
- data/test/test_convert.rb +0 -30
- data/test/test_importer.rb +0 -56
data/test/test_attribs.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_attribs.rb
|
6
|
-
|
7
|
-
require 'helper'
|
8
|
-
|
9
|
-
|
10
|
-
class TestAttribs < MiniTest::Test
|
11
|
-
|
12
|
-
def read_test_page( code )
|
13
|
-
html = File.read( "#{Factbook.root}/test/data/src/#{code}.html" )
|
14
|
-
page = Factbook::Page.new( code, html: html )
|
15
|
-
page
|
16
|
-
end
|
17
|
-
|
18
|
-
def read_test_page_from_json( code )
|
19
|
-
json = File.read( "#{Factbook.root}/test/data/json/#{code}.json" )
|
20
|
-
page = Factbook::Page.new( code, json: json )
|
21
|
-
page
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
def test_au_from_html
|
26
|
-
page = read_test_page( 'au' ) # note: use builtin test page (do NOT fetch via internet)
|
27
|
-
|
28
|
-
assert_page_au( page )
|
29
|
-
end
|
30
|
-
|
31
|
-
def xxx_test_au_from_json
|
32
|
-
|
33
|
-
## todo/fix: check some issue with newlines? when comparing background or something ???
|
34
|
-
page = read_test_page_from_json( 'au' )
|
35
|
-
|
36
|
-
assert_page_au( page )
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
def assert_page_au( page )
|
41
|
-
########
|
42
|
-
## Introduction
|
43
|
-
assert_equal page.background, "Once the center of power for the large Austro-Hungarian Empire, Austria was reduced to a small republic after its defeat in World War I. Following annexation by Nazi Germany in 1938 and subsequent occupation by the victorious Allies in 1945, Austria's status remained unclear for a decade. A State Treaty signed in 1955 ended the occupation, recognized Austria's independence, and forbade unification with Germany. A constitutional law that same year declared the country's \"perpetual neutrality\" as a condition for Soviet military withdrawal. The Soviet Union's collapse in 1991 and Austria's entry into the EU in 1995 have altered the meaning of this neutrality. A prosperous, democratic country, Austria entered the EU Economic and Monetary Union in 1999."
|
44
|
-
|
45
|
-
###########
|
46
|
-
## Geography
|
47
|
-
assert_equal page.area, "83,871 sq km"
|
48
|
-
assert_equal page.area_land, "82,445 sq km"
|
49
|
-
assert_equal page.area_water, "1,426 sq km"
|
50
|
-
assert_equal page.area_note, nil
|
51
|
-
assert_equal page.area_comparative, "about the size of South Carolina; slightly more than two-thirds the size of Pennsylvania"
|
52
|
-
assert_equal page.climate, "temperate; continental, cloudy; cold winters with frequent rain and some snow in lowlands and snow in mountains; moderate summers with occasional showers"
|
53
|
-
assert_equal page.terrain, "mostly mountains (Alps) in the west and south; mostly flat or gently sloping along the eastern and northern margins"
|
54
|
-
|
55
|
-
# was:
|
56
|
-
## assert_equal page.elevation_lowest, "Neusiedler See 115 m"
|
57
|
-
## assert_equal page.elevation_highest, "Grossglockner 3,798 m"
|
58
|
-
## new ????
|
59
|
-
## assert_equal page.elevation_extremes, "lowest point: Neusiedler See 115 m ++ highest point: Grossglockner 3,798 m"
|
60
|
-
|
61
|
-
assert_equal page.resources, "oil, coal, lignite, timber, iron ore, copper, zinc, antimony, magnesite, tungsten, graphite, salt, hydropower"
|
62
|
-
|
63
|
-
###################
|
64
|
-
## People and Society
|
65
|
-
assert_equal page.languages, "German (official nationwide) 88.6%, Turkish 2.3%, Serbian 2.2%, Croatian (official in Burgenland) 1.6%, other (includes Slovene, official in South Carinthia, and Hungarian, official in Burgenland) 5.3% (2001 est.)"
|
66
|
-
assert_equal page.religions, "Catholic 73.8% (includes Roman Catholic 73.6%, other Catholic 0.2%), Protestant 4.9%, Muslim 4.2%, Orthodox 2.2%, other 0.8% (includes other Christian), none 12%, unspecified 2% (2001 est.)"
|
67
|
-
assert_equal page.population, "8,711,770 (July 2016 est.)"
|
68
|
-
assert_equal page.population_growth, "0.51% (2016 est.)"
|
69
|
-
assert_equal page.birth_rate, "9.5 births/1,000 population (2016 est.)"
|
70
|
-
assert_equal page.death_rate, "9.5 deaths/1,000 population (2016 est.)"
|
71
|
-
assert_equal page.migration_rate, "5.2 migrant(s)/1,000 population (2016 est.)"
|
72
|
-
assert_equal page.major_cities, "VIENNA (capital) 1.753 million (2015)"
|
73
|
-
|
74
|
-
|
75
|
-
####################
|
76
|
-
## Economy
|
77
|
-
## assert_equal page.economy_overview, "Austria, with its well-developed market economy, skilled labor force, and high standard of living, is closely tied to other EU economies, especially Germany's. Its economy features a large service sector, a relatively sound industrial sector, and a small, but highly developed agricultural sector. Economic growth was anemic at less than 0.5% in 2013 and 2014, and growth in 2015 is not expected to exceed 0.5%. Austria’s 5.6% unemployment rate, while low by European standards, is at an historic high for Austria. Without extensive vocational training programs and generous early retirement, the unemployment rate would be even higher. Public finances have not stabilized even after a 2012 austerity package of expenditure cuts and new revenues. On the contrary, in 2014, the government created a “bad bank” for the troubled nationalized “Hypo Alpe Adria” bank, pushing the budget deficit up by 0.9% of GDP to 2.4% and public debt to 84.5% of the GDP. Although Austria's fiscal position compares favorably with other euro-zone countries, it faces several external risks, such as Austrian banks' continued exposure to Central and Eastern Europe, repercussions from the Hypo Alpe Adria bank collapse, political and economic uncertainties caused by the European sovereign debt crisis, the current crisis in Russia/Ukraine, the recent appreciation of the Swiss Franc, and political developments in Hungary."
|
78
|
-
assert_equal page.gdp_ppp, "$405.1 billion (2015 est.) ++ $401.6 billion (2014 est.) ++ $400.2 billion (2013 est.)"
|
79
|
-
assert_equal page.gdp_ppp_note, "data are in 2015 US dollars"
|
80
|
-
assert_equal page.gdp, "$374.3 billion (2015 est.)"
|
81
|
-
assert_equal page.gdp_growth, "0.9% (2015 est.) ++ 0.4% (2014 est.) ++ 0.3% (2013 est.)"
|
82
|
-
assert_equal page.gdp_ppp_capita, "$47,000 (2015 est.) ++ $47,000 (2014 est.) ++ $47,200 (2013 est.)"
|
83
|
-
assert_equal page.gdp_ppp_capita_note, "data are in 2015 US dollars"
|
84
|
-
assert_equal page.saving, "25% of GDP (2015 est.) ++ 24.7% of GDP (2014 est.) ++ 25.2% of GDP (2013 est.)"
|
85
|
-
end
|
86
|
-
|
87
|
-
end # class TestAttribs
|
data/test/test_attribs_def.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_attribs_def.rb
|
6
|
-
|
7
|
-
require 'helper'
|
8
|
-
|
9
|
-
|
10
|
-
class TestAttribsDef < MiniTest::Test
|
11
|
-
|
12
|
-
def test_attribs
|
13
|
-
|
14
|
-
attribs = Factbook.attributes
|
15
|
-
pp attribs
|
16
|
-
|
17
|
-
assert true
|
18
|
-
end
|
19
|
-
|
20
|
-
end # class TestAttribsDef
|
data/test/test_convert.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_convert.rb
|
6
|
-
|
7
|
-
require 'helper'
|
8
|
-
|
9
|
-
|
10
|
-
class TestConvert < MiniTest::Test
|
11
|
-
|
12
|
-
def test_au
|
13
|
-
im = Factbook::Importer.new
|
14
|
-
|
15
|
-
###########
|
16
|
-
## Geography
|
17
|
-
assert_equal 83_871, im.sq_km( "83,871 sq km" ) ## page.area
|
18
|
-
assert_equal 82_445, im.sq_km( "82,445 sq km" ) ## page.area_land
|
19
|
-
assert_equal 1_426, im.sq_km( "1,426 sq km" ) ## page.area_water
|
20
|
-
|
21
|
-
###################
|
22
|
-
## People and Society
|
23
|
-
assert_equal 8_665_550, im.num( "8,665,550 (July 2015 est.)" ) ## page.population
|
24
|
-
assert_equal 0.55, im.percent( "0.55% (2015 est.)" ) ## page.population_growth
|
25
|
-
assert_equal 9.41, im.rate_per_thousand( "9.41 births/1,000 population (2015 est.)" ) ## page.birth_rate
|
26
|
-
assert_equal 9.42, im.rate_per_thousand( "9.42 deaths/1,000 population (2015 est.)" ) ## page.death_rate
|
27
|
-
assert_equal 5.56, im.rate_per_thousand( "5.56 migrant(s)/1,000 population (2015 est.)" ) ## page.migration_rate
|
28
|
-
end
|
29
|
-
|
30
|
-
end # class TestConvert
|
data/test/test_importer.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_importer.rb
|
6
|
-
|
7
|
-
require 'helper'
|
8
|
-
|
9
|
-
|
10
|
-
class TestImporter < MiniTest::Test
|
11
|
-
|
12
|
-
def setup_in_memory_db
|
13
|
-
# Database Setup & Config
|
14
|
-
ActiveRecord::Base.logger = Logger.new( STDOUT )
|
15
|
-
## ActiveRecord::Base.colorize_logging = false - no longer exists - check new api/config setting?
|
16
|
-
|
17
|
-
ActiveRecord::Base.establish_connection( adapter: 'sqlite3',
|
18
|
-
database: ':memory:' )
|
19
|
-
|
20
|
-
## build schema
|
21
|
-
Factbook::CreateDb.new.up
|
22
|
-
end
|
23
|
-
|
24
|
-
def read_test_page( code )
|
25
|
-
html = File.read( "#{Factbook.root}/test/data/src/#{code}.html" )
|
26
|
-
page = Factbook::Page.new( code, html: html )
|
27
|
-
page
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
def to_be_done_test_au_fix_me
|
32
|
-
page = read_test_page( 'au' ) # use builtin test page (do NOT fetch via internet)
|
33
|
-
|
34
|
-
setup_in_memory_db()
|
35
|
-
|
36
|
-
im = Factbook::Importer.new
|
37
|
-
im.import( page )
|
38
|
-
|
39
|
-
rec = Factbook::Fact.find_by! code: 'au'
|
40
|
-
|
41
|
-
###########
|
42
|
-
## Geography
|
43
|
-
assert_equal 83_871, rec.area
|
44
|
-
assert_equal 82_445, rec.area_land
|
45
|
-
assert_equal 1_426, rec.area_water
|
46
|
-
|
47
|
-
###################
|
48
|
-
## People and Society
|
49
|
-
assert_equal 8_665_550, rec.population
|
50
|
-
assert_equal 0.55, rec.population_growth
|
51
|
-
assert_equal 9.41, rec.birth_rate
|
52
|
-
assert_equal 9.42, rec.death_rate
|
53
|
-
assert_equal 5.56, rec.migration_rate
|
54
|
-
end
|
55
|
-
|
56
|
-
end # class TestImporter
|