statbank_denmark 0.0.2 → 0.1.1

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
  SHA256:
3
- metadata.gz: 9fe13751db3842c5b7628fa470243b2fe1aba17ca9f0f3dba9b2d98299341929
4
- data.tar.gz: 678f45c7a3da9ce45ae4baafe3ecb55acb1d9e5a87fb44f815e64b18b3487ea4
3
+ metadata.gz: 6d0a8e0c92420913c343d904f90f28636ff241d0a9d218d9ca24c170aff2a6ad
4
+ data.tar.gz: b9dc4ace09453161698d89f42fded461dc84be0f7d6b18c2c8a40ed9fd2e2c2b
5
5
  SHA512:
6
- metadata.gz: 13005041a71c6ae61c4edea58c0de8381fe68c37acc1a8743e955544a866f85ab0907a69c70c8fda0d545f850793cffa072e743e9bfa0b502a91a7c8a4dd4c70
7
- data.tar.gz: abbc0c2b0002d9a2f7ac6d1d07e09e6022efde6d54484a83f8db0ad1c5866948b9bfc8b0541d3b63df1119e23054242cc86947066afe3bb84efb599fc52791a8
6
+ metadata.gz: 24f71e8c419da107d3398b516d6813f15dd6f70fb9c718daccd622565435d7aabcc10f22887061969b727f23e0891f5a506fc69c16576951cea25f1b83e20356
7
+ data.tar.gz: 7416ec1be1476ea1738bc9058a049927b03f6b61308f04be7d1f35a409c52e0f7a1218b1bb5d4e3e809f9d269a1e7fd927019e661f30e09c60170ee4bd9ca74b
data/CHANGELOG ADDED
@@ -0,0 +1,50 @@
1
+ # statbank_denmark/CHANGELOG
2
+
3
+ ## 20260928
4
+
5
+ 0.1.1: alias_method :tableinfo, :table_info
6
+
7
+ 1. + StatBankDenmark.tableinfo
8
+ 2. + StatBankDenmark::Client#tableinfo
9
+ 3. ~ StatBankDenmark::VERSION: /0.1.0/0.1.1/
10
+
11
+ 0.1.0: + StatBankDenmark::Tables
12
+
13
+ 1. + StatBankDenmark::Tables: six crime and population tables and their dimensions, taken from table_info.
14
+ 2. + StatBankDenmark::Tables.[], .ids, .dimensions, and .column.
15
+ 3. + test/StatBankDenmark/Tables_test.rb
16
+ 4. ~ lib/StatBankDenmark.rb: + require_relative './StatBankDenmark/Tables'
17
+ 5. ~ statbank_denmark.gemspec: - spec.date
18
+ 6. ~ StatBankDenmark::VERSION: /0.0.2/0.1.0/
19
+
20
+ 0.0.2: ~ test/StatBankDenmark_test.rb: /test_helper/helper/
21
+
22
+ 1. It named a file which does not exist, so this test had never run.
23
+ 2. ~ StatBankDenmark::VERSION: /0.0.1/0.0.2/
24
+
25
+
26
+ ## 20260822
27
+
28
+ 0.0.1: + LICENSE
29
+
30
+ 1. + LICENSE
31
+ 2. ~ statbank_denmark.gemspec: + 'LICENSE'
32
+ 3. ~ StatBankDenmark::VERSION: /0.0.0/0.0.1/
33
+
34
+
35
+ ## 20250908
36
+
37
+ 0.0.0: + /subjects, /tables, /tableinfo, and /data endpoints; and provide basic table searching.
38
+
39
+ 1. + StatBankDenmark
40
+ 2. + StatBankDenmark.subjects: A convenience method StatBankDenmark::Client#subjects.
41
+ 3. + StatBankDenmark.tables: A convenience method StatBankDenmark::Client#tables.
42
+ 4. + StatBankDenmark.table_info: A convenience method StatBankDenmark::Client#table_info.
43
+ 5. + StatBankDenmark.data: A convenience method StatBankDenmark::Client#data.
44
+ 6. + StatBankDenmark.search: A convenience method StatBankDenmark::Client#search.
45
+ 7. + StatBankDenmark::Client
46
+ 8. + StatBankDenmark::Client#subjects: /subjects endpoint
47
+ 9. + StatBankDenmark::Client#tables: /tables endpoint
48
+ 10. + StatBankDenmark::Client#table_info: /tableinfo endpoint
49
+ 11. + StatBankDenmark::Client#data: /data endpoint
50
+ 12. + StatBankDenmark::Client.search: Search all tables by string.
data/README.md CHANGED
@@ -58,6 +58,7 @@ StatBankDenmark.tables(include_inactive: true, subject: 4)
58
58
  StatBankDenmark.table_info('STRAF42') # implicitly format: 'json'
59
59
  StatBankDenmark.table_info('STRAF42', format: 'json') # explicitly format: 'json'
60
60
  StatBankDenmark.table_info('STRAF42', format: 'csv') # format: 'csv'
61
+ StatBankDenmark.tableinfo('STRAF42') # an alias, /tableinfo being the endpoint
61
62
 
62
63
  # Get data from a specific table
63
64
  StatBankDenmark.data('STRAF42') # implicitly format: 'csv'
@@ -114,6 +115,37 @@ client.search('befolkning', lang: 'da') # lang: 'da'
114
115
  client.search('BEFOLKNING', lang: 'da') # case insensitive search and lang: 'da'
115
116
  ```
116
117
 
118
+ ### Table metadata
119
+
120
+ Six crime and population tables and their dimensions. `table_info` answers with
121
+ the values a dimension takes; this is a starting point for choosing which table
122
+ to ask.
123
+
124
+ ```ruby
125
+ # Which tables are described here
126
+ StatBankDenmark::Tables.ids # => ["STRAF42", "STRAF10", "STRAFNA3", "FOLK1C", "FOLK2", "VAN66"]
127
+
128
+ # What a table is
129
+ StatBankDenmark::Tables['STRAF42'][:name] # => "Decisions, total"
130
+ StatBankDenmark::Tables['straf42'] # the id is taken in any case
131
+
132
+ # Every dimension of a table, named as the API names them
133
+ StatBankDenmark::Tables.dimensions('STRAF10').keys # => ["OVERTRÆD", "Tid"]
134
+
135
+ # What a dimension is called once the row is read as Ruby
136
+ StatBankDenmark::Tables.column('STRAF42', 'HERKOMST1') # => :national_origin
137
+ StatBankDenmark::Tables.column('FOLK2', 'STATSB') # => :citizenship
138
+ ```
139
+
140
+ Two things are worth knowing before choosing a table. `HERKOMST1` in `STRAF42`
141
+ and `HERKOMST` in `FOLK1C` and `FOLK2` are not two spellings of one dimension —
142
+ the first is citizenship, the second residence — so they do not substitute. And
143
+ `STRAFNA3` and `VAN66` have no ancestry dimension at all; `IELAND`, country of
144
+ origin, is the nearest either offers.
145
+
146
+ Asking with a dimension a table has not got answers 400, which reads as the table
147
+ being broken when it is the request that is wrong.
148
+
117
149
  ## Contributing
118
150
 
119
151
  1. Fork it (https://github.com/thoran/statbank_denmark/fork)
@@ -72,6 +72,9 @@ module StatBankDenmark
72
72
  )
73
73
  handle_response(response)
74
74
  end
75
+ # The endpoint is /tableinfo, which is how StatBank's own documentation names
76
+ # it, and the spelling anyone arriving from there reaches for first.
77
+ alias_method :tableinfo, :table_info
75
78
 
76
79
  def data(
77
80
  table_id,
@@ -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
@@ -2,5 +2,5 @@
2
2
  # StatBankDenmark::VERSION
3
3
 
4
4
  module StatBankDenmark
5
- VERSION = '0.0.2'
5
+ VERSION = '0.1.1'
6
6
  end
@@ -3,6 +3,7 @@
3
3
 
4
4
  require_relative './StatBankDenmark/VERSION'
5
5
  require_relative './StatBankDenmark/Client'
6
+ require_relative './StatBankDenmark/Tables'
6
7
 
7
8
  module StatBankDenmark
8
9
  class << self
@@ -17,6 +18,9 @@ module StatBankDenmark
17
18
  def table_info(table_id, **options)
18
19
  client.table_info(table_id, **options)
19
20
  end
21
+ # The endpoint is /tableinfo, which is how StatBank's own documentation names
22
+ # it, and the spelling anyone arriving from there reaches for first.
23
+ alias_method :tableinfo, :table_info
20
24
 
21
25
  def data(table_id, **options)
22
26
  client.data(table_id, **options)
@@ -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.txt',
19
+ 'CHANGELOG',
21
20
  'Gemfile',
22
21
  'LICENSE',
23
22
  'README.md',
@@ -132,6 +132,11 @@ describe StatBankDenmark::Client do
132
132
  end
133
133
  end
134
134
 
135
+ it "answers to tableinfo, which is what the endpoint is called" do
136
+ _(client).must_respond_to(:tableinfo)
137
+ _(StatBankDenmark::Client.instance_method(:tableinfo).original_name).must_equal(:table_info)
138
+ end
139
+
135
140
  it "raises ArgumentError for nil table_id" do
136
141
  _(proc{client.table_info(nil)}).must_raise(ArgumentError)
137
142
  end
@@ -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
@@ -11,5 +11,10 @@ describe StatBankDenmark do
11
11
  _(StatBankDenmark).must_respond_to(:data)
12
12
  _(StatBankDenmark).must_respond_to(:search)
13
13
  end
14
+
15
+ it "answers to tableinfo, which is what the endpoint is called" do
16
+ _(StatBankDenmark).must_respond_to(:tableinfo)
17
+ _(StatBankDenmark.method(:tableinfo).original_name).must_equal(:table_info)
18
+ end
14
19
  end
15
20
  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.2
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-09-09 00:00:00.000000000 Z
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.txt
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.