statbank_denmark 0.0.2 → 0.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 +4 -4
- data/CHANGELOG +44 -0
- data/README.md +31 -0
- data/lib/StatBankDenmark/Tables.rb +95 -0
- data/lib/StatBankDenmark/VERSION.rb +1 -1
- data/lib/StatBankDenmark.rb +1 -0
- data/statbank_denmark.gemspec +1 -2
- data/test/StatBankDenmark/Tables_test.rb +73 -0
- metadata +5 -3
- data/CHANGELOG.txt +0 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 183b691efeb61af245aaaddb2f7e736c4509f7a99619447b46baec3c5b318dcb
|
|
4
|
+
data.tar.gz: c1b14881d01331e323f354c7f809e03370b5bbb7e819dc8fc27ba9764a2a10e1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: efccb6b847ccf3d941baa91107d3b02f9afc88ca98cf5cefd22460833f1eb9858eaa7ae34a84a95676d626662604855b4f572f15050a19bcde74861ade568223
|
|
7
|
+
data.tar.gz: dd6d92d90f93ab9ade68bf709072984f827d1c885fb80523023cd6e6a4fbfd76415265c7ba44edc7e8994a10cbf4c11493b039e8d76d651f86819eab2f7f69e6
|
data/CHANGELOG
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# statbank_denmark/CHANGELOG
|
|
2
|
+
|
|
3
|
+
## 20260928
|
|
4
|
+
|
|
5
|
+
0.1.0: + StatBankDenmark::Tables
|
|
6
|
+
|
|
7
|
+
1. + StatBankDenmark::Tables: six crime and population tables and their dimensions, taken from table_info.
|
|
8
|
+
2. + StatBankDenmark::Tables.[], .ids, .dimensions, and .column.
|
|
9
|
+
3. + test/StatBankDenmark/Tables_test.rb
|
|
10
|
+
4. ~ lib/StatBankDenmark.rb: + require_relative './StatBankDenmark/Tables'
|
|
11
|
+
5. ~ statbank_denmark.gemspec: - spec.date
|
|
12
|
+
6. ~ StatBankDenmark::VERSION: /0.0.2/0.1.0/
|
|
13
|
+
|
|
14
|
+
0.0.2: ~ test/StatBankDenmark_test.rb: /test_helper/helper/
|
|
15
|
+
|
|
16
|
+
1. It named a file which does not exist, so this test had never run.
|
|
17
|
+
2. ~ StatBankDenmark::VERSION: /0.0.1/0.0.2/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## 20260822
|
|
21
|
+
|
|
22
|
+
0.0.1: + LICENSE
|
|
23
|
+
|
|
24
|
+
1. + LICENSE
|
|
25
|
+
2. ~ statbank_denmark.gemspec: + 'LICENSE'
|
|
26
|
+
3. ~ StatBankDenmark::VERSION: /0.0.0/0.0.1/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## 20250908
|
|
30
|
+
|
|
31
|
+
0.0.0: + /subjects, /tables, /tableinfo, and /data endpoints; and provide basic table searching.
|
|
32
|
+
|
|
33
|
+
1. + StatBankDenmark
|
|
34
|
+
2. + StatBankDenmark.subjects: A convenience method StatBankDenmark::Client#subjects.
|
|
35
|
+
3. + StatBankDenmark.tables: A convenience method StatBankDenmark::Client#tables.
|
|
36
|
+
4. + StatBankDenmark.table_info: A convenience method StatBankDenmark::Client#table_info.
|
|
37
|
+
5. + StatBankDenmark.data: A convenience method StatBankDenmark::Client#data.
|
|
38
|
+
6. + StatBankDenmark.search: A convenience method StatBankDenmark::Client#search.
|
|
39
|
+
7. + StatBankDenmark::Client
|
|
40
|
+
8. + StatBankDenmark::Client#subjects: /subjects endpoint
|
|
41
|
+
9. + StatBankDenmark::Client#tables: /tables endpoint
|
|
42
|
+
10. + StatBankDenmark::Client#table_info: /tableinfo endpoint
|
|
43
|
+
11. + StatBankDenmark::Client#data: /data endpoint
|
|
44
|
+
12. + StatBankDenmark::Client.search: Search all tables by string.
|
data/README.md
CHANGED
|
@@ -114,6 +114,37 @@ client.search('befolkning', lang: 'da') # lang: 'da'
|
|
|
114
114
|
client.search('BEFOLKNING', lang: 'da') # case insensitive search and lang: 'da'
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
+
### Table metadata
|
|
118
|
+
|
|
119
|
+
Six crime and population tables and their dimensions. `table_info` answers with
|
|
120
|
+
the values a dimension takes; this is a starting point for choosing which table
|
|
121
|
+
to ask.
|
|
122
|
+
|
|
123
|
+
```ruby
|
|
124
|
+
# Which tables are described here
|
|
125
|
+
StatBankDenmark::Tables.ids # => ["STRAF42", "STRAF10", "STRAFNA3", "FOLK1C", "FOLK2", "VAN66"]
|
|
126
|
+
|
|
127
|
+
# What a table is
|
|
128
|
+
StatBankDenmark::Tables['STRAF42'][:name] # => "Decisions, total"
|
|
129
|
+
StatBankDenmark::Tables['straf42'] # the id is taken in any case
|
|
130
|
+
|
|
131
|
+
# Every dimension of a table, named as the API names them
|
|
132
|
+
StatBankDenmark::Tables.dimensions('STRAF10').keys # => ["OVERTRÆD", "Tid"]
|
|
133
|
+
|
|
134
|
+
# What a dimension is called once the row is read as Ruby
|
|
135
|
+
StatBankDenmark::Tables.column('STRAF42', 'HERKOMST1') # => :national_origin
|
|
136
|
+
StatBankDenmark::Tables.column('FOLK2', 'STATSB') # => :citizenship
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Two things are worth knowing before choosing a table. `HERKOMST1` in `STRAF42`
|
|
140
|
+
and `HERKOMST` in `FOLK1C` and `FOLK2` are not two spellings of one dimension —
|
|
141
|
+
the first is citizenship, the second residence — so they do not substitute. And
|
|
142
|
+
`STRAFNA3` and `VAN66` have no ancestry dimension at all; `IELAND`, country of
|
|
143
|
+
origin, is the nearest either offers.
|
|
144
|
+
|
|
145
|
+
Asking with a dimension a table has not got answers 400, which reads as the table
|
|
146
|
+
being broken when it is the request that is wrong.
|
|
147
|
+
|
|
117
148
|
## Contributing
|
|
118
149
|
|
|
119
150
|
1. Fork it (https://github.com/thoran/statbank_denmark/fork)
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# lib/StatBankDenmark/Tables.rb
|
|
2
|
+
# StatBankDenmark::Tables
|
|
3
|
+
|
|
4
|
+
# Six crime and population tables and their dimensions, taken from table_info on
|
|
5
|
+
# 20260928. The values each dimension takes are not here: 1693 of them across
|
|
6
|
+
# these six, Tid grows every year, and table_info answers with them already.
|
|
7
|
+
#
|
|
8
|
+
# Two things worth knowing before choosing a table. HERKOMST1 in STRAF42 and
|
|
9
|
+
# HERKOMST in FOLK1C and FOLK2 are not two spellings of one dimension: the first
|
|
10
|
+
# is citizenship and the second residence, so they do not substitute. And
|
|
11
|
+
# STRAFNA3 and VAN66 have no ancestry dimension at all — IELAND, country of
|
|
12
|
+
# origin, is the nearest either offers.
|
|
13
|
+
|
|
14
|
+
module StatBankDenmark
|
|
15
|
+
module Tables
|
|
16
|
+
TABLES = {
|
|
17
|
+
'STRAF42' => {
|
|
18
|
+
name: 'Decisions, total',
|
|
19
|
+
dimensions: {
|
|
20
|
+
'HERKOMST1' => {name: 'national origin', as: :national_origin},
|
|
21
|
+
'OVERTRÆD' => {name: 'type of offence', as: :type_of_offence},
|
|
22
|
+
'AFGØRELSE' => {name: 'type of decision', as: :type_of_decision},
|
|
23
|
+
'ALDER' => {name: 'age', as: :age},
|
|
24
|
+
'KØN' => {name: 'sex', as: :sex},
|
|
25
|
+
'Tid' => {name: 'time', as: :time, time: true},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
'STRAF10' => {
|
|
29
|
+
name: 'Reported criminal offences',
|
|
30
|
+
dimensions: {
|
|
31
|
+
'OVERTRÆD' => {name: 'type of offence', as: :type_of_offence},
|
|
32
|
+
'Tid' => {name: 'time', as: :time, time: true},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
'STRAFNA3' => {
|
|
36
|
+
name: 'Persons guilty in crimes',
|
|
37
|
+
dimensions: {
|
|
38
|
+
'KOEN' => {name: 'sex', as: :sex},
|
|
39
|
+
'ALDER' => {name: 'age', as: :age},
|
|
40
|
+
'IELAND' => {name: 'country of origin', as: :country_of_origin},
|
|
41
|
+
'Tid' => {name: 'time', as: :time, time: true},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
'FOLK1C' => {
|
|
45
|
+
name: 'Population at the first day of the quarter',
|
|
46
|
+
dimensions: {
|
|
47
|
+
'OMRÅDE' => {name: 'region', as: :region},
|
|
48
|
+
'KØN' => {name: 'sex', as: :sex},
|
|
49
|
+
'ALDER' => {name: 'age', as: :age},
|
|
50
|
+
'HERKOMST' => {name: 'ancestry', as: :ancestry},
|
|
51
|
+
'IELAND' => {name: 'country of origin', as: :country_of_origin},
|
|
52
|
+
'Tid' => {name: 'time', as: :time, time: true},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
'FOLK2' => {
|
|
56
|
+
name: 'Population 1. January',
|
|
57
|
+
dimensions: {
|
|
58
|
+
'ALDER' => {name: 'age', as: :age},
|
|
59
|
+
'KØN' => {name: 'sex', as: :sex},
|
|
60
|
+
'HERKOMST' => {name: 'ancestry', as: :ancestry},
|
|
61
|
+
'STATSB' => {name: 'citizenship', as: :citizenship},
|
|
62
|
+
'IELAND' => {name: 'country of origin', as: :country_of_origin},
|
|
63
|
+
'Tid' => {name: 'time', as: :time, time: true},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
'VAN66' => {
|
|
67
|
+
name: 'Residence permits (year)',
|
|
68
|
+
dimensions: {
|
|
69
|
+
'STATSB' => {name: 'citizenship', as: :citizenship},
|
|
70
|
+
'OPHOLD' => {name: 'residence permit', as: :residence_permit},
|
|
71
|
+
'Tid' => {name: 'time', as: :time, time: true},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
class << self
|
|
77
|
+
def [](table_id)
|
|
78
|
+
TABLES[table_id.to_s.upcase]
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def ids
|
|
82
|
+
TABLES.keys
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def dimensions(table_id)
|
|
86
|
+
self[table_id]&.fetch(:dimensions, nil)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# What a dimension is called once the row is read as Ruby.
|
|
90
|
+
def column(table_id, dimension)
|
|
91
|
+
dimensions(table_id)&.dig(dimension.to_s, :as)
|
|
92
|
+
end
|
|
93
|
+
end # class << self
|
|
94
|
+
end
|
|
95
|
+
end
|
data/lib/StatBankDenmark.rb
CHANGED
data/statbank_denmark.gemspec
CHANGED
|
@@ -4,7 +4,6 @@ Gem::Specification.new do |spec|
|
|
|
4
4
|
spec.name = 'statbank_denmark'
|
|
5
5
|
|
|
6
6
|
spec.version = StatBankDenmark::VERSION
|
|
7
|
-
spec.date = '2025-09-09'
|
|
8
7
|
|
|
9
8
|
spec.summary = "A Ruby client for the StatBank Denmark API."
|
|
10
9
|
spec.description = "A Ruby client for easy access to StatBank; Denmark's official statistics (Danmarks Statistik) REST API."
|
|
@@ -17,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
|
17
16
|
spec.required_ruby_version = '>= 2.7'
|
|
18
17
|
|
|
19
18
|
spec.files = [
|
|
20
|
-
'CHANGELOG
|
|
19
|
+
'CHANGELOG',
|
|
21
20
|
'Gemfile',
|
|
22
21
|
'LICENSE',
|
|
23
22
|
'README.md',
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# test/StatBankDenmark/Tables_test.rb
|
|
2
|
+
|
|
3
|
+
require_relative '../helper'
|
|
4
|
+
|
|
5
|
+
describe StatBankDenmark::Tables do
|
|
6
|
+
context "[]" do
|
|
7
|
+
it "answers a table by its id" do
|
|
8
|
+
_(StatBankDenmark::Tables['STRAF42'][:name]).must_equal("Decisions, total")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "takes the id in any case, the API naming them in capitals" do
|
|
12
|
+
_(StatBankDenmark::Tables['straf42']).must_equal(StatBankDenmark::Tables['STRAF42'])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "answers nil for one it does not know" do
|
|
16
|
+
_(StatBankDenmark::Tables['NOSUCHTABLE']).must_be_nil
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context "dimensions" do
|
|
21
|
+
it "names them as the API does" do
|
|
22
|
+
_(StatBankDenmark::Tables.dimensions('STRAF10').keys).must_equal(%w{OVERTRÆD Tid})
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "marks the time dimension, there being one per table" do
|
|
26
|
+
StatBankDenmark::Tables.ids.each do |id|
|
|
27
|
+
timed = StatBankDenmark::Tables.dimensions(id).select{|_, detail| detail[:time]}
|
|
28
|
+
_(timed.keys).must_equal(%w{Tid}, "#{id} does not mark exactly one time dimension")
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context "column" do
|
|
34
|
+
it "answers what a dimension is called once read as Ruby" do
|
|
35
|
+
_(StatBankDenmark::Tables.column('STRAF42', 'HERKOMST1')).must_equal(:national_origin)
|
|
36
|
+
_(StatBankDenmark::Tables.column('FOLK2', 'STATSB')).must_equal(:citizenship)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "answers nil for a dimension the table has not got" do
|
|
40
|
+
_(StatBankDenmark::Tables.column('VAN66', 'HERKOMST1')).must_be_nil
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# The header comment says these disagreements are real. Were the API to settle
|
|
45
|
+
# them, these would fail and the comment would want deleting rather than keeping.
|
|
46
|
+
context "the disagreements the header records" do
|
|
47
|
+
it "spells ancestry differently in the crime and population tables" do
|
|
48
|
+
_(StatBankDenmark::Tables.dimensions('STRAF42')).must_include('HERKOMST1')
|
|
49
|
+
_(StatBankDenmark::Tables.dimensions('FOLK1C')).must_include('HERKOMST')
|
|
50
|
+
_(StatBankDenmark::Tables.dimensions('FOLK1C')).wont_include('HERKOMST1')
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "spells sex KOEN in STRAFNA3 and KØN everywhere else" do
|
|
54
|
+
_(StatBankDenmark::Tables.dimensions('STRAFNA3')).must_include('KOEN')
|
|
55
|
+
_(StatBankDenmark::Tables.dimensions('STRAF42')).must_include('KØN')
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context "the tables themselves" do
|
|
60
|
+
it "names every one it knows" do
|
|
61
|
+
_(StatBankDenmark::Tables.ids.sort).must_equal(%w{FOLK1C FOLK2 STRAF10 STRAF42 STRAFNA3 VAN66})
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "gives every dimension a name and a column" do
|
|
65
|
+
StatBankDenmark::Tables.ids.each do |id|
|
|
66
|
+
StatBankDenmark::Tables.dimensions(id).each do |dimension, detail|
|
|
67
|
+
_(detail[:name]).wont_be_nil("#{id}/#{dimension} has no :name")
|
|
68
|
+
_(detail[:as]).wont_be_nil("#{id}/#{dimension} has no :as")
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: statbank_denmark
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thoran
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: http.rb
|
|
@@ -100,7 +100,7 @@ executables: []
|
|
|
100
100
|
extensions: []
|
|
101
101
|
extra_rdoc_files: []
|
|
102
102
|
files:
|
|
103
|
-
- CHANGELOG
|
|
103
|
+
- CHANGELOG
|
|
104
104
|
- Gemfile
|
|
105
105
|
- LICENSE
|
|
106
106
|
- README.md
|
|
@@ -108,11 +108,13 @@ files:
|
|
|
108
108
|
- lib/StatBankDenmark.rb
|
|
109
109
|
- lib/StatBankDenmark/Client.rb
|
|
110
110
|
- lib/StatBankDenmark/Error.rb
|
|
111
|
+
- lib/StatBankDenmark/Tables.rb
|
|
111
112
|
- lib/StatBankDenmark/VERSION.rb
|
|
112
113
|
- lib/statbank_denmark.rb
|
|
113
114
|
- statbank_denmark.gemspec
|
|
114
115
|
- test/StatBankDenmark/Client_test.rb
|
|
115
116
|
- test/StatBankDenmark/Error_test.rb
|
|
117
|
+
- test/StatBankDenmark/Tables_test.rb
|
|
116
118
|
- test/StatBankDenmark/VERSION_test.rb
|
|
117
119
|
- test/StatBankDenmark_test.rb
|
|
118
120
|
- test/helper.rb
|
data/CHANGELOG.txt
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# CHANGELOG.md
|
|
2
|
-
|
|
3
|
-
## [0.0.2] - 2026-09-28
|
|
4
|
-
- ~ test/StatBankDenmark_test.rb: /test_helper/helper/. It named a file which does not exist, so this test had never run.
|
|
5
|
-
- ~ StatBankDenmark::VERSION: /0.0.1/0.0.2/
|
|
6
|
-
|
|
7
|
-
## [0.0.1] - 2026-08-22
|
|
8
|
-
- + LICENSE: the MIT text, copyright 2025-2026 thoran. The gemspec has declared MIT while the repository carried no licence text at all.
|
|
9
|
-
- ~ statbank_denmark.gemspec: + 'LICENSE' to spec.files, so the gem carries what the declaration claims.
|
|
10
|
-
- ~ StatBankDenmark::VERSION: /0.0.0/0.0.1/
|
|
11
|
-
|
|
12
|
-
## [0.0.0] - 2025-09-08
|
|
13
|
-
- Initial release
|
|
14
|
-
- subjects(): /subjects endpoint
|
|
15
|
-
- tables(): /tables endpoint
|
|
16
|
-
- tableinfo(): /tableinfo endpoint
|
|
17
|
-
- data(): /data endpoint
|
|
18
|
-
- search(): Search all tables by string.
|