everypolitician 0.6.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70bd3480dd8c6504c3c21701dd0c705f75346f5b
4
- data.tar.gz: bc7a9c59bdef1a226ca281b5dc5fb8b322a6f034
3
+ metadata.gz: 049d21610458ca4158fbc452bf99fe57b88443ff
4
+ data.tar.gz: a4c2bc68a937231ac8a6758f0a46ec1a32e4c7b5
5
5
  SHA512:
6
- metadata.gz: 8cf500912b6c6541ef12d35ee1f702082bef9c6bf1fa70fa466ec3ba0e21612f130ecfdd8f749672f2192806eae0d03f8208d899b0ee4905304d065a385c2472
7
- data.tar.gz: 3d0c46815af909d5986eeb3c947cb34b2edfb1a636ea05d9d62b87f3a0ea3a3c16bcbee76673f02d7d5895a34b4b2b9a6ea30734e7a4b485b9a09b4c346dbd03
6
+ metadata.gz: ba198093b9ac78b87a542c8d601634b8619732d64c16bf51f831498287e501832b72065f2d05ff162e3bd611c99e57662772d7fb98347d0fd8398bfa72d762c2
7
+ data.tar.gz: fe87ab19b2fc7bdafb30e38a7ebc120c402902a47ab85d75026c49a3501f140a10a1d5c9e04ef955fa4e3e62dddb6fcdba35ab611f305f302ec0bef08e50d313
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .rubocop-https---raw-githubusercontent-com-everypolitician-everypolitician-data-master--rubocop-base-yml
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/everypolitician/everypolitician-data/master/.rubocop_base.yml
3
+ - .rubocop_todo.yml
4
+
5
+ # We're OK with a class of EveryPolitician
6
+ Style/ConstantName:
7
+ Exclude:
8
+ - 'lib/everypolitician.rb'
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,27 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-08-15 19:54:18 +0100 using RuboCop version 0.42.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ Metrics/AbcSize:
11
+ Max: 24
12
+
13
+ # Offense count: 1
14
+ # Configuration parameters: CountComments.
15
+ Metrics/ClassLength:
16
+ Max: 152
17
+
18
+ # Offense count: 20
19
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
20
+ # URISchemes: http, https
21
+ Metrics/LineLength:
22
+ Max: 144
23
+
24
+ # Offense count: 1
25
+ # Configuration parameters: CountComments.
26
+ Metrics/MethodLength:
27
+ Max: 11
data/.travis.yml CHANGED
@@ -1,5 +1,9 @@
1
1
  language: ruby
2
2
  cache: bundler
3
+ sudo: false
4
+ script:
5
+ - bundle exec rake test
6
+ - bundle exec rake rubocop
3
7
  rvm:
4
8
  - 2.0.0
5
9
  - 2.1.7
data/CHANGELOG.md CHANGED
@@ -3,6 +3,61 @@
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
+ ## Unreleased
7
+
8
+ ## [0.13.0] - 2016-08-18
9
+
10
+ ### Added
11
+
12
+ - There is now an `Everypolitician::Index` class which can be instantiated with
13
+ a url pointing to a `countries.json` file. This replaces the need to globally
14
+ set a url via `Everypolitician.countries_json=`.
15
+ - You can access a country via the `Everypolitician::Index#country` method, which takes a (case-insensitive) slug for the country.
16
+ - You can get a list of all countries via the `Everypolitician::Index#countries` method.
17
+
18
+ ## [0.12.0] - 2016-08-16
19
+
20
+ ### Changed
21
+
22
+ - Trying to find a non-existent country or legislature now returns `nil` rather
23
+ than raising an exception.
24
+
25
+ ## [0.11.0] - 2016-08-07
26
+
27
+ ### Added
28
+
29
+ - Searches by slug for a Country or a Legislature are now case insensitive
30
+
31
+ ## [0.10.0] - 2016-08-04
32
+
33
+ ### Changed
34
+
35
+ - The code now uses the `popolo_url` field from the data, so the url
36
+ host has changed from `raw.githubusercontent.com` to `cdn.rawgit.com`.
37
+
38
+ ## [0.9.0] - 2016-07-28
39
+
40
+ ### Added
41
+
42
+ - The`Legislature#lastmod` attribute now returns a Time object instead of just
43
+ a string with the time in seconds.
44
+
45
+ ## [0.8.0] - 2016-07-26
46
+
47
+ ### Added
48
+
49
+ - There is now a `Legislature#statement_count` method for returning the
50
+ statement count of a legislature, which corresponds to the `statement_count`
51
+ field in the legislatures of a country coming from the data in `countries_json`.
52
+
53
+ ## [0.7.0] - 2016-06-21
54
+
55
+ ### Added
56
+
57
+ - There is now a `Legislature.directory` method for returning the
58
+ directory path under `data` where the raw data on everypolician data
59
+ can be found
60
+
6
61
  ## [0.6.1] - 2016-05-23
7
62
 
8
63
  ## Fixed
@@ -62,3 +117,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
62
117
  [0.5.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.4.0...v0.5.0
63
118
  [0.6.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.5.0...v0.6.0
64
119
  [0.6.1]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.6.0...v0.6.1
120
+ [0.7.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.6.1...v0.7.0
121
+ [0.8.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.7.0...v0.8.0
122
+ [0.9.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.8.0...v0.9.0
123
+ [0.10.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.9.0...v0.10.0
124
+ [0.11.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.10.0...v0.11.0
125
+ [0.12.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.11.0...v0.12.0
126
+ [0.13.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.12.0...v0.13.0
data/README.md CHANGED
@@ -20,19 +20,39 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
+ Use as shown below, passing the `:slug` of the country to the `country` method, and the `:slug` of the legislature to the `legislature` method. Examples:
24
+
23
25
  ```ruby
24
26
  require 'everypolitician'
25
27
 
26
- australia = Everypolitician.country('Australia')
28
+ australia = Everypolitician::Index.new.country('Australia')
27
29
  australia.code # => "AU"
28
30
  senate = australia.legislature('Senate')
29
31
  senate.popolo # => #<Everypolitician::Popolo::JSON>
32
+
33
+ united_kingdom = Everypolitician::Index.new.country('UK')
34
+ house_of_commons = united_kingdom.legislature('Commons')
35
+
36
+ american_samoa = Everypolitician::Index.new.country('American-Samoa')
37
+ house_of_representatives = american_samoa.legislature('House')
38
+
39
+ united_arab_emirates = Everypolitician::Index.new.country('United-Arab-Emirates')
40
+ national_council = united_arab_emirates.legislature('Federal-National-Council')
41
+
42
+ algeria = Everypolitician::Index.new.country('Algeria')
43
+ national_assembly = algeria.legislature('Majlis')
44
+
45
+ # Iterate though all known countries
46
+ Everypolitician::Index.new.countries do |country|
47
+ puts "#{country.name} has #{country.legislatures.size} legislature(s)"
48
+ end
30
49
  ```
31
50
 
32
- If you want to point at a different `countries.json`, e.g. a local path or a different url, you can set it like this:
51
+ If you want to point at a different version of `countries.json` you can supply an
52
+ `index_url` option to `Everypolitician::Index.new`.
33
53
 
34
54
  ```ruby
35
- Everypolitician.countries_json = 'path/to/local/countries.json'
55
+ Everypolitician::Index.new(index_url: 'https://cdn.rawgit.com/everypolitician/everypolitician-data/080cb46/countries.json')
36
56
  ```
37
57
 
38
58
  ## Development
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
+ require 'rubocop/rake_task'
3
4
 
4
5
  Rake::TestTask.new(:test) do |t|
5
6
  t.libs << 'test'
@@ -7,4 +8,6 @@ Rake::TestTask.new(:test) do |t|
7
8
  t.test_files = FileList['test/**/*_test.rb']
8
9
  end
9
10
 
11
+ RuboCop::RakeTask.new
12
+
10
13
  task default: :test
@@ -22,8 +22,9 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency 'bundler', '~> 1.10'
24
24
  spec.add_development_dependency 'rake', '~> 10.0'
25
- spec.add_development_dependency 'minitest'
26
- spec.add_development_dependency 'pry'
27
- spec.add_development_dependency 'vcr'
28
- spec.add_development_dependency 'webmock'
25
+ spec.add_development_dependency 'minitest', '~> 5.9.0'
26
+ spec.add_development_dependency 'pry', '~> 0.10.4'
27
+ spec.add_development_dependency 'rubocop', '~> 0.42.0'
28
+ spec.add_development_dependency 'vcr', '~> 3.0.3'
29
+ spec.add_development_dependency 'webmock', '~> 2.0.3'
29
30
  end
@@ -5,8 +5,6 @@ require 'everypolitician/popolo'
5
5
  require 'csv'
6
6
 
7
7
  module Everypolitician
8
- class Error < StandardError; end
9
-
10
8
  class << self
11
9
  attr_writer :countries_json
12
10
  attr_writer :countries
@@ -39,6 +37,35 @@ module Everypolitician
39
37
  [country, legislature]
40
38
  end
41
39
 
40
+ class Index
41
+ DEFAULT_INDEX_URL = 'https://raw.githubusercontent.com/' \
42
+ 'everypolitician/everypolitician-data/master/countries.json'.freeze
43
+
44
+ attr_reader :index_url
45
+
46
+ def initialize(index_url: DEFAULT_INDEX_URL)
47
+ @index_url = index_url
48
+ end
49
+
50
+ def country(slug)
51
+ country_index[slug.to_s.downcase]
52
+ end
53
+
54
+ def countries
55
+ @countries ||= begin
56
+ JSON.parse(open(index_url).read, symbolize_names: true).map do |c|
57
+ Country.new(c)
58
+ end
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def country_index
65
+ @country_index ||= Hash[countries.map { |c| [c.slug.downcase, c] }]
66
+ end
67
+ end
68
+
42
69
  class Country
43
70
  attr_reader :name
44
71
  attr_reader :code
@@ -47,8 +74,10 @@ module Everypolitician
47
74
 
48
75
  def self.find(query)
49
76
  query = { slug: query } if query.is_a?(String)
50
- country = Everypolitician.countries.find { |c| query.all? { |k, v| c[k] == v } }
51
- fail Error, "Couldn't find country for query: #{query}" if country.nil?
77
+ country = Everypolitician.countries.find do |c|
78
+ query.all? { |k, v| c[k].to_s.downcase == v.to_s.downcase }
79
+ end
80
+ return if country.nil?
52
81
  new(country)
53
82
  end
54
83
 
@@ -69,31 +98,36 @@ module Everypolitician
69
98
 
70
99
  def legislature(query)
71
100
  query = { slug: query } if query.is_a?(String)
72
- legislature = legislatures.find { |l| query.all? { |k, v| l.__send__(k) == v } }
73
- fail Error, "Unknown legislature: #{query}" if legislature.nil?
74
- legislature
101
+ legislatures.find do |l|
102
+ query.all? { |k, v| l.__send__(k).to_s.downcase == v.to_s.downcase }
103
+ end
75
104
  end
76
105
  end
77
106
 
78
107
  class Legislature
79
108
  attr_reader :name
80
109
  attr_reader :slug
81
- attr_reader :lastmod
110
+ attr_reader :lastmod_str
82
111
  attr_reader :person_count
83
112
  attr_reader :sha
84
113
  attr_reader :country
85
114
  attr_reader :raw_data
115
+ attr_reader :statement_count
116
+ attr_reader :popolo_url
86
117
 
87
118
  def self.find(country_slug, legislature_slug)
88
- Country.find(country_slug).legislature(legislature_slug)
119
+ country = Country.find(country_slug)
120
+ country && country.legislature(legislature_slug)
89
121
  end
90
122
 
91
123
  def initialize(legislature_data, country)
92
124
  @name = legislature_data[:name]
93
125
  @slug = legislature_data[:slug]
94
- @lastmod = legislature_data[:lastmod]
126
+ @lastmod_str = legislature_data[:lastmod]
95
127
  @person_count = legislature_data[:person_count]
96
128
  @sha = legislature_data[:sha]
129
+ @statement_count = legislature_data[:statement_count]
130
+ @popolo_url = legislature_data[:popolo_url]
97
131
  @raw_data = legislature_data
98
132
  @country = country
99
133
  end
@@ -102,16 +136,24 @@ module Everypolitician
102
136
  @popolo ||= Everypolitician::Popolo.parse(open(popolo_url).read)
103
137
  end
104
138
 
105
- def popolo_url
106
- @popolo_url ||= 'https://raw.githubusercontent.com/everypolitician' \
107
- "/everypolitician-data/#{sha}/#{raw_data[:popolo]}"
108
- end
109
-
110
139
  def legislative_periods
111
140
  @legislative_periods ||= raw_data[:legislative_periods].map do |lp|
112
- LegislativePeriod.new(lp, self, self.country)
141
+ LegislativePeriod.new(lp, self, country)
113
142
  end
114
143
  end
144
+
145
+ def directory
146
+ @directory = raw_data[:sources_directory].split('/')[1, 2].join('/')
147
+ end
148
+
149
+ def self.from_sources_dir(dir)
150
+ @index_by_sources ||= EveryPolitician.countries.map(&:legislatures).flatten.group_by(&:directory)
151
+ @index_by_sources[dir][0]
152
+ end
153
+
154
+ def lastmod
155
+ Time.at(lastmod_str.to_i).gmtime
156
+ end
115
157
  end
116
158
 
117
159
  class LegislativePeriod
@@ -1,3 +1,3 @@
1
1
  module Everypolitician
2
- VERSION = '0.6.1'
2
+ VERSION = '0.13.0'.freeze
3
3
  end
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.6.1
4
+ version: 0.13.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-05-23 00:00:00.000000000 Z
11
+ date: 2016-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: everypolitician-popolo
@@ -56,58 +56,72 @@ dependencies:
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 5.9.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 5.9.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.10.4
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.10.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.42.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.42.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: vcr
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - ">="
101
+ - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0'
103
+ version: 3.0.3
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - ">="
108
+ - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0'
110
+ version: 3.0.3
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: webmock
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ">="
115
+ - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '0'
117
+ version: 2.0.3
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - ">="
122
+ - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '0'
124
+ version: 2.0.3
111
125
  description:
112
126
  email:
113
127
  - chrismytton@gmail.com
@@ -116,6 +130,8 @@ extensions: []
116
130
  extra_rdoc_files: []
117
131
  files:
118
132
  - ".gitignore"
133
+ - ".rubocop.yml"
134
+ - ".rubocop_todo.yml"
119
135
  - ".travis.yml"
120
136
  - CHANGELOG.md
121
137
  - Gemfile