govkit-ca 0.0.13 → 0.0.14

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: d0b61e37c1480b7a74fa8eee100aadc3b20ad9f8
4
- data.tar.gz: 21a6a467de791251785c1d1829634421eed5544d
3
+ metadata.gz: 552c21addb48040ade097636fd88ec1e60464d4b
4
+ data.tar.gz: 4a99ef183fefcddfdd06516aaaf968c8bcb55f03
5
5
  SHA512:
6
- metadata.gz: 5d77a599c818d350b7c27ac8626d5f82d26aae4add3c71294482156e3990838c81949fb36a318426016666206fc8c91122976973c4250caf992d3929c95ba045
7
- data.tar.gz: f7d0fedc2b0caf4f51c884d83ceff9d73921cc5a2e72e7256ed16f31cb2f4e8d55f41e282c259a203eb8be8d7a09279411362066b8d678ec1c24c770f2879dc7
6
+ metadata.gz: 964b1d7bfb550b526a8ed5cc7cd7f093aab3d2f096f182abe41a492e867fcf43ab31d115051f53968665da977cdc07abb95c41e50de1dc533f79b66be9d082ea
7
+ data.tar.gz: e9f9c2b9923969bbdf265a5fcef8d376058fcd87ed067e22068137a800f88786c5f7e0c09ba5da825cc3efc2c1c4e3efefffb90cd425b4f8a0caa97ff90c86e9
@@ -73,6 +73,17 @@ module GovKit
73
73
  request ['representative-sets', opts.delete(:representative_set)], opts
74
74
  end
75
75
 
76
+ # Get elections.
77
+ #
78
+ # @param [Hash] opts optional arguments
79
+ # @option opts [String] :election an election
80
+ # @option opts [Integer] :limit
81
+ # @option opts [Integer] :offset
82
+ # @see https://represent.opennorth.ca/api/#election
83
+ def elections(opts = {})
84
+ request ['elections', opts.delete(:election)], opts
85
+ end
86
+
76
87
  # Get representatives.
77
88
  #
78
89
  # @param [Hash] opts optional arguments
@@ -92,6 +103,25 @@ module GovKit
92
103
  request(['representatives', opts.delete(:representative_set)], opts)
93
104
  end
94
105
 
106
+ # Get candidates.
107
+ #
108
+ # @param [Hash] opts optional arguments
109
+ # @option opts [String] :electon an election
110
+ # @option opts [Array<Float>,String] :point a comma-separated latitude and longitude
111
+ # @option opts [Array<Strong>,String] :districts a comma-separated list of boundaries
112
+ # @option opts [Integer] :limit
113
+ # @option opts [Integer] :offset
114
+ # @see https://represent.opennorth.ca/api/#candidate
115
+ def candidates(opts = {})
116
+ if Array === opts[:point]
117
+ opts[:point] = opts[:point].join(',')
118
+ end
119
+ if Array === opts[:districts]
120
+ opts[:districts] = opts[:districts].join(',')
121
+ end
122
+ request(['candidates', opts.delete(:candidate)], opts)
123
+ end
124
+
95
125
  private
96
126
 
97
127
  def request(parts, opts)
@@ -1,5 +1,5 @@
1
1
  module GovKit
2
2
  module CA
3
- VERSION = "0.0.13"
3
+ VERSION = "0.0.14"
4
4
  end
5
5
  end
data/tasks/tasks.rb CHANGED
@@ -1,20 +1,7 @@
1
1
  require File.expand_path('../../lib/gov_kit-ca', __FILE__)
2
2
 
3
- # The following file maps 629,605 postal codes to electoral districts:
4
- # https://github.com/danielharan/canadian-postal-code-to-electoral-districts/raw/master/pc_edid.yml
5
- # However, it contains invalid postal codes, such as M5V1L6, and doesn't contain
6
- # every electoral district, such as 35061 (postal code L1H1X8).
7
- #
8
- # http://www.digital-copyright.ca/pcfrf/pcfrf.tgz contains
9
- # postal-code-for-districts.csv, "which is 308 postal codes that should map to
10
- # each of the 308 different electoral districts." However, six of them do not
11
- # exist (G0A2C0, J8M1R8, J0W1B0, J0B1H0, L0J1B0, N2A1A3), 14 are duplicate, and
12
- # the remaining 294 map to 246 electoral districts.
13
- #
14
- # The included tasks/postal-code-for-districts.csv covers 275 electoral
15
- # districts at the time of writing.
16
3
  desc "Picks the set cover for postal codes to electoral districts"
17
- task :trim_postal_codes, :file do |t,args|
4
+ task :set_cover, :file do |t,args|
18
5
  abort "Usage: rake #{t.name}[postal-code-for-districts.csv]" unless args[:file]
19
6
 
20
7
  # Get the electoral districts that each postal code covers
@@ -23,12 +10,13 @@ task :trim_postal_codes, :file do |t,args|
23
10
  postal_to_edid[postal_code] = GovKit::CA::PostalCode.find_electoral_districts_by_postal_code(postal_code)
24
11
  end
25
12
 
13
+ # Report how many electoral districts are covered.
26
14
  size = postal_to_edid.values.flatten.uniq.size
27
15
  if size < 308
28
- puts "Postal codes cover #{size} of 308 electoral districts."
16
+ puts "Postal codes cover #{size} electoral districts."
29
17
  end
30
18
 
31
- # Get the minimum number of postal codes to cover all electoral districts.
19
+ # Get the minimum number of postal codes to cover the electoral districts.
32
20
  # This is an instance of the set cover problem, which is NP-complete. Use the
33
21
  # greedy algorithm, which is the best-possible polynomial time approximation
34
22
  # algorithm for set cover. https://en.wikipedia.org/wiki/Set_cover_problem
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govkit-ca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Open North
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-28 00:00:00.000000000 Z
11
+ date: 2015-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -138,7 +138,6 @@ files:
138
138
  - LICENSE
139
139
  - README.md
140
140
  - Rakefile
141
- - USAGE
142
141
  - govkit-ca.gemspec
143
142
  - lib/gov_kit-ca.rb
144
143
  - lib/gov_kit-ca/postal_code.rb
data/USAGE DELETED
@@ -1 +0,0 @@
1
- See README.md for full usage details.