nl_api 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -0
- data/lib/nl_api.rb +1 -0
- data/lib/nl_api/historic_municipality.rb +68 -0
- data/lib/nl_api/municipality.rb +4 -0
- data/lib/nl_api/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35a62d543c02fe196a4f120689b5af59bf67e9fb
|
4
|
+
data.tar.gz: a2f585406841c936c16808ee9eb4df73f1072289
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
@@ -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
|
data/lib/nl_api/municipality.rb
CHANGED
@@ -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'
|
data/lib/nl_api/version.rb
CHANGED
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.
|
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-
|
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:
|