nl_api 1.0.0 → 1.1.0

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: d97c1ea88c6eb2592475755ae67a84785ad1bd74
4
- data.tar.gz: 5eaf71defddf43d66d8a8af0cf31e11941d459f0
3
+ metadata.gz: 35a62d543c02fe196a4f120689b5af59bf67e9fb
4
+ data.tar.gz: a2f585406841c936c16808ee9eb4df73f1072289
5
5
  SHA512:
6
- metadata.gz: eace9313b2353c36424af8be82ff88cc765c5b1c9ae0879d7f89bf09895d4f10e555121b835d68135660f5bb193dd8e3e023c9b973a636a0b27f00a7ea7b4cf8
7
- data.tar.gz: 0a27e52885f00ce66b12ec8ae1f743a765750bcd2e4f6c29a1dff2bf3a9cbbccdea003594b08ddc2c82193623d49f9dc2a9d9c5055c32a5a7d5092ab63badfd2
6
+ metadata.gz: 892924aa185379fe44533207bc5e3b37c8d8336e7fa152e2af8924049612b7e11246542ace5df3c974c37b4ad1569c825a65ded30e7c610a35b086ae1f9ca929
7
+ data.tar.gz: 7e6b2201cb49c20cf63caaea88fd100e728d34e4349ba952179bba6eb01502f1f769f36606f6554592308912f7b4611e509d7075259bb481143538d432a2baa9
data/README.md CHANGED
@@ -18,12 +18,43 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install nl_api
20
20
 
21
+ ## Usage
22
+
23
+ Find municipalities by name:
24
+
25
+ ```ruby
26
+ # Find municipality
27
+ municipality = NlApi::Municipality.find_by(name: 'Rotterdam')
28
+
29
+ # Get province of municipality
30
+ province = municipality.province
31
+
32
+ # Get municipalities in the province
33
+ province.municipalities
34
+ # [#<NlApi::Municipality:0x007fa8fc2247a8 @code=482, @name="Alblasserdam", @province_name="Zuid-Holland", @province_code=28>, ...]
35
+
36
+ # Get the municipalities this one is the result of
37
+ municipality.merged_municipalities
38
+ # Result: [#<NlApi::HistoricMunicipality:0x007fa8fbc37ed0 @code=1037, @name="Charlois", @code_after_merge=599>, ...]
39
+
40
+ # Find history municipality
41
+ historic_municipality = NlApi::HistoricMunicipality.find_by(name: 'Overschie')
42
+ historic_municipality.municipality_after_merge
43
+ # Result: #<NlApi::Municipality:0x007fa8fc1cf5a0 @code=599, @name="Rotterdam", @province_name="Zuid-Holland", @province_code=28>
44
+
45
+ ```
46
+
47
+
21
48
  ## Development
22
49
 
23
50
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
51
 
25
52
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
53
 
54
+ ## Changelog
55
+
56
+ - v1.1 Add class to deal with no longer existing municipalities
57
+ - v1.0 first release
27
58
  ## Contributing
28
59
 
29
60
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nl_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/lib/nl_api.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "nl_api/version"
2
+ require "nl_api/historic_municipality"
2
3
  require "nl_api/municipality"
3
4
  require "nl_api/province"
4
5
  module NlApi
@@ -0,0 +1,68 @@
1
+ class NlApi::HistoricMunicipality
2
+ attr_reader :code, :name, :code_after_merge
3
+
4
+ def initialize(attributes)
5
+ @code = attributes[:code]
6
+ @name = attributes[:name]
7
+ @code_after_merge = attributes[:code_after_merge]
8
+ end
9
+
10
+ def province
11
+ municipality_after_merge.province
12
+ end
13
+
14
+ def municipality_after_merge
15
+ has_merged? ? NlApi::Municipality.find_by(code: code_after_merge) : nil
16
+ end
17
+
18
+ def has_merged?
19
+ !!code_after_merge
20
+ end
21
+
22
+ class << self
23
+ include Enumerable
24
+ require 'csv'
25
+
26
+ attr_writer :filename
27
+
28
+ def filename
29
+ @filename ||= '../../data/BAG_gemeententabel.csv'
30
+ end
31
+
32
+ def path
33
+ File.join(File.dirname(File.expand_path(__FILE__)), filename)
34
+ end
35
+
36
+ def read_csv
37
+ @store ||= CSV.read(path, headers: true, col_sep: ',').map{ |line|
38
+ NlApi::HistoricMunicipality.new(
39
+ code: line[0].to_i,
40
+ name: line[1],
41
+ code_after_merge: line[2].to_i
42
+ ) }
43
+ end
44
+
45
+ def all
46
+ @all ||= read_csv
47
+ end
48
+
49
+ def each(&block)
50
+ all.each(&block)
51
+ self
52
+ end
53
+
54
+ def find_by(where)
55
+ field = where.keys.first
56
+ value = where.values.first
57
+
58
+ find{ |i| i.send(field.to_sym) == value }
59
+ end
60
+
61
+ def find_all_by(where)
62
+ field = where.keys.first
63
+ value = where.values.first
64
+
65
+ find_all{ |i| i.send(field.to_sym) == value }
66
+ end
67
+ end
68
+ end
@@ -12,6 +12,10 @@ class NlApi::Municipality
12
12
  self.class.provinces[province_code] ||= NlApi::Province.new(province_code, province_name)
13
13
  end
14
14
 
15
+ def merged_municipalities
16
+ NlApi::HistoricMunicipality.find_all_by(code_after_merge: code)
17
+ end
18
+
15
19
  class << self
16
20
  include Enumerable
17
21
  require 'csv'
@@ -1,3 +1,3 @@
1
1
  module NlApi
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nl_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maarten van Vliet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-24 00:00:00.000000000 Z
11
+ date: 2016-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,6 +72,7 @@ files:
72
72
  - data/BAG_gemeententabel.csv
73
73
  - data/gemeentenalfabetisch2016.csv
74
74
  - lib/nl_api.rb
75
+ - lib/nl_api/historic_municipality.rb
75
76
  - lib/nl_api/municipality.rb
76
77
  - lib/nl_api/province.rb
77
78
  - lib/nl_api/version.rb
@@ -101,4 +102,3 @@ signing_key:
101
102
  specification_version: 4
102
103
  summary: Simple wrapper for CBS municipality data
103
104
  test_files: []
104
- has_rdoc: