the_country_identity 0.0.2 → 0.0.3
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 240143087b06b0988f6be0a9f05363daac91b1d4
|
4
|
+
data.tar.gz: 02ac846e8d921b7b2aa3bdacde1bc446615284a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8335ab858d3e574bca074e4464694789bb9900e987f6a4421c08667b982f734a8a36f2b14aa0d6ec089c6f142c8aa2a887380206c8f6dee1a7a3b749b7428d6c
|
7
|
+
data.tar.gz: 227e8e03d4d0b1e6ae5dd5a0313aae64f90b1dcf0d1fb9ce86f2692ec1b970e53abe4e40a1217092f721fa10394da38b88f6706a900a24de0130cbe8d5a8b052
|
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# TheCountryIdentity
|
2
2
|
|
3
|
-
[](http://badge.fury.io/rb/the_country_identity) [](https://travis-ci.org/p1nox/the_country_identity) [](https://coveralls.io/r/p1nox/the_country_identity)
|
4
4
|
|
5
5
|
Introducing __the_country_identity__, a [CIA World Factbook](https://www.cia.gov/library/publications/the-world-factbook/) crawler gem, honoring _[The Bourne Series](http://en.wikipedia.org/wiki/Bourne_Series)_.
|
6
6
|
|
7
|
-
The source of information is a [RDF Turtle endpoint](http://wifo5-04.informatik.uni-mannheim.de/factbook/all) served
|
7
|
+
The source of information is a [RDF Turtle endpoint](http://wifo5-04.informatik.uni-mannheim.de/factbook/all) served from the [D2R Server for the CIA Factbook](http://wifo5-03.informatik.uni-mannheim.de/factbook/) hosted by the [Research Group Data and Web Science](http://dws.informatik.uni-mannheim.de/en/home/) at the University of Mannheim, Germany. In case you get no information from an existing country try [here](http://wifo5-03.informatik.uni-mannheim.de/factbook/data/venezuela) or [here](http://wifo5-04.informatik.uni-mannheim.de/factbook/all) to see if this server is alive.
|
8
|
+
|
9
|
+
__This is experimental software, you can use it on production at your own risk.__
|
8
10
|
|
9
11
|
## Installation
|
10
12
|
|
@@ -32,7 +34,9 @@ Or install it yourself as:
|
|
32
34
|
> country.get_property('lifeexpectancyatbirth_totalpopulation')
|
33
35
|
=> "73.28E0"
|
34
36
|
|
35
|
-
You can find all the country property keys [here](http://wifo5-04.informatik.uni-mannheim.de/factbook/page/venezuela).
|
37
|
+
You can find all the country property keys [here](http://wifo5-04.informatik.uni-mannheim.de/factbook/page/venezuela) and a running example on a rails application [here](https://github.com/alphadeville/mil1-api).
|
38
|
+
|
39
|
+
* Note: properties will be lazy returned, so a request to the RDF server will be fired only at the first execution of `get_property` method.
|
36
40
|
|
37
41
|
## Roadmap
|
38
42
|
|
@@ -6,46 +6,38 @@ module TheCountryIdentity
|
|
6
6
|
@@URI_PREFIX = 'http://wifo5-03.informatik.uni-mannheim.de/factbook/data/'
|
7
7
|
@@STATEMENT_PREFIX = 'http://wifo5-04.informatik.uni-mannheim.de/factbook/ns#'
|
8
8
|
|
9
|
+
attr_accessor :cache
|
9
10
|
attr_reader :country_name
|
10
11
|
attr_reader :url
|
11
|
-
attr_reader :
|
12
|
-
attr_accessor :data
|
12
|
+
attr_reader :repository
|
13
13
|
|
14
|
-
def initialize(
|
15
|
-
|
14
|
+
def initialize(country_name)
|
15
|
+
@cache = {}
|
16
|
+
@country_name = country_name.downcase.gsub(' ', '_').gsub('usa', 'united_states')
|
17
|
+
@url = @@URI_PREFIX + @country_name
|
16
18
|
end
|
17
19
|
|
18
20
|
def get_property(property_name)
|
19
|
-
return @
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
return @cache[property_name] if @cache[property_name]
|
22
|
+
|
23
|
+
begin
|
24
|
+
unless repo.nil?
|
25
|
+
options = { :predicate => ::RDF::URI("#{@@STATEMENT_PREFIX}#{property_name}") }
|
26
|
+
repo.query(options) do |stmnt|
|
27
|
+
@cache[property_name] = stmnt.object.value
|
28
|
+
end
|
25
29
|
end
|
30
|
+
rescue => e
|
31
|
+
puts "Not able to get country information, through exception: #{e}"
|
26
32
|
end
|
27
33
|
|
28
|
-
@
|
29
|
-
end
|
30
|
-
|
31
|
-
def fetch_country(country_name)
|
32
|
-
@data = {}
|
33
|
-
unless country_name.nil?
|
34
|
-
@country_name = country_name.downcase.gsub(' ', '_').gsub('usa', 'united_states')
|
35
|
-
@url = @@URI_PREFIX + @country_name
|
36
|
-
|
37
|
-
begin
|
38
|
-
fetch_rdf
|
39
|
-
rescue => e
|
40
|
-
puts "Not able to get country information, through exception: #{e}"
|
41
|
-
end
|
42
|
-
end
|
34
|
+
@cache[property_name]
|
43
35
|
end
|
44
36
|
|
45
37
|
private
|
46
38
|
|
47
|
-
def
|
48
|
-
@
|
39
|
+
def repo
|
40
|
+
@repository ||= ::RDF::Repository.load(@url)
|
49
41
|
end
|
50
42
|
|
51
43
|
end
|
@@ -22,13 +22,14 @@ describe TheCountryIdentity do
|
|
22
22
|
expect(@country.url).to eq 'http://wifo5-03.informatik.uni-mannheim.de/factbook/data/operation_treadstone'
|
23
23
|
end
|
24
24
|
|
25
|
-
it 'sets correct
|
26
|
-
|
25
|
+
it 'sets correct repository (RDF::Repository)' do
|
26
|
+
@country.get_property('lifeexpectancyatbirth_totalpopulation')
|
27
|
+
expect(@country.repository).to be_nil
|
27
28
|
end
|
28
29
|
|
29
|
-
it 'sets initial value
|
30
|
-
expect(@country.
|
31
|
-
expect(@country.
|
30
|
+
it 'sets initial value to be cached' do
|
31
|
+
expect(@country.cache).to be_instance_of(Hash)
|
32
|
+
expect(@country.cache.empty?).to be_truthy
|
32
33
|
end
|
33
34
|
|
34
35
|
it 'returns nil value for a given property' do
|
@@ -58,19 +59,20 @@ describe TheCountryIdentity do
|
|
58
59
|
expect(@country.url).to eq 'http://wifo5-03.informatik.uni-mannheim.de/factbook/data/venezuela'
|
59
60
|
end
|
60
61
|
|
61
|
-
it 'sets correct
|
62
|
-
|
63
|
-
expect(@country.
|
64
|
-
expect(@country.
|
65
|
-
expect(@country.
|
66
|
-
expect(@country.
|
67
|
-
expect(@country.
|
68
|
-
expect(@country.
|
62
|
+
it 'sets correct repository (RDF::Repository)' do
|
63
|
+
@country.get_property('lifeexpectancyatbirth_totalpopulation')
|
64
|
+
expect(@country.repository).to be_instance_of(::RDF::Repository)
|
65
|
+
expect(@country.repository.readable?).to be_truthy
|
66
|
+
expect(@country.repository.writable?).to be_truthy
|
67
|
+
expect(@country.repository.persistent?).to be_falsey
|
68
|
+
expect(@country.repository.transient?).to be_truthy
|
69
|
+
expect(@country.repository.empty?).to be_falsey
|
70
|
+
expect(@country.repository.count).to be 197
|
69
71
|
end
|
70
72
|
|
71
|
-
it 'sets initial value
|
72
|
-
expect(@country.
|
73
|
-
expect(@country.
|
73
|
+
it 'sets initial value to be cached' do
|
74
|
+
expect(@country.cache).to be_instance_of(Hash)
|
75
|
+
expect(@country.cache.empty?).to be_truthy
|
74
76
|
end
|
75
77
|
|
76
78
|
it 'returns a custom value for a given property' do
|
@@ -78,14 +80,14 @@ describe TheCountryIdentity do
|
|
78
80
|
life_expectancy = @country.get_property(property)
|
79
81
|
expect(life_expectancy).to be_instance_of(String)
|
80
82
|
expect(life_expectancy).to eq '73.28E0'
|
81
|
-
expect(@country.
|
83
|
+
expect(@country.cache[property]).to eq '73.28E0'
|
82
84
|
end
|
83
85
|
|
84
86
|
it 'returns nil value for a given unknown property' do
|
85
87
|
property = 'operation_blackbriar'
|
86
88
|
life_expectancy = @country.get_property(property)
|
87
89
|
expect(life_expectancy).to be_nil
|
88
|
-
expect(@country.
|
90
|
+
expect(@country.cache[property]).to be_nil
|
89
91
|
end
|
90
92
|
|
91
93
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_country_identity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raul Pino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: linkeddata
|
@@ -183,7 +183,7 @@ files:
|
|
183
183
|
- lib/the_country_identity/rdf.rb
|
184
184
|
- lib/the_country_identity/version.rb
|
185
185
|
- spec/spec_helper.rb
|
186
|
-
- spec/
|
186
|
+
- spec/the_country_identity_rdf_spec.rb
|
187
187
|
- the_country_identity.gemspec
|
188
188
|
homepage: https://github.com/p1nox/the_country_identity
|
189
189
|
licenses:
|
@@ -211,4 +211,4 @@ specification_version: 4
|
|
211
211
|
summary: Fetch data from CIA World Factbook
|
212
212
|
test_files:
|
213
213
|
- spec/spec_helper.rb
|
214
|
-
- spec/
|
214
|
+
- spec/the_country_identity_rdf_spec.rb
|