factbook 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Manifest.txt +6 -0
- data/README.md +28 -1
- data/Rakefile +2 -1
- data/lib/factbook.rb +7 -0
- data/lib/factbook/db/importer.rb +92 -0
- data/lib/factbook/db/models.rb +11 -0
- data/lib/factbook/db/schema.rb +36 -0
- data/lib/factbook/page.rb +45 -0
- data/lib/factbook/version.rb +2 -2
- data/script/testbr.rb +23 -0
- data/test/test_attribs.rb +51 -0
- data/test/test_convert.rb +30 -0
- data/test/test_importer.rb +55 -0
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24d96765bcda05d51ce7f72baa5f565da45aa85b
|
4
|
+
data.tar.gz: 7841f960d9905ad051c6ef255f374ed875091f88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93fac1f61de8fcd72e98afb4ed5bb6619cb849fac69ef979c2a5703fd2886a0cf8b6a9c260cb179c3209d6d61a57170ac7dc11e81c59928ec3532efcbf212180
|
7
|
+
data.tar.gz: 5e84df0a02a7278b9cb54f19fd02364abe302c78a1aa222b334e3844141b13d82c10e1e51b53d5a906bbb8f43ee59cd44b02abde2aff58c6f1cff37355346ce8
|
data/Manifest.txt
CHANGED
@@ -11,6 +11,9 @@ lib/factbook/builder.rb
|
|
11
11
|
lib/factbook/builder_item.rb
|
12
12
|
lib/factbook/codes.rb
|
13
13
|
lib/factbook/comparisons.rb
|
14
|
+
lib/factbook/db/importer.rb
|
15
|
+
lib/factbook/db/models.rb
|
16
|
+
lib/factbook/db/schema.rb
|
14
17
|
lib/factbook/page.rb
|
15
18
|
lib/factbook/sanitizer.rb
|
16
19
|
lib/factbook/sect.rb
|
@@ -28,10 +31,13 @@ test/data/be.yml
|
|
28
31
|
test/data/src/au.html
|
29
32
|
test/data/src/be.html
|
30
33
|
test/helper.rb
|
34
|
+
test/test_attribs.rb
|
31
35
|
test/test_builder.rb
|
32
36
|
test/test_codes.rb
|
33
37
|
test/test_comparisons.rb
|
38
|
+
test/test_convert.rb
|
34
39
|
test/test_fields.rb
|
40
|
+
test/test_importer.rb
|
35
41
|
test/test_item_builder.rb
|
36
42
|
test/test_json.rb
|
37
43
|
test/test_page.rb
|
data/README.md
CHANGED
@@ -64,6 +64,33 @@ resulting in:
|
|
64
64
|
...
|
65
65
|
```
|
66
66
|
|
67
|
+
### Use shortcut attribute accessors
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
pp page.background ## same as page['Introduction']['Background']['text']
|
71
|
+
# => "Following more than three centuries..."
|
72
|
+
pp page.area ## same as page['Geography'][''Area']['total']['text']
|
73
|
+
# => "8,515,770 sq km"
|
74
|
+
pp page.area_land ## same as page['Geography'][''Area']['land']['text']
|
75
|
+
# => "8,358,140 sq km"
|
76
|
+
pp page.area_water ## same as page['Geography'][''Area']['water']['text']
|
77
|
+
# => "157,630 sq km"
|
78
|
+
pp page.area_note ## same as page['Geography'][''Area']['note']['text']
|
79
|
+
# => "includes Arquipelago de Fernando de Noronha, Atol das Rocas, ..."
|
80
|
+
pp page.area_comparative ## same as page['Geography']['Area - comparative']['text']
|
81
|
+
# => "slightly smaller than the US"
|
82
|
+
pp page.climate ## same as page['Geography']['Climate']['text']
|
83
|
+
# => "mostly tropical, but temperate in south"
|
84
|
+
pp page.terrain ## same as page['Geography']['Terrain']['text']
|
85
|
+
# => "mostly flat to rolling lowlands in north; ..."
|
86
|
+
pp page.elevation_lowest ## same as page['Geography']['Elevation extremes']['lowest point']['text']
|
87
|
+
# => "Atlantic Ocean 0 m"
|
88
|
+
pp page.elevation_highest ## same as page['Geography']['Elevation extremes']['highest point']['text']
|
89
|
+
# => "Pico da Neblina 2,994 m"
|
90
|
+
pp page.resources ## same as page['Geography'][Natural resources']['text']
|
91
|
+
# => "bauxite, gold, iron ore, manganese, nickel, phosphates, ..."
|
92
|
+
...
|
93
|
+
```
|
67
94
|
|
68
95
|
### Save to disk as JSON
|
69
96
|
|
@@ -75,7 +102,7 @@ end
|
|
75
102
|
```
|
76
103
|
|
77
104
|
|
78
|
-
###
|
105
|
+
### List all codes
|
79
106
|
|
80
107
|
```ruby
|
81
108
|
Factbook.codes.each do |code|
|
data/Rakefile
CHANGED
data/lib/factbook.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
## stdlibs
|
4
4
|
|
5
5
|
require 'net/http'
|
6
|
+
require 'net/https' ## note: cia factbook requires https
|
6
7
|
require 'uri'
|
7
8
|
require 'cgi'
|
8
9
|
require 'pp'
|
@@ -18,6 +19,8 @@ require 'logutils'
|
|
18
19
|
require 'fetcher'
|
19
20
|
require 'nokogiri'
|
20
21
|
|
22
|
+
require 'active_record' ## add activerecord/db support (NOT optional for now)
|
23
|
+
|
21
24
|
|
22
25
|
# our own code
|
23
26
|
|
@@ -36,6 +39,10 @@ require 'factbook/comparisons'
|
|
36
39
|
|
37
40
|
require 'factbook/table' ## e.g. TableReader
|
38
41
|
|
42
|
+
require 'factbook/db/schema' ## database (sql tables) support
|
43
|
+
require 'factbook/db/models'
|
44
|
+
require 'factbook/db/importer'
|
45
|
+
|
39
46
|
|
40
47
|
|
41
48
|
module Factbook
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Factbook
|
4
|
+
|
5
|
+
class Importer
|
6
|
+
|
7
|
+
def import( page )
|
8
|
+
|
9
|
+
## note: assumes active connection
|
10
|
+
|
11
|
+
code = page.info.country_code
|
12
|
+
name = page.info.country_name
|
13
|
+
|
14
|
+
attribs = {
|
15
|
+
name: name,
|
16
|
+
area: sq_km( page.area ), # e.g. 83,871 sq km
|
17
|
+
area_land: sq_km( page.area_land ), # e.g. 82,445 sq km
|
18
|
+
area_water: sq_km( page.area_water ), # e.g. 1,426 sq km
|
19
|
+
|
20
|
+
population: num( page.population ), # e.g. 8,665,550 (July 2015 est.)
|
21
|
+
population_growth: percent( page.population_growth ), # e.g. 0.55% (2015 est.)
|
22
|
+
birth_rate: rate_per_thousand( page.birth_rate ), # e.g. 9.41 births/1,000 population (2015 est.)
|
23
|
+
death_rate: rate_per_thousand( page.death_rate ), # e.g. 9.42 deaths/1,000 population (2015 est.)
|
24
|
+
migration_rate: rate_per_thousand( page.migration_rate ), # e.g. 5.56 migrant(s)/1,000 population (2015 est.)
|
25
|
+
}
|
26
|
+
|
27
|
+
rec = Fact.find_by( code: code )
|
28
|
+
if rec.nil? ## create (new) record
|
29
|
+
rec = Fact.new
|
30
|
+
attribs[ :code ] = code
|
31
|
+
puts "create fact record #{code}/#{name}:"
|
32
|
+
else ## update (exisiting) record
|
33
|
+
puts "update fact record #{code}/#{name}:"
|
34
|
+
end
|
35
|
+
|
36
|
+
puts " #{attribs.inspect}"
|
37
|
+
rec.update_attributes!( attribs )
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def rate_per_thousand( text )
|
42
|
+
# e.g. 9.41 births/1,000 population (2015 est.)
|
43
|
+
# 9.42 deaths/1,000 population (2015 est.)
|
44
|
+
# 5.56 migrant(s)/1,000 population (2015 est.)
|
45
|
+
|
46
|
+
if text =~/([0-9\.]+) [a-z\(\)]+\/1,000/
|
47
|
+
$1.to_f
|
48
|
+
else
|
49
|
+
puts "*** warn: unknown rate <name>/1,000 format (no match): >#{text}<"
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def num( text )
|
55
|
+
# e.g. 8,665,550 (July 2015 est.)
|
56
|
+
|
57
|
+
if text =~/([0-9,\.]+)/
|
58
|
+
$1.gsub(',', '').to_i ## note: remove commas (,) if present
|
59
|
+
else
|
60
|
+
puts "*** warn: unknown number format (no match): >#{text}<"
|
61
|
+
nil ## return nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def percent( text )
|
66
|
+
# e.g. 0.55% (2015 est.)
|
67
|
+
|
68
|
+
if text =~/([0-9\.]+)%/
|
69
|
+
$1.to_f
|
70
|
+
else
|
71
|
+
puts "*** warn: unknown percent format (no match): >#{text}<"
|
72
|
+
nil ## return nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def sq_km( text )
|
77
|
+
# e.g. 83,871 sq km
|
78
|
+
## todo - check vatican - uses float e.g. 0.44 ?? add support?
|
79
|
+
|
80
|
+
if text =~/([0-9,\.]+) sq km/
|
81
|
+
$1.gsub(',', '').to_i ## note: remove commas (,) if present
|
82
|
+
else
|
83
|
+
puts "*** warn: unknown sq km format (no match): >#{text}<"
|
84
|
+
nil ## return nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
end # class Importer
|
90
|
+
|
91
|
+
end # module Factbook
|
92
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Factbook
|
4
|
+
|
5
|
+
class CreateDb
|
6
|
+
|
7
|
+
def up
|
8
|
+
|
9
|
+
ActiveRecord::Schema.define do
|
10
|
+
|
11
|
+
create_table :facts do |t|
|
12
|
+
t.string :code, null: false # country code e.g. au
|
13
|
+
t.string :name, null: false # country name e.g. Austria
|
14
|
+
|
15
|
+
t.integer :area # e.g. 83,871 sq km
|
16
|
+
t.integer :area_land # e.g. 82,445 sq km --use float - why? why not?
|
17
|
+
t.integer :area_water # e.g. 1,426 sq km
|
18
|
+
|
19
|
+
t.integer :population # e.g. 8,665,550 (July 2015 est.)
|
20
|
+
t.float :population_growth # e.g. 0.55% (2015 est.)
|
21
|
+
t.float :birth_rate # e.g. 9.41 births/1,000 population (2015 est.)
|
22
|
+
t.float :death_rate # e.g. 9.42 deaths/1,000 population (2015 est.)
|
23
|
+
t.float :migration_rate # e.g. 5.56 migrant(s)/1,000 population (2015 est.)
|
24
|
+
|
25
|
+
t.timestamps
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end # block Schema.define
|
30
|
+
|
31
|
+
end # method up
|
32
|
+
|
33
|
+
|
34
|
+
end # class CreateDb
|
35
|
+
|
36
|
+
end # module Factbook
|
data/lib/factbook/page.rb
CHANGED
@@ -29,6 +29,7 @@ class Page
|
|
29
29
|
include LogUtils::Logging
|
30
30
|
|
31
31
|
attr_reader :sects ## "structured" access e.g. sects/subsects/etc.
|
32
|
+
attr_reader :info ## meta info e.g. country_code, country_name, region_name, last_updated, etc.
|
32
33
|
attr_reader :data ## "plain" access with vanilla hash
|
33
34
|
|
34
35
|
|
@@ -49,6 +50,7 @@ class Page
|
|
49
50
|
|
50
51
|
b = Builder.from_string( html )
|
51
52
|
@sects = b.sects
|
53
|
+
@info = b.page_info ## todo: change b.page_info to info too - why? why not??
|
52
54
|
|
53
55
|
@data = {}
|
54
56
|
@sects.each do |sect|
|
@@ -80,6 +82,49 @@ class Page
|
|
80
82
|
data[key]
|
81
83
|
end
|
82
84
|
|
85
|
+
## add convenience (shortcut) accessors / attributes / fields / getters
|
86
|
+
|
87
|
+
ATTRIBUTES = {
|
88
|
+
'Introduction' => [[:background, 'Background' ]],
|
89
|
+
'Geography' => [[:area, 'Area', 'total'], ## convert to number -- why? why not??
|
90
|
+
[:area_land, 'Area', 'land' ],
|
91
|
+
[:area_water, 'Area', 'water'],
|
92
|
+
[:area_note, 'Area', 'note' ],
|
93
|
+
[:area_comparative, 'Area - comparative'],
|
94
|
+
[:climate, 'Climate'],
|
95
|
+
[:terrain, 'Terrain'],
|
96
|
+
[:elevation_lowest, 'Elevation extremes', 'lowest point'],
|
97
|
+
[:elevation_highest,'Elevation extremes', 'highest point'],
|
98
|
+
[:resources, 'Natural resources']],
|
99
|
+
'People and Society' => [[:languages, 'Languages' ],
|
100
|
+
[:religions, 'Religions' ],
|
101
|
+
[:population, 'Population' ],
|
102
|
+
[:population_growth, 'Population growth rate' ],
|
103
|
+
[:birth_rate, 'Birth rate' ],
|
104
|
+
[:death_rate, 'Death rate' ],
|
105
|
+
[:migration_rate, 'Net migration rate' ],
|
106
|
+
[:major_cities, 'Major urban areas - population' ]],
|
107
|
+
}
|
108
|
+
|
109
|
+
ATTRIBUTES.each do |section_title, attribs|
|
110
|
+
attribs.each do |attrib|
|
111
|
+
## e.g.
|
112
|
+
## def background() data['Introduction']['Background']['text']; end
|
113
|
+
## def location() data['Geography']['Location']['text']; end
|
114
|
+
## etc.
|
115
|
+
if attrib.size == 2
|
116
|
+
define_method attrib[0] do
|
117
|
+
@data.fetch( section_title, {} ).fetch( attrib[1], {} )['text']
|
118
|
+
end
|
119
|
+
else ## assume size 3 for now
|
120
|
+
define_method attrib[0] do
|
121
|
+
@data.fetch( section_title, {} ).fetch( attrib[1], {} ).fetch( attrib[2], {} )['text']
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
|
83
128
|
private
|
84
129
|
def fetch_page( url_string )
|
85
130
|
|
data/lib/factbook/version.rb
CHANGED
data/script/testbr.rb
CHANGED
@@ -8,3 +8,26 @@ require 'factbook'
|
|
8
8
|
page = Factbook::Page.new( 'br' ) # br is the country code for Brazil
|
9
9
|
pp page.data # pretty print hash
|
10
10
|
|
11
|
+
puts "background:"
|
12
|
+
pp page.background ## same as page['Introduction']['Background']['text']
|
13
|
+
puts "area:"
|
14
|
+
pp page.area ## same as page['Geography'][''Area']['total']['text']
|
15
|
+
puts "area_land:"
|
16
|
+
pp page.area_land ## same as page['Geography'][''Area']['land']['text']
|
17
|
+
puts "area_water:"
|
18
|
+
pp page.area_water ## same as page['Geography'][''Area']['water']['text']
|
19
|
+
puts "area_note:"
|
20
|
+
pp page.area_note ## same as page['Geography'][''Area']['note']['text']
|
21
|
+
puts "area comparative:"
|
22
|
+
pp page.area_comparative ## same as page['Geography']['Area - comparative']['text']
|
23
|
+
puts "climate:"
|
24
|
+
pp page.climate ## same as page['Geography']['Climate']['text']
|
25
|
+
puts "terrain:"
|
26
|
+
pp page.terrain ## same as page['Geography']['Terrain']['text']
|
27
|
+
puts "elevation_lowest:"
|
28
|
+
pp page.elevation_lowest ## same as page['Geography']['Elevation extremes']['lowest point']['text']
|
29
|
+
puts "elevation_highest:"
|
30
|
+
pp page.elevation_highest ## same as page['Geography']['Elevation extremes']['highest point']['text']
|
31
|
+
puts "resources:"
|
32
|
+
pp page.resources ## same as page['Geography'][Natural resources']['text']
|
33
|
+
|
@@ -0,0 +1,51 @@
|
|
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 test_au
|
19
|
+
page = read_test_page( 'au' ) # use builtin test page (do NOT fetch via internet)
|
20
|
+
|
21
|
+
########
|
22
|
+
## Introduction
|
23
|
+
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 European Union in 1995 have altered the meaning of this neutrality. A prosperous, democratic country, Austria entered the EU Economic and Monetary Union in 1999."
|
24
|
+
|
25
|
+
###########
|
26
|
+
## Geography
|
27
|
+
assert_equal page.area, "83,871 sq km"
|
28
|
+
assert_equal page.area_land, "82,445 sq km"
|
29
|
+
assert_equal page.area_water, "1,426 sq km"
|
30
|
+
assert_equal page.area_note, nil
|
31
|
+
assert_equal page.area_comparative, "about the size of South Carolina; slightly more than two-thirds the size of Pennsylvania"
|
32
|
+
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"
|
33
|
+
assert_equal page.terrain, "mostly mountains (Alps) in the west and south; mostly flat or gently sloping along the eastern and northern margins"
|
34
|
+
assert_equal page.elevation_lowest, "Neusiedler See 115 m"
|
35
|
+
assert_equal page.elevation_highest, "Grossglockner 3,798 m"
|
36
|
+
assert_equal page.resources, "oil, coal, lignite, timber, iron ore, copper, zinc, antimony, magnesite, tungsten, graphite, salt, hydropower"
|
37
|
+
|
38
|
+
###################
|
39
|
+
## People and Society
|
40
|
+
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.)"
|
41
|
+
assert_equal page.religions, "Catholic 73.8% (includes Roman Catholic 73.6%, other Catholic .2%), Protestant 4.9%, Muslim 4.2%, Orthodox 2.2%, other 0.8% (includes other Christian), none 12%, unspecified 2% (2001 est.)"
|
42
|
+
assert_equal page.population, "8,665,550 (July 2015 est.)"
|
43
|
+
assert_equal page.population_growth, "0.55% (2015 est.)"
|
44
|
+
assert_equal page.birth_rate, "9.41 births/1,000 population (2015 est.)"
|
45
|
+
assert_equal page.death_rate, "9.42 deaths/1,000 population (2015 est.)"
|
46
|
+
assert_equal page.migration_rate, "5.56 migrant(s)/1,000 population (2015 est.)"
|
47
|
+
assert_equal page.major_cities, "VIENNA (capital) 1.753 million (2015)"
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end # class TestAttribs
|
@@ -0,0 +1,30 @@
|
|
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
|
@@ -0,0 +1,55 @@
|
|
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
|
+
def test_au
|
31
|
+
page = read_test_page( 'au' ) # use builtin test page (do NOT fetch via internet)
|
32
|
+
|
33
|
+
setup_in_memory_db()
|
34
|
+
|
35
|
+
im = Factbook::Importer.new
|
36
|
+
im.import( page )
|
37
|
+
|
38
|
+
rec = Factbook::Fact.find_by! code: 'au'
|
39
|
+
|
40
|
+
###########
|
41
|
+
## Geography
|
42
|
+
assert_equal 83_871, rec.area
|
43
|
+
assert_equal 82_445, rec.area_land
|
44
|
+
assert_equal 1_426, rec.area_water
|
45
|
+
|
46
|
+
###################
|
47
|
+
## People and Society
|
48
|
+
assert_equal 8_665_550, rec.population
|
49
|
+
assert_equal 0.55, rec.population_growth
|
50
|
+
assert_equal 9.41, rec.birth_rate
|
51
|
+
assert_equal 9.42, rec.death_rate
|
52
|
+
assert_equal 5.56, rec.migration_rate
|
53
|
+
end
|
54
|
+
|
55
|
+
end # class TestImporter
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factbook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logutils
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rdoc
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,6 +117,9 @@ files:
|
|
103
117
|
- lib/factbook/builder_item.rb
|
104
118
|
- lib/factbook/codes.rb
|
105
119
|
- lib/factbook/comparisons.rb
|
120
|
+
- lib/factbook/db/importer.rb
|
121
|
+
- lib/factbook/db/models.rb
|
122
|
+
- lib/factbook/db/schema.rb
|
106
123
|
- lib/factbook/page.rb
|
107
124
|
- lib/factbook/sanitizer.rb
|
108
125
|
- lib/factbook/sect.rb
|
@@ -120,10 +137,13 @@ files:
|
|
120
137
|
- test/data/src/au.html
|
121
138
|
- test/data/src/be.html
|
122
139
|
- test/helper.rb
|
140
|
+
- test/test_attribs.rb
|
123
141
|
- test/test_builder.rb
|
124
142
|
- test/test_codes.rb
|
125
143
|
- test/test_comparisons.rb
|
144
|
+
- test/test_convert.rb
|
126
145
|
- test/test_fields.rb
|
146
|
+
- test/test_importer.rb
|
127
147
|
- test/test_item_builder.rb
|
128
148
|
- test/test_json.rb
|
129
149
|
- test/test_page.rb
|