everypolitician-popolo 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +31 -6
- data/lib/everypolitician/popolo.rb +14 -76
- data/lib/everypolitician/popolo/area.rb +18 -0
- data/lib/everypolitician/popolo/collection.rb +18 -0
- data/lib/everypolitician/popolo/event.rb +18 -0
- data/lib/everypolitician/popolo/membership.rb +26 -0
- data/lib/everypolitician/popolo/organization.rb +25 -0
- data/lib/everypolitician/popolo/person.rb +97 -0
- data/lib/everypolitician/popolo/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 819ab96e2d0f30e3bf74ba4778a571516a159a36
|
4
|
+
data.tar.gz: db95c96de4e2645f3610aefa37121649599f509f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 111f78af9e392de63fbc5c4cda75ed9752653a2a8472b0980e60956f3cd72f850d8f63769d9e0f6bab719644f9bc3454d3a1d2c0a3e581294038e12b3d9c85ce
|
7
|
+
data.tar.gz: 64c9211c16d8f2f19b49266b34820db29c80ef634e2ebf320efa96947014e82eecf3ea5e2ecde1cdc4da0c7b65e710c3b164b54d3df6d5d120f52345fbd9ddeb
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
5
|
+
|
6
|
+
## [0.2.0] - 2016-03-11
|
7
|
+
|
8
|
+
## Added
|
9
|
+
|
10
|
+
- Support for all Popolo collections that EveryPolitician uses - People, Organizations, Areas, Memberships and Events. Thanks to @equivalentideas and @henare for this contribution!
|
11
|
+
|
12
|
+
## 0.1.0 - 2016-01-26
|
13
|
+
|
14
|
+
- Initial release
|
15
|
+
|
16
|
+
[0.2.0]: https://github.com/everypolitician/everypolitician-popolo/compare/v0.1.0...v0.2.0
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Everypolitician::Popolo
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
[EveryPolitician](http://everypolitician.org) provides its data in [Popolo](http://www.popoloproject.com/) format. If you want to interact with this data from Ruby then this library should make that task simpler.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,35 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
You'll need to download a Popolo file from [EveryPolitician](http://everypolitician.org/). The following example uses [Åland Lagting](https://github.com/everypolitician/everypolitician-data/raw/master/data/Aland/Lagting/ep-popolo-v1.0.json) (which is the legislature of the Åland islands,
|
24
|
+
available as JSON data from the
|
25
|
+
[EveryPolitician page for Åland](http://everypolitician.org/aland/)).
|
26
|
+
|
27
|
+
First you'll need to require the library and read in a file from disk.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'everypolitician/popolo'
|
31
|
+
popolo = Everypolitician::Popolo.read('ep-popolo-v1.0.json')
|
32
|
+
```
|
33
|
+
|
34
|
+
All Popolo classes used by EveryPolitician are implemented:
|
35
|
+
|
36
|
+
* [Person](http://www.popoloproject.com/specs/person.html)
|
37
|
+
* [Organization](http://www.popoloproject.com/specs/organization.html)
|
38
|
+
* [Area](http://www.popoloproject.com/specs/area.html)
|
39
|
+
* [Event](http://www.popoloproject.com/specs/event.html)
|
40
|
+
* [Membership](http://www.popoloproject.com/specs/membership.html)
|
41
|
+
|
42
|
+
There are methods defined for each property on a class, e.g. for a Person:
|
43
|
+
|
44
|
+
```
|
45
|
+
popolo.persons.count # => 47
|
46
|
+
person = popolo.persons.first
|
47
|
+
person.id # => "e3aab23e-a883-4763-be0d-92e5936024e2"
|
48
|
+
person.name # => "Aaltonen Carina"
|
49
|
+
person.image # => "http://www.lagtinget.ax/files/aaltonen_carina.jpg"
|
50
|
+
person.wikidata # => "Q4934081"
|
51
|
+
```
|
26
52
|
|
27
53
|
## Development
|
28
54
|
|
@@ -32,10 +58,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
58
|
|
33
59
|
## Contributing
|
34
60
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
61
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/everypolitician/everypolitician-popolo.
|
36
62
|
|
37
63
|
|
38
64
|
## License
|
39
65
|
|
40
66
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
@@ -1,4 +1,10 @@
|
|
1
1
|
require 'everypolitician/popolo/version'
|
2
|
+
require 'everypolitician/popolo/collection'
|
3
|
+
require 'everypolitician/popolo/person'
|
4
|
+
require 'everypolitician/popolo/organization'
|
5
|
+
require 'everypolitician/popolo/area'
|
6
|
+
require 'everypolitician/popolo/event'
|
7
|
+
require 'everypolitician/popolo/membership'
|
2
8
|
require 'json'
|
3
9
|
|
4
10
|
module Everypolitician
|
@@ -24,89 +30,21 @@ module Everypolitician
|
|
24
30
|
def persons
|
25
31
|
People.new(popolo[:persons])
|
26
32
|
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class People
|
30
|
-
include Enumerable
|
31
|
-
|
32
|
-
attr_reader :documents
|
33
|
-
|
34
|
-
def initialize(documents)
|
35
|
-
@documents = documents.map { |p| Person.new(p) }
|
36
|
-
end
|
37
|
-
|
38
|
-
def each(&block)
|
39
|
-
documents.each(&block)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class Person
|
44
|
-
class Error < StandardError; end
|
45
|
-
|
46
|
-
attr_reader :document
|
47
|
-
|
48
|
-
def initialize(document)
|
49
|
-
@document = document
|
50
|
-
document.each do |key, value|
|
51
|
-
define_singleton_method(key) { value }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def [](key)
|
56
|
-
document[key]
|
57
|
-
end
|
58
|
-
|
59
|
-
def key?(key)
|
60
|
-
document.key?(key)
|
61
|
-
end
|
62
|
-
|
63
|
-
def links
|
64
|
-
document.fetch(:links, [])
|
65
|
-
end
|
66
|
-
|
67
|
-
def email
|
68
|
-
self[:email]
|
69
|
-
end
|
70
|
-
|
71
|
-
def twitter
|
72
|
-
if key?(:contact_details)
|
73
|
-
if twitter_contact = self[:contact_details].find { |d| d[:type] == 'twitter' }
|
74
|
-
twitter_contact[:value].strip
|
75
|
-
end
|
76
|
-
elsif key?(:links)
|
77
|
-
if twitter_link = self[:links].find { |d| d[:note][/twitter/i] }
|
78
|
-
twitter_link[:url].strip
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def facebook
|
84
|
-
facebook_link = links.find { |d| d[:note] == 'facebook' }
|
85
|
-
facebook_link[:url] if facebook_link
|
86
|
-
end
|
87
33
|
|
88
|
-
def
|
89
|
-
|
90
|
-
historic = other_names.find_all { |n| n.key?(:end_date) }
|
91
|
-
return name if historic.empty?
|
92
|
-
at_date = historic.find_all do |n|
|
93
|
-
n[:end_date] >= date && (n[:start_date] || '0000-00-00') <= date
|
94
|
-
end
|
95
|
-
return name if at_date.empty?
|
96
|
-
fail Error, "Too many names at #{date}: #{at_date}" if at_date.count > 1
|
97
|
-
at_date.first[:name]
|
34
|
+
def organizations
|
35
|
+
Organizations.new(popolo[:organizations])
|
98
36
|
end
|
99
37
|
|
100
|
-
def
|
101
|
-
|
38
|
+
def areas
|
39
|
+
Areas.new(popolo[:areas])
|
102
40
|
end
|
103
41
|
|
104
|
-
def
|
105
|
-
|
42
|
+
def events
|
43
|
+
Events.new(popolo[:events])
|
106
44
|
end
|
107
45
|
|
108
|
-
def
|
109
|
-
|
46
|
+
def memberships
|
47
|
+
Memberships.new(popolo[:memberships])
|
110
48
|
end
|
111
49
|
end
|
112
50
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Everypolitician
|
2
|
+
module Popolo
|
3
|
+
class Areas < Collection
|
4
|
+
def initialize(documents)
|
5
|
+
@documents = documents.map { |p| Area.new(p) }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Area
|
10
|
+
def initialize(document)
|
11
|
+
@document = document
|
12
|
+
document.each do |key, value|
|
13
|
+
define_singleton_method(key) { value }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Everypolitician
|
2
|
+
module Popolo
|
3
|
+
class Collection
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
attr_reader :documents
|
7
|
+
|
8
|
+
def each(&block)
|
9
|
+
documents.each(&block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def -(other)
|
13
|
+
other_ids = Set.new(other.documents.map(&:id))
|
14
|
+
documents.reject { |d| other_ids.include?(d.id) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Everypolitician
|
2
|
+
module Popolo
|
3
|
+
class Events < Collection
|
4
|
+
def initialize(documents)
|
5
|
+
@documents = documents.map { |p| Event.new(p) }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Event
|
10
|
+
def initialize(document)
|
11
|
+
@document = document
|
12
|
+
document.each do |key, value|
|
13
|
+
define_singleton_method(key) { value }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Everypolitician
|
2
|
+
module Popolo
|
3
|
+
class Memberships < Collection
|
4
|
+
def initialize(documents)
|
5
|
+
@documents = documents.map { |p| Membership.new(p) }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Membership
|
10
|
+
def initialize(document)
|
11
|
+
@document = document
|
12
|
+
document.each do |key, value|
|
13
|
+
define_singleton_method(key) { value }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def start_date
|
18
|
+
@document[:start_date]
|
19
|
+
end
|
20
|
+
|
21
|
+
def end_date
|
22
|
+
@document[:end_date]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Everypolitician
|
2
|
+
module Popolo
|
3
|
+
class Organizations < Collection
|
4
|
+
def initialize(documents)
|
5
|
+
@documents = documents.map { |p| Organization.new(p) }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Organization
|
10
|
+
attr_reader :document
|
11
|
+
|
12
|
+
def initialize(document)
|
13
|
+
@document = document
|
14
|
+
document.each do |key, value|
|
15
|
+
define_singleton_method(key) { value }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def ==(other)
|
20
|
+
id == other.id
|
21
|
+
end
|
22
|
+
alias eql? ==
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Everypolitician
|
2
|
+
module Popolo
|
3
|
+
class People < Collection
|
4
|
+
def initialize(documents)
|
5
|
+
@documents = documents.map { |p| Person.new(p) }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Person
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
attr_reader :document
|
13
|
+
|
14
|
+
def initialize(document)
|
15
|
+
@document = document
|
16
|
+
document.each do |key, value|
|
17
|
+
define_singleton_method(key) { value }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def [](key)
|
22
|
+
document[key]
|
23
|
+
end
|
24
|
+
|
25
|
+
def key?(key)
|
26
|
+
document.key?(key)
|
27
|
+
end
|
28
|
+
|
29
|
+
def ==(other)
|
30
|
+
id == other.id
|
31
|
+
end
|
32
|
+
alias eql? ==
|
33
|
+
|
34
|
+
def links
|
35
|
+
document.fetch(:links, [])
|
36
|
+
end
|
37
|
+
|
38
|
+
def identifiers
|
39
|
+
document.fetch(:identifiers, [])
|
40
|
+
end
|
41
|
+
|
42
|
+
def identifier(scheme)
|
43
|
+
identifiers.find(->{{}}) { |i| i[:scheme] == scheme }[:identifier]
|
44
|
+
end
|
45
|
+
|
46
|
+
def email
|
47
|
+
self[:email]
|
48
|
+
end
|
49
|
+
|
50
|
+
def twitter
|
51
|
+
if key?(:contact_details)
|
52
|
+
if twitter_contact = self[:contact_details].find { |d| d[:type] == 'twitter' }
|
53
|
+
return twitter_contact[:value].strip
|
54
|
+
end
|
55
|
+
end
|
56
|
+
if key?(:links)
|
57
|
+
if twitter_link = self[:links].find { |d| d[:note][/twitter/i] }
|
58
|
+
return twitter_link[:url].strip
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def facebook
|
64
|
+
facebook_link = links.find { |d| d[:note] == 'facebook' }
|
65
|
+
facebook_link[:url] if facebook_link
|
66
|
+
end
|
67
|
+
|
68
|
+
def wikidata
|
69
|
+
identifier('wikidata')
|
70
|
+
end
|
71
|
+
|
72
|
+
def name_at(date)
|
73
|
+
return name unless key?(:other_names)
|
74
|
+
historic = other_names.find_all { |n| n.key?(:end_date) }
|
75
|
+
return name if historic.empty?
|
76
|
+
at_date = historic.find_all do |n|
|
77
|
+
n[:end_date] >= date && (n[:start_date] || '0000-00-00') <= date
|
78
|
+
end
|
79
|
+
return name if at_date.empty?
|
80
|
+
fail Error, "Too many names at #{date}: #{at_date}" if at_date.count > 1
|
81
|
+
at_date.first[:name]
|
82
|
+
end
|
83
|
+
|
84
|
+
def sort_name
|
85
|
+
name
|
86
|
+
end
|
87
|
+
|
88
|
+
def image
|
89
|
+
self[:image]
|
90
|
+
end
|
91
|
+
|
92
|
+
def gender
|
93
|
+
self[:gender]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: everypolitician-popolo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Mytton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,6 +75,7 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
77
|
- ".travis.yml"
|
78
|
+
- CHANGELOG.md
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE.txt
|
80
81
|
- README.md
|
@@ -83,6 +84,12 @@ files:
|
|
83
84
|
- bin/setup
|
84
85
|
- everypolitician-popolo.gemspec
|
85
86
|
- lib/everypolitician/popolo.rb
|
87
|
+
- lib/everypolitician/popolo/area.rb
|
88
|
+
- lib/everypolitician/popolo/collection.rb
|
89
|
+
- lib/everypolitician/popolo/event.rb
|
90
|
+
- lib/everypolitician/popolo/membership.rb
|
91
|
+
- lib/everypolitician/popolo/organization.rb
|
92
|
+
- lib/everypolitician/popolo/person.rb
|
86
93
|
- lib/everypolitician/popolo/version.rb
|
87
94
|
homepage: https://github.com/everypolitician/everypolitician-popolo
|
88
95
|
licenses:
|