data_gov_au 0.5.0 → 0.6.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
  SHA256:
3
- metadata.gz: b5814d7896076071cd29082fccc44d4d1c43d17434d9b2dbd4efd83a2c2e975b
4
- data.tar.gz: 13ab8f6c4971a90a738470861880b2bb3edc36faf2a5f293b00998c1313e2ff3
3
+ metadata.gz: 60bf7ec173c873b3ad031f6fee912d0318d1e77de54a7d91842d482d6a4c4cc0
4
+ data.tar.gz: 6367a0906b0277b8c40052c7394c27316db0ff80f455a3a7551a613e91e3173a
5
5
  SHA512:
6
- metadata.gz: 927c2ba32f8ab74d71a5ec4141acbfc14c32a5e1eb095cda08750b028fc1a788a1ce61886343178e4ee9e6def328fc6923b1ce4e738a0d425bbdda8d04a0d880
7
- data.tar.gz: efcdf5a651c8aef12a83d28778762492b04e0c9dbbbb7d43b123c6d88333bf12a3a90a1391df2d8e280c448c5a6e62e769741ff8aa14366fc0a01a094a378eb6
6
+ metadata.gz: 13be48ce2bec0fec8c2300c7fb66b3d57d7dc8dc0a774780d71aa451f435354812e3348bc165b90632c0e976e6014391c1481b674a7a4dcbccba3d1d3b0856bc
7
+ data.tar.gz: 9045e5e782b45488d3ac712a4d573ed90baed377e12fc82895aa568add5e7afaf2658c651ce048e221d3d0c04cdc7fce5592fe9399399d870ffd192595cb5f07
data/CHANGELOG CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  ## 20261125
4
4
 
5
+ 0.6.0: + DataGovAu::AsicCompanies::Parser, + DataGovAu::AsicCompanies::Extract
6
+
7
+ 1. + DataGovAu::AsicCompanies::Parser: The register yielded a row at a time, each line split by DSV.parse_line rather than read through DSV#each, which reads every row before yielding the first.
8
+ 2. + DataGovAu::AsicCompanies::Extract: A release's rows, read out of its zip as rubyzip inflates it.
9
+ 3. ~ DataGovAu::AsicCompanies::Release: + #zip_paths.
10
+ 4. ~ DataGovAu::AsicCompanies: + NothingToParse, + RegisterMalformed.
11
+ 5. ~ lib/DataGovAu/AsicCompanies.rb: Extract and Parser are required.
12
+ 6. ~ data_gov_au(.rb).gemspec: + dsv, ~> 0.13. The description names the ASIC register.
13
+ 7. + test/DataGovAu/AsicCompanies/Parser_test.rb, Extract_test.rb. ~ test/DataGovAu/AsicCompanies/Release_test.rb: Its zips are found. ~ test/DataGovAu/AsicCompanies/helper.rb: + asic_rows(), asic_register_text(), asic_release_holding(): 222 runs.
14
+ 8. ~ README.md: The ASIC Company Dataset: + Parsing, + What a row comes out as. Its rows are some 4.5 million, not 3.
15
+ 9. ~ ROADMAP.md: The ASIC register's rows are read. + 1.0.
16
+ 10. ~ PROPOSED.md: Datasets: + Pointer datasets. + Libraries given by the caller for hosts elsewhere. The catalogue: Four of the hosts pointed to are CKAN portals. The ASIC Company Dataset: Rows gathered by ACN as well as yielded one at a time.
17
+ 11. ~ TODO: - The register's parsing.
18
+ 12. ~ DataGovAu::AbnBulkExtract::Parser, DataGovAu::Catalogue#action, test/DataGovAu/AbnBulkExtract/Extract_test.rb, Lines_test.rb, Parser_test.rb, test/DataGovAu/Dataset_test.rb: Comments and test names say yields or returns where they said gives up.
19
+ 13. ~ DataGovAu::VERSION: /0.5.0/0.6.0/
20
+
5
21
  0.5.0: + DataGovAu::AsicCompanies, - DataGovAu::ABR
6
22
 
7
23
  1. + lib/DataGovAu/AsicCompanies.rb: + DATASET, + ATTRIBUTION.
data/README.md CHANGED
@@ -283,7 +283,7 @@ Any output leaving the machine must carry that attribution; `DataGovAu::AbnBulkE
283
283
 
284
284
  ## The ASIC Company Dataset
285
285
 
286
- `DataGovAu::AsicCompanies`, built on the catalogue, holds ASIC's weekly snapshot of its company register: every registered company, those deregistered in the past year, and the former names of those registered, some 3 million rows in one tab-separated file of about 401 MB, or 79 MB zipped. It fetches each release; reading its rows is still to come. It is named for the dataset's name in the catalogue, `asic-companies`, which `DataGovAu::AsicCompanies::DATASET` holds.
286
+ `DataGovAu::AsicCompanies`, built on the catalogue, holds ASIC's weekly snapshot of its company register: every registered company, those deregistered in the past year, and the former names of those registered, some 4.5 million rows in one tab-separated file of about 401 MB, or 79 MB zipped. It fetches each release and reads its rows. It is named for the dataset's name in the catalogue, `asic-companies`, which `DataGovAu::AsicCompanies::DATASET` holds.
287
287
 
288
288
  ```ruby
289
289
  require 'DataGovAu/AsicCompanies'
@@ -295,6 +295,8 @@ Its parts are the extract's, each its own copy until what they share is clear:
295
295
  - `Fetch`: the current release found through the catalogue, and whatever of it is not held retrieved.
296
296
  - `ExtractDate`: the date the register was extracted, read from the first bytes of the zip.
297
297
  - `Release`: a release on disk, its directory named for that date.
298
+ - `Extract`: a release's rows, read out of its zip.
299
+ - `Parser`: the register, read a row at a time.
298
300
 
299
301
  ### Why a local copy
300
302
 
@@ -323,6 +325,44 @@ A release is the zip and the help file. The catalogue also lists the register un
323
325
 
324
326
  A release is named for the date in the zip's own record of when the file inside it was written, which is the date ASIC gives the extract, in Sydney's time. The file inside is named for the month alone, as `COMPANY_202611.csv`, and the catalogue's `modified_on` is a day earlier in UTC. The record stands in the zip's first few hundred bytes, so it is asked for by range before anything large is retrieved.
325
327
 
328
+ ### Parsing
329
+
330
+ ```ruby
331
+ date = DataGovAu::AsicCompanies::Release.dates_held(config).first
332
+ release = DataGovAu::AsicCompanies::Release.new(config, date)
333
+
334
+ DataGovAu::AsicCompanies::Extract.new(release).each_record do |record|
335
+ record[:acn] # => "000000019"
336
+ end
337
+ ```
338
+
339
+ Reading touches nothing on the network. The register is read out of the zip as rubyzip inflates it, a line at a time, and each line is split by dsv, so the 401 MB file is never held whole: the 20261124 release's 4,464,241 rows take about a minute. The header is checked before any row is yielded, and a row with other than fifteen fields stops the read, naming its line, so that a register whose columns have moved is not read under the wrong names.
340
+
341
+ ### What a row comes out as
342
+
343
+ A row is one name a company has held, so a company comes as many rows as it has had names, under the same ACN. Nothing is filtered, derived or discarded: each field is the string the register holds.
344
+
345
+ ```ruby
346
+ {
347
+ company_name: 'LOVINI HOLDINGS PTY LTD', acn: '000000019',
348
+ type: 'APTY', class: 'LMSH', sub_class: 'PROP', status: 'REGD',
349
+ date_of_registration: '08/01/1990', date_of_deregistration: '',
350
+ previous_state_of_registration: 'NSW', state_registration_number: '46869041',
351
+ modified_since_last_report: '', current_name_indicator: '',
352
+ abn: '89000000019', current_name: 'MONAKA PTY LTD', current_name_start_date: '28/01/2016',
353
+ }
354
+ ```
355
+
356
+ That row is a former name. Its `current_name_indicator` is empty, and its `current_name` and `current_name_start_date` give the name which replaced it. The row for the current name, `MONAKA PTY LTD`, has `current_name_indicator` `'Y'` and those two fields empty.
357
+
358
+ Kept as the register gives them:
359
+
360
+ - An empty field is `''`, every column being present in every row.
361
+ - An ABN of `'0'` is a company with none, as 1,708,744 of the 20261124 release's rows are.
362
+ - Dates are `dd/mm/yyyy`.
363
+ - Where `type` is `RACN`, a registered Australian body, `acn` holds its ARBN.
364
+ - A quote in a name is part of it, as in `TUMUT BOWLING & RECREATION CLUB LTD. TRADING AS "CLUB TUMUT" LTD`, the register quoting nothing; and spaces trailing a name are kept.
365
+
326
366
  ### On disk
327
367
 
328
368
  ```
data/TODO CHANGED
@@ -5,4 +5,3 @@
5
5
  3. DataGovAu::AbnBulkExtract: storage, every record and every name stored with the dates over which it held, nothing filtered and nothing derived at ingest.
6
6
  4. DataGovAu::AbnBulkExtract: querying, every criterion a WHERE clause, none of them applied at ingest.
7
7
  5. DataGovAu::AbnBulkExtract: output, CSV through dsv, carrying the ABR's attribution.
8
- 6. DataGovAu::AsicCompanies: parsing, the tab-separated register read out of the zip through dsv, its byte-order mark and CRLF line ends allowed for.
data/data_gov_au.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.version = DataGovAu::VERSION
18
18
 
19
19
  spec.summary = "A client for data.gov.au's CKAN API, and the datasets built on it."
20
- spec.description = "Find a dataset through data.gov.au's CKAN catalogue by its name or id, read what the catalogue says of it and of each of its resources, and download a resource once, checked against the length the catalogue reports. Built on it, the Australian Business Register's weekly ABN bulk extract, each release fetched once and kept."
20
+ spec.description = "Find a dataset through data.gov.au's CKAN catalogue by its name or id, read what the catalogue says of it and of each of its resources, and download a resource once, checked against the length the catalogue reports. Built on it, the Australian Business Register's weekly ABN bulk extract and ASIC's weekly company register, each release fetched once and kept, and read a record at a time."
21
21
 
22
22
  spec.author = 'thoran'
23
23
  spec.email = 'code@thoran.com'
@@ -41,6 +41,7 @@ Gem::Specification.new do |spec|
41
41
  ].flatten
42
42
 
43
43
  spec.runtime_dependencies = [
44
+ ['dsv', '~> 0.13'],
44
45
  'http.rb',
45
46
  'ox',
46
47
  'rubyzip',
@@ -7,7 +7,7 @@ require_relative './Error'
7
7
 
8
8
  module DataGovAu
9
9
  module AbnBulkExtract
10
- # One XML file of an extract, read as a stream and given up one record at a time. Nothing is filtered, nothing is derived and nothing is discarded: every element and attribute the schema allows for is carried into the record, dates as the strings the extract gives them, so that what is asked of the data later is not settled here.
10
+ # One XML file of an extract, read as a stream and yielded one record at a time. Nothing is filtered, nothing is derived and nothing is discarded: every element and attribute the schema allows for is carried into the record, dates as the strings the extract gives them, so that what is asked of the data later is not settled here.
11
11
  #
12
12
  # A record comes out shaped so:
13
13
  #
@@ -44,7 +44,7 @@ module DataGovAu
44
44
  @error == NO_ERROR
45
45
  end
46
46
 
47
- # Every record was given up where the file reports no error and holds as many as its own TransferInfo promised.
47
+ # Every record was yielded where the file reports no error and holds as many as its own TransferInfo promised.
48
48
  def whole?
49
49
  error_free? && !record_count.nil? && records_parsed == record_count
50
50
  end
@@ -1,5 +1,5 @@
1
1
  # DataGovAu/AsicCompanies/Error.rb
2
- # DataGovAu::AsicCompanies::ExtractUndated
2
+ # DataGovAu::AsicCompanies::ExtractUndated, NothingToParse, RegisterMalformed
3
3
 
4
4
  require_relative '../Error'
5
5
 
@@ -7,5 +7,11 @@ module DataGovAu
7
7
  module AsicCompanies
8
8
  # The zip did not date the file it holds, so the release cannot be named.
9
9
  class ExtractUndated < Error; end
10
+
11
+ # No release is held, or the one held has no zip file, so there is nothing to parse.
12
+ class NothingToParse < Error; end
13
+
14
+ # The register is not laid out as ASIC writes it: its header names other columns, or a row has other than one field for each.
15
+ class RegisterMalformed < Error; end
10
16
  end
11
17
  end
@@ -0,0 +1,46 @@
1
+ # DataGovAu/AsicCompanies/Extract.rb
2
+ # DataGovAu::AsicCompanies::Extract
3
+
4
+ require 'zip'
5
+
6
+ require_relative './Error'
7
+ require_relative './Parser'
8
+
9
+ module DataGovAu
10
+ module AsicCompanies
11
+ # A release's rows, read out of the zip as it lies. rubyzip inflates the register as it is read and the parser takes it a line at a time, so neither the 79 MB zip nor the 401 MB register inside it is ever held whole.
12
+ class Extract
13
+ # Each file in the release's zip, as its name and the stream rubyzip inflates.
14
+ def each_member
15
+ return enum_for(:each_member) unless block_given?
16
+ raise NothingToParse, "#{@release.directory} holds no zip file" if paths.empty?
17
+ paths.each do |path|
18
+ Zip::File.open(path) do |zip|
19
+ zip.entries.select(&:file?).each{|entry| entry.get_input_stream{|io| yield entry.name, io}}
20
+ end
21
+ end
22
+ end
23
+
24
+ # Each file in the release's zip, as its own parser, so that a caller can report its progress.
25
+ def each_file
26
+ return enum_for(:each_file) unless block_given?
27
+ each_member{|name, io| yield name, Parser.new(io)}
28
+ end
29
+
30
+ def each_record(&block)
31
+ return enum_for(:each_record) unless block
32
+ each_file{|_name, parser| parser.each_record(&block)}
33
+ end
34
+
35
+ def paths
36
+ @paths ||= @release.zip_paths
37
+ end
38
+
39
+ private
40
+
41
+ def initialize(release)
42
+ @release = release
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,84 @@
1
+ # DataGovAu/AsicCompanies/Parser.rb
2
+ # DataGovAu::AsicCompanies::Parser
3
+
4
+ require 'dsv'
5
+
6
+ require_relative './Error'
7
+
8
+ module DataGovAu
9
+ module AsicCompanies
10
+ # The register as ASIC writes it, read as a stream and yielded a row at a time: tab-separated, each line ending CRLF, a byte-order mark before the header, and a quote in a name being part of the name rather than the start of a quoted field. Nothing is filtered, derived or discarded: every field comes as the string the register gives, an empty one as '', dates as dd/mm/yyyy, and an ABN of 0 where the company has none.
11
+ #
12
+ # A row is one name a company has held, so a company comes as many rows as it has had names, under the same ACN. A row comes out shaped so:
13
+ #
14
+ # {
15
+ # company_name: 'LOVINI HOLDINGS PTY LTD', acn: '000000019',
16
+ # type: 'APTY', class: 'LMSH', sub_class: 'PROP', status: 'REGD',
17
+ # date_of_registration: '08/01/1990', date_of_deregistration: '',
18
+ # previous_state_of_registration: 'NSW', state_registration_number: '46869041',
19
+ # modified_since_last_report: '', current_name_indicator: '',
20
+ # abn: '89000000019', current_name: 'MONAKA PTY LTD', current_name_start_date: '28/01/2016',
21
+ # }
22
+ class Parser
23
+ BYTE_ORDER_MARK = ""
24
+ COLUMN_SEPARATOR = "\t"
25
+ ROW_SEPARATOR = "\r\n"
26
+
27
+ # The register's columns as its header names them, in order, and the key each is given under.
28
+ COLUMNS = {
29
+ 'Company Name' => :company_name,
30
+ 'ACN' => :acn,
31
+ 'Type' => :type,
32
+ 'Class' => :class,
33
+ 'Sub Class' => :sub_class,
34
+ 'Status' => :status,
35
+ 'Date of Registration' => :date_of_registration,
36
+ 'Date of Deregistration' => :date_of_deregistration,
37
+ 'Previous State of Registration' => :previous_state_of_registration,
38
+ 'State Registration number' => :state_registration_number,
39
+ 'Modified since last report' => :modified_since_last_report,
40
+ 'Current Name Indicator' => :current_name_indicator,
41
+ 'ABN' => :abn,
42
+ 'Current Name' => :current_name,
43
+ 'Current Name Start Date' => :current_name_start_date,
44
+ }
45
+
46
+ attr_reader :records_parsed
47
+
48
+ # The header is checked before any row is yielded, so that a register whose columns have moved stops rather than having its values yielded under the wrong names.
49
+ def each_record
50
+ return enum_for(:each_record) unless block_given?
51
+ validate_header
52
+ while (line = @io.gets(ROW_SEPARATOR))
53
+ @records_parsed += 1
54
+ yield record(fields(line))
55
+ end
56
+ self
57
+ end
58
+
59
+ private
60
+
61
+ def initialize(io)
62
+ @io = io
63
+ @records_parsed = 0
64
+ end
65
+
66
+ def validate_header
67
+ line = @io.gets(ROW_SEPARATOR)
68
+ header = line && fields(line.force_encoding(Encoding::UTF_8).delete_prefix(BYTE_ORDER_MARK))
69
+ return if header == COLUMNS.keys
70
+ raise RegisterMalformed, "the header is #{header.inspect}, where #{COLUMNS.keys.inspect} was expected"
71
+ end
72
+
73
+ # One line into its fields through dsv, with no quoting, since the register quotes nothing.
74
+ def fields(line)
75
+ DSV.parse_line(line.force_encoding(Encoding::UTF_8), column_separator: COLUMN_SEPARATOR, row_separator: ROW_SEPARATOR, quote: :none)
76
+ end
77
+
78
+ def record(fields)
79
+ return COLUMNS.values.zip(fields).to_h if fields.size == COLUMNS.size
80
+ raise RegisterMalformed, "line #{@records_parsed + 1} has #{fields.size} fields, where #{COLUMNS.size} were expected"
81
+ end
82
+ end
83
+ end
84
+ end
@@ -28,6 +28,11 @@ module DataGovAu
28
28
  File.join(directory, resource.filename)
29
29
  end
30
30
 
31
+ # The zips in the release's directory, read from the directory rather than from the catalogue, so that a release on disk can be parsed without going back to data.gov.au.
32
+ def zip_paths
33
+ @zip_paths ||= Dir.glob(File.join(directory, '*.zip')).sort
34
+ end
35
+
31
36
  def held?(resource)
32
37
  resource.held_at?(path_for(resource))
33
38
  end
@@ -6,7 +6,9 @@
6
6
  require_relative './AsicCompanies/Config'
7
7
  require_relative './AsicCompanies/Error'
8
8
  require_relative './AsicCompanies/ExtractDate'
9
+ require_relative './AsicCompanies/Extract'
9
10
  require_relative './AsicCompanies/Fetch'
11
+ require_relative './AsicCompanies/Parser'
10
12
  require_relative './AsicCompanies/Release'
11
13
 
12
14
  module DataGovAu
@@ -30,7 +30,7 @@ module DataGovAu
30
30
  yield(self) if block_given?
31
31
  end
32
32
 
33
- # One call to the action API, giving up its result where the answer reports success.
33
+ # One call to the action API, returning its result where the answer reports success.
34
34
  def action(name, parameters = {})
35
35
  url = "#{@api_url}/#{name}"
36
36
  response = HTTP.get(url, parameters, {'User-Agent' => @user_agent})
@@ -2,5 +2,5 @@
2
2
  # DataGovAu::VERSION
3
3
 
4
4
  module DataGovAu
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.0'
6
6
  end
@@ -4,7 +4,7 @@ require_relative '../../helper'
4
4
 
5
5
  describe DataGovAu::AbnBulkExtract::Extract do
6
6
  describe "reading out of the zips" do
7
- it "gives up the records of a zipped file" do
7
+ it "yields the records of a zipped file" do
8
8
  Dir.mktmpdir do |directory|
9
9
  release = release_holding(directory, Date.new(2026, 10, 28))
10
10
  _(DataGovAu::AbnBulkExtract::Extract.new(release).each_record.to_a.length).must_equal 9
@@ -12,7 +12,7 @@ describe DataGovAu::AbnBulkExtract::Lines do
12
12
  end
13
13
 
14
14
  describe "a file laid out a record a line" do
15
- it "gives up each record as its ABN and its text" do
15
+ it "yields each record as its ABN and its text" do
16
16
  _lines, read_records = read(text)
17
17
  _(read_records).must_equal [['11111111111', records[0]], ['22222222222', records[1]], ['33333333333', records[2]]]
18
18
  end
@@ -36,7 +36,7 @@ describe DataGovAu::AbnBulkExtract::Parser do
36
36
  end
37
37
  end
38
38
 
39
- it "counts itself short where the file reports an error, every record given up or not" do
39
+ it "counts itself short where the file reports an error, every record yielded or not" do
40
40
  Dir.mktmpdir do |directory|
41
41
  path = File.join(directory, 'erred.xml')
42
42
  File.write(path, File.read(fixture_path('20261020Public01.xml')).sub('<Transfer error="none">', '<Transfer error="partial">'))
@@ -58,8 +58,8 @@ describe DataGovAu::AbnBulkExtract::Parser do
58
58
  end
59
59
  end
60
60
 
61
- describe "the record it gives up" do
62
- it "gives up every record in the file" do
61
+ describe "the record it yields" do
62
+ it "yields every record in the file" do
63
63
  _(fixture_records.length).must_equal 9
64
64
  end
65
65
 
@@ -179,7 +179,7 @@ describe DataGovAu::AbnBulkExtract::Parser do
179
179
  end
180
180
  end
181
181
 
182
- describe "the shape it gives up" do
182
+ describe "the shape it yields" do
183
183
  # The storage stage writes a row per record, so every record carrying the same keys matters more than the keys being few.
184
184
  it "gives every record the same keys" do
185
185
  _(fixture_records.collect(&:keys).uniq.length).must_equal 1
@@ -0,0 +1,28 @@
1
+ # test/DataGovAu/AsicCompanies/Extract_test.rb
2
+
3
+ require_relative './helper'
4
+
5
+ describe DataGovAu::AsicCompanies::Extract do
6
+ it "yields the rows of the zipped register" do
7
+ Dir.mktmpdir do |directory|
8
+ records = DataGovAu::AsicCompanies::Extract.new(asic_release_holding(directory)).each_record.to_a
9
+ _(records.collect{|record| record[:acn]}).must_equal ['000000019', '000000019', '000000260', '001001074']
10
+ end
11
+ end
12
+
13
+ it "yields the register as its name and its own parser" do
14
+ Dir.mktmpdir do |directory|
15
+ reached = []
16
+ DataGovAu::AsicCompanies::Extract.new(asic_release_holding(directory)).each_file{|name, parser| reached << [name, parser.each_record{}.records_parsed]}
17
+ _(reached).must_equal [[ASIC_MEMBER, 4]]
18
+ end
19
+ end
20
+
21
+ it "stops where the release holds no zip" do
22
+ Dir.mktmpdir do |directory|
23
+ release = DataGovAu::AsicCompanies::Release.new(asic_config_in(directory), Date.new(2026, 11, 24))
24
+ release.create_directory
25
+ _(->{DataGovAu::AsicCompanies::Extract.new(release).each_record.to_a}).must_raise DataGovAu::AsicCompanies::NothingToParse
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,81 @@
1
+ # test/DataGovAu/AsicCompanies/Parser_test.rb
2
+
3
+ require_relative './helper'
4
+
5
+ describe DataGovAu::AsicCompanies::Parser do
6
+ def records_of(text)
7
+ DataGovAu::AsicCompanies::Parser.new(StringIO.new(text)).each_record.to_a
8
+ end
9
+
10
+ describe "a row" do
11
+ it "comes keyed by the register's columns" do
12
+ _(records_of(asic_register_text).first).must_equal({
13
+ company_name: 'LOVINI HOLDINGS PTY LTD', acn: '000000019',
14
+ type: 'APTY', class: 'LMSH', sub_class: 'PROP', status: 'REGD',
15
+ date_of_registration: '08/01/1990', date_of_deregistration: '',
16
+ previous_state_of_registration: 'NSW', state_registration_number: '46869041',
17
+ modified_since_last_report: '', current_name_indicator: '',
18
+ abn: '89000000019', current_name: 'MONAKA PTY LTD', current_name_start_date: '28/01/2016',
19
+ })
20
+ end
21
+
22
+ it "is one name, so that a company comes as many rows as it has held names" do
23
+ _(records_of(asic_register_text).select{|record| record[:acn] == '000000019'}.collect{|record| record[:company_name]}).must_equal ['LOVINI HOLDINGS PTY LTD', 'MONAKA PTY LTD']
24
+ end
25
+
26
+ # The register quotes nothing, so a quote is part of the name.
27
+ it "keeps a quote in a name as part of it" do
28
+ _(records_of(asic_register_text).last[:company_name]).must_equal 'TUMUT BOWLING & RECREATION CLUB LTD. TRADING AS "CLUB TUMUT" LTD'
29
+ end
30
+
31
+ it "keeps a quote opening a name as part of it" do
32
+ row = ['"KARAISKAKIS" LIMITED', '000842160', 'APUB', 'LMGT', 'ULSN', 'REGD', '02/11/1970', '', 'NSW', '1', '', 'Y', '0', '', '']
33
+ _(records_of(asic_register_text([row])).first[:company_name]).must_equal '"KARAISKAKIS" LIMITED'
34
+ end
35
+
36
+ it "gives fields as the strings the register holds, an ABN of 0 and empty fields included" do
37
+ record = records_of(asic_register_text)[2]
38
+ _(record[:abn]).must_equal '0'
39
+ _(record[:current_name]).must_equal ''
40
+ _(record[:date_of_deregistration]).must_equal '13/03/2026'
41
+ end
42
+
43
+ it "keeps spaces trailing a name" do
44
+ row = ['THE HOLY APOSTLES LIMITED ', '001233790', 'APUB', 'LMGT', 'ULSN', 'REGD', '01/01/1977', '', 'NSW', '1', '', 'Y', '0', '', '']
45
+ _(records_of(asic_register_text([row])).first[:company_name]).must_equal 'THE HOLY APOSTLES LIMITED '
46
+ end
47
+
48
+ it "is read as UTF-8 from a stream handing over bytes" do
49
+ text = asic_register_text([['CAFÉ PTY LTD', '000000001', 'APTY', 'LMSH', 'PROP', 'REGD', '01/01/2000', '', '', '', '', 'Y', '0', '', '']]).b
50
+ record = records_of(text).first
51
+ _(record[:company_name]).must_equal 'CAFÉ PTY LTD'
52
+ _(record[:company_name].encoding).must_equal Encoding::UTF_8
53
+ end
54
+ end
55
+
56
+ it "counts the rows yielded" do
57
+ parser = DataGovAu::AsicCompanies::Parser.new(StringIO.new(asic_register_text))
58
+ _(parser.each_record{}.records_parsed).must_equal 4
59
+ end
60
+
61
+ it "yields nothing from a register holding only its header" do
62
+ _(records_of(asic_register_text([]))).must_equal []
63
+ end
64
+
65
+ describe "a register not laid out as ASIC writes it" do
66
+ it "stops where the header names other columns" do
67
+ header = DataGovAu::AsicCompanies::Parser::COLUMNS.keys.rotate
68
+ _(->{records_of(asic_register_text(header: header))}).must_raise DataGovAu::AsicCompanies::RegisterMalformed
69
+ end
70
+
71
+ it "stops where there is no header" do
72
+ _(->{records_of('')}).must_raise DataGovAu::AsicCompanies::RegisterMalformed
73
+ end
74
+
75
+ it "stops at a row with other than fifteen fields, naming its line" do
76
+ rows = asic_rows.dup.insert(1, asic_rows[1].first(14))
77
+ error = _(->{records_of(asic_register_text(rows))}).must_raise DataGovAu::AsicCompanies::RegisterMalformed
78
+ _(error.message).must_match(/line 3 has 14 fields/)
79
+ end
80
+ end
81
+ end
@@ -56,6 +56,13 @@ describe DataGovAu::AsicCompanies::Release do
56
56
  end
57
57
  end
58
58
 
59
+ it "finds its zips in its directory" do
60
+ Dir.mktmpdir do |directory|
61
+ release = asic_release_holding(directory)
62
+ _(release.zip_paths).must_equal [File.join(release.directory, 'company_202611.zip')]
63
+ end
64
+ end
65
+
59
66
  describe "the releases held" do
60
67
  it "are none where nothing has been fetched" do
61
68
  Dir.mktmpdir do |directory|
@@ -51,3 +51,28 @@ def stub_asic_peek(resource = asic_zip_resource, header = asic_zip_header)
51
51
  with(headers: {'Range' => "bytes=0-#{DataGovAu::AsicCompanies::ExtractDate::PEEK_LENGTH - 1}"}).
52
52
  to_return(status: 206, body: header)
53
53
  end
54
+
55
+ # Rows from the register of 20261124: a company under a former name and then its current one, a company deregistered with no ABN, and a name holding quotes.
56
+ def asic_rows
57
+ [
58
+ ['LOVINI HOLDINGS PTY LTD', '000000019', 'APTY', 'LMSH', 'PROP', 'REGD', '08/01/1990', '', 'NSW', '46869041', '', '', '89000000019', 'MONAKA PTY LTD', '28/01/2016'],
59
+ ['MONAKA PTY LTD', '000000019', 'APTY', 'LMSH', 'PROP', 'REGD', '08/01/1990', '', 'NSW', '46869041', '', 'Y', '89000000019', '', ''],
60
+ ['COMMONWEALTH PORTLAND CEMENT COMPANY PTY LTD', '000000260', 'APTY', 'LMSH', 'PROP', 'DRGD', '27/05/1907', '13/03/2026', 'NSW', '00010535', '', 'Y', '0', '', ''],
61
+ ['TUMUT BOWLING & RECREATION CLUB LTD. TRADING AS "CLUB TUMUT" LTD', '001001074', 'APUB', 'LMGT', 'ULSN', 'REGD', '12/05/1972', '', 'NSW', '14592147', '', 'Y', '62001001074', '', ''],
62
+ ]
63
+ end
64
+
65
+ # The register as ASIC writes it: a byte-order mark, then the header and each row tab-separated, every line ending CRLF.
66
+ def asic_register_text(rows = asic_rows, header: DataGovAu::AsicCompanies::Parser::COLUMNS.keys)
67
+ "" + ([header] + rows).collect{|fields| fields.join("\t") + "\r\n"}.join
68
+ end
69
+
70
+ # A release holding the register zipped, as the fetch leaves one.
71
+ def asic_release_holding(directory, date = Date.new(2026, 11, 24), text = asic_register_text)
72
+ release = DataGovAu::AsicCompanies::Release.new(asic_config_in(directory), date)
73
+ release.create_directory
74
+ Zip::File.open(File.join(release.directory, 'company_202611.zip'), create: true) do |zip|
75
+ zip.get_output_stream(ASIC_MEMBER){|io| io.write(text)}
76
+ end
77
+ release
78
+ end
@@ -24,7 +24,7 @@ describe DataGovAu::Dataset do
24
24
  _(DataGovAu::Catalogue.new.dataset('abn-bulk-extract').resources).must_equal []
25
25
  end
26
26
 
27
- it "gives up its entry as the catalogue gave it" do
27
+ it "returns its entry as the catalogue gave it" do
28
28
  _(dataset.to_h).must_equal package
29
29
  end
30
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_gov_au
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -9,6 +9,20 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: dsv
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.13'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '0.13'
12
26
  - !ruby/object:Gem::Dependency
13
27
  name: http.rb
14
28
  requirement: !ruby/object:Gem::Requirement
@@ -110,8 +124,8 @@ dependencies:
110
124
  description: Find a dataset through data.gov.au's CKAN catalogue by its name or id,
111
125
  read what the catalogue says of it and of each of its resources, and download a
112
126
  resource once, checked against the length the catalogue reports. Built on it, the
113
- Australian Business Register's weekly ABN bulk extract, each release fetched once
114
- and kept.
127
+ Australian Business Register's weekly ABN bulk extract and ASIC's weekly company
128
+ register, each release fetched once and kept, and read a record at a time.
115
129
  email: code@thoran.com
116
130
  executables: []
117
131
  extensions: []
@@ -141,8 +155,10 @@ files:
141
155
  - lib/DataGovAu/AsicCompanies.rb
142
156
  - lib/DataGovAu/AsicCompanies/Config.rb
143
157
  - lib/DataGovAu/AsicCompanies/Error.rb
158
+ - lib/DataGovAu/AsicCompanies/Extract.rb
144
159
  - lib/DataGovAu/AsicCompanies/ExtractDate.rb
145
160
  - lib/DataGovAu/AsicCompanies/Fetch.rb
161
+ - lib/DataGovAu/AsicCompanies/Parser.rb
146
162
  - lib/DataGovAu/AsicCompanies/Release.rb
147
163
  - lib/DataGovAu/Catalogue.rb
148
164
  - lib/DataGovAu/Dataset.rb
@@ -166,7 +182,9 @@ files:
166
182
  - test/DataGovAu/AbnBulkExtract/Release_test.rb
167
183
  - test/DataGovAu/AsicCompanies/Config_test.rb
168
184
  - test/DataGovAu/AsicCompanies/ExtractDate_test.rb
185
+ - test/DataGovAu/AsicCompanies/Extract_test.rb
169
186
  - test/DataGovAu/AsicCompanies/Fetch_test.rb
187
+ - test/DataGovAu/AsicCompanies/Parser_test.rb
170
188
  - test/DataGovAu/AsicCompanies/Release_test.rb
171
189
  - test/DataGovAu/AsicCompanies/helper.rb
172
190
  - test/DataGovAu/Catalogue_test.rb