everypolitician 0.4.0 → 0.5.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 +14 -0
- data/lib/everypolitician/version.rb +1 -1
- data/lib/everypolitician.rb +58 -41
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f5019b4f32557bebbe011a84ef324b25faedfa2
|
4
|
+
data.tar.gz: 721813c2e6d40c2714c742520ccb7e569174303c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f648d3407c0ffd02073518f016a2c5f5964a75d98fbcf18aff88dc39344ef6f929fc7c4be4dbd4c58d43511b0e1e78d674b2f830bba2df22b5f8c397526b2a7
|
7
|
+
data.tar.gz: ee7abeb616c7537c2b4111953051900ce4138369bd403b0f350eb5f1b844190f65f2bd0a3218c8f887cbceb375aff3dd801e7214ae3d65784dad8ed5b457ca8c
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,19 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
5
5
|
|
6
|
+
## [0.5.0] - 2016-01-27
|
7
|
+
|
8
|
+
### Added
|
9
|
+
|
10
|
+
- `Everypolitician.countries` method for returning an array of all countries.
|
11
|
+
- Find countries and legislatures by arbitrary attributes, e.g. `Everypolitician.country(code: 'AU')`
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
|
15
|
+
- We no longer use ruby metaprogramming to define the methods on `Country` and `Legislature`, they are now explicitly defined as properties and methods.
|
16
|
+
- `Legislature#popolo_url` now uses the `Legislature#sha` method rather than `master` in the raw url.
|
17
|
+
- `countries.json` is only loaded once, when it's first accessed. If you want to force a refetch then you can call `Everypolitician.countries = nil`.
|
18
|
+
|
6
19
|
## [0.4.0] - 2016-01-26
|
7
20
|
|
8
21
|
### Changed
|
@@ -33,3 +46,4 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
33
46
|
[0.2.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.1.0...v0.2.0
|
34
47
|
[0.3.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.2.0...v0.3.0
|
35
48
|
[0.4.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.3.0...v0.4.0
|
49
|
+
[0.5.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.4.0...v0.5.0
|
data/lib/everypolitician.rb
CHANGED
@@ -8,6 +8,7 @@ module Everypolitician
|
|
8
8
|
|
9
9
|
class << self
|
10
10
|
attr_writer :countries_json
|
11
|
+
attr_writer :countries
|
11
12
|
end
|
12
13
|
|
13
14
|
def self.countries_json
|
@@ -15,6 +16,14 @@ module Everypolitician
|
|
15
16
|
'everypolitician/everypolitician-data/master/countries.json'
|
16
17
|
end
|
17
18
|
|
19
|
+
def self.countries
|
20
|
+
@countries ||= begin
|
21
|
+
JSON.parse(open(countries_json).read, symbolize_names: true).map do |c|
|
22
|
+
Country.new(c)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
18
27
|
def self.country(slug)
|
19
28
|
Country.find(slug)
|
20
29
|
end
|
@@ -29,69 +38,77 @@ module Everypolitician
|
|
29
38
|
[country, legislature]
|
30
39
|
end
|
31
40
|
|
32
|
-
class
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
41
|
+
class Country
|
42
|
+
attr_reader :name
|
43
|
+
attr_reader :code
|
44
|
+
attr_reader :slug
|
45
|
+
attr_reader :raw_data
|
46
|
+
|
47
|
+
def self.find(query)
|
48
|
+
query = { slug: query } if query.is_a?(String)
|
49
|
+
country = Everypolitician.countries.find { |c| query.all? { |k, v| c[k] == v } }
|
50
|
+
fail Error, "Couldn't find country for query: #{query}" if country.nil?
|
51
|
+
new(country)
|
39
52
|
end
|
40
53
|
|
41
|
-
|
42
|
-
|
43
|
-
|
54
|
+
def initialize(country_data)
|
55
|
+
@name = country_data[:name]
|
56
|
+
@code = country_data[:code]
|
57
|
+
@slug = country_data[:slug]
|
58
|
+
@raw_data = country_data
|
44
59
|
end
|
45
|
-
end
|
46
60
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
61
|
+
def [](key)
|
62
|
+
raw_data[key]
|
63
|
+
end
|
64
|
+
|
65
|
+
def legislatures
|
66
|
+
@legislatures ||= @raw_data[:legislatures].map { |l| Legislature.new(l) }
|
52
67
|
end
|
53
68
|
|
54
|
-
def legislature(
|
55
|
-
|
69
|
+
def legislature(query)
|
70
|
+
query = { slug: query } if query.is_a?(String)
|
71
|
+
legislature = legislatures.find { |l| query.all? { |k, v| l.__send__(k) == v } }
|
56
72
|
fail Error, "Unknown legislature slug: #{slug}" if legislature.nil?
|
57
|
-
|
73
|
+
legislature
|
58
74
|
end
|
59
75
|
end
|
60
76
|
|
61
|
-
class Legislature
|
77
|
+
class Legislature
|
78
|
+
attr_reader :name
|
79
|
+
attr_reader :slug
|
80
|
+
attr_reader :lastmod
|
81
|
+
attr_reader :person_count
|
82
|
+
attr_reader :sha
|
83
|
+
attr_reader :raw_data
|
84
|
+
|
62
85
|
def self.find(country_slug, legislature_slug)
|
63
86
|
Country.find(country_slug).legislature(legislature_slug)
|
64
87
|
end
|
65
88
|
|
66
|
-
def
|
67
|
-
@
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
data
|
89
|
+
def initialize(legislature_data)
|
90
|
+
@name = legislature_data[:name]
|
91
|
+
@slug = legislature_data[:slug]
|
92
|
+
@lastmod = legislature_data[:lastmod]
|
93
|
+
@person_count = legislature_data[:person_count]
|
94
|
+
@sha = legislature_data[:sha]
|
95
|
+
@raw_data = legislature_data
|
74
96
|
end
|
75
|
-
end
|
76
|
-
|
77
|
-
class CountriesJson
|
78
|
-
include Enumerable
|
79
97
|
|
80
|
-
def
|
81
|
-
@
|
98
|
+
def popolo
|
99
|
+
@popolo ||= Everypolitician::Popolo.parse(open(popolo_url).read)
|
82
100
|
end
|
83
101
|
|
84
|
-
def
|
85
|
-
|
102
|
+
def popolo_url
|
103
|
+
@popolo_url ||= 'https://raw.githubusercontent.com/everypolitician' \
|
104
|
+
"/everypolitician-data/#{sha}/#{raw_data[:popolo]}"
|
86
105
|
end
|
87
106
|
|
88
|
-
|
89
|
-
|
90
|
-
def raw_json_string
|
91
|
-
@json ||= open(Everypolitician.countries_json).read
|
107
|
+
def legislative_periods
|
108
|
+
@legislative_periods ||= raw_data[:legislative_periods]
|
92
109
|
end
|
93
110
|
end
|
94
111
|
end
|
95
112
|
|
96
113
|
# Alternative constant name which is how it's usually capitalized in public copy.
|
97
|
-
EveryPolitician
|
114
|
+
EveryPolitician ||= Everypolitician
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: everypolitician
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.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-01-
|
11
|
+
date: 2016-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: everypolitician-popolo
|