metanorma-iho 1.4.2 → 1.4.4

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: 824725320798b47f87cd40d24f23c15cd4ab90be26fc64f57bad206e64582b37
4
- data.tar.gz: c44ebe0729cc65fae4f5fdc44cf7fc96e7803f0f2d86d2ba882dfc3428a3240a
3
+ metadata.gz: a3da18a8be2e40f16e10a09308744537a593c03099e4d395c9a4004273545877
4
+ data.tar.gz: 5a7f3901c4cc3dc78854ece02de179f4231ae1ed437d93efa9c9ce41b5f622f0
5
5
  SHA512:
6
- metadata.gz: 6f2bbdc06b70a035b7934587c0e5d970803a20da9e975561cbe435b93a3a2525183276ae2daf39c59c5eb6817bc4896a4092b64ed4025da049b08844490ee96e
7
- data.tar.gz: 24be541a07bbad79baee00bdc2bbabe6db706473e119693508bbc4f9f125c0c6f16ef4aa0790f8a8468c2143fcfcb1793cf2fb2a74a4976e93a671e300577a4f
6
+ metadata.gz: 916280944560415e3eb66ae34e509c1616effe6c585bd67daab375c63e95d82b35157e3210c0311bc62a281c7a76f1e1a4ad707fec72e3dc95215e2eec636f17
7
+ data.tar.gz: a0f6442cf4d0e9beab353784ff3824c1b3c3beaa7c837459d16dafd79262d05cd171b2d2f2e2ddeba19f7d12303c1629a6447d2e1f653e636d51e24ef15ed15b
data/Gemfile CHANGED
@@ -5,7 +5,6 @@ gemspec
5
5
 
6
6
  # canonical line: relaton 3 finals over the α engine line
7
7
  gem "pubid", "~> 2.0"
8
- gem "relaton-cli", "~> 3.0"
9
8
  gem "isodoc", "~> 3.7.9"
10
9
  gem "isodoc-i18n", github: "metanorma/isodoc-i18n", branch: "main"
11
10
  gem "metanorma-standoc", "~> 3.5.7"
@@ -142,6 +142,12 @@ module IsoDoc
142
142
 
143
143
  def middle_section_asset_names(doc)
144
144
  doc.xpath(ns(middle_sections)).each do |c|
145
+ # Flavors may declare multiple normative-reference titles
146
+ # (e.g. IALA normref_titles: References, Further reading), yielding
147
+ # several //bibliography/references[@normative='true'] elements.
148
+ # Section anchoring registers only the first normref match, so the
149
+ # remainder carry no anchor and have no label to hang assets from.
150
+ @anchors[c["id"]] or next
145
151
  hierarchical_asset_names(c, @anchors[c["id"]][:label])
146
152
  end
147
153
  end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Iho
5
+ module Amendment
6
+ # Pure transform reconstructing the publication state produced by
7
+ # applying amendment records in sequence up to a target amendment
8
+ # number.
9
+ #
10
+ # The transform is deterministic: records order by sequence with
11
+ # input order as tie-break, the input is never mutated, and repeated
12
+ # folds of the same input yield equal states.
13
+ module Fold
14
+ # Folds +records+ up to amendment +upto+ and returns the
15
+ # resulting {State}.
16
+ #
17
+ # @param records [Array<Record, Hash>] sequenced amendment records
18
+ # @param upto [Integer] target amendment number, >= 0 (0 is the
19
+ # base publication, with no records applied)
20
+ # @return [State]
21
+ def self.call(records, upto:)
22
+ validate_upto!(upto)
23
+ ordered = Array(records).each_with_index
24
+ .map { |record, index| [normalize(record), index] }
25
+ .sort_by { |record, index| [record.sequence, index] }
26
+ .map(&:first)
27
+ applied, excluded = ordered.partition { |record| record.sequence <= upto }
28
+ State.new(upto: upto, applied: applied, excluded: excluded)
29
+ end
30
+
31
+ # The highest amendment sequence present in +records+; 0 when no
32
+ # records are given. Upper bound for iterating publication states.
33
+ #
34
+ # @param records [Array<Record, Hash>]
35
+ # @return [Integer]
36
+ def self.max_sequence(records)
37
+ Array(records)
38
+ .map { |record| normalize(record).sequence }.max || 0
39
+ end
40
+
41
+ def self.validate_upto!(upto)
42
+ return if upto.is_a?(Integer) && upto >= 0
43
+
44
+ raise ArgumentError,
45
+ "amendment number must be a non-negative Integer, " \
46
+ "got #{upto.inspect}"
47
+ end
48
+
49
+ # Accepts {Record} instances and hashes. In the hash form,
50
+ # +anchor+ and +sequence+ are routing keys and every remaining key
51
+ # becomes record payload; top-level keys may be given as strings.
52
+ def self.normalize(record)
53
+ case record
54
+ when Record
55
+ build(anchor: record.anchor, sequence: record.sequence,
56
+ payload: (record.payload || {}).dup)
57
+ when Hash
58
+ entry = record.transform_keys { |key| key.is_a?(String) ? key.to_sym : key }
59
+ build(anchor: entry[:anchor], sequence: entry[:sequence],
60
+ payload: entry.except(:anchor, :sequence))
61
+ else
62
+ raise ArgumentError,
63
+ "amendment records must be Amendment::Record or Hash, " \
64
+ "got #{record.class}"
65
+ end
66
+ end
67
+
68
+ def self.build(anchor:, sequence:, payload: {})
69
+ unless anchor.is_a?(String) && !anchor.empty?
70
+ raise ArgumentError,
71
+ "amendment record needs a non-empty String anchor, " \
72
+ "got #{anchor.inspect}"
73
+ end
74
+ unless sequence.is_a?(Integer) && sequence >= 1
75
+ raise ArgumentError,
76
+ "amendment record for #{anchor.inspect} needs an " \
77
+ "Integer sequence >= 1, got #{sequence.inspect}"
78
+ end
79
+
80
+ Record.new(anchor: anchor, sequence: sequence,
81
+ payload: payload.freeze)
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Iho
5
+ module Amendment
6
+ # One amendment record: the amendment carrying it names the unit it
7
+ # touches (+anchor+, a stable unit identifier), its position in the
8
+ # amendment sequence (+sequence+, 1-based), and whatever descriptive
9
+ # payload the publisher models — effective date, approval, citation
10
+ # of the issuing communication, summary.
11
+ #
12
+ # The fold reads only +anchor+ and +sequence+; +payload+ passes
13
+ # through untouched for the presentation layer to consume.
14
+ Record = Struct.new(:anchor, :sequence, :payload, keyword_init: true)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Iho
5
+ module Amendment
6
+ # The publication state produced by {Fold}: which amendment records
7
+ # are applied at the target amendment number, which are excluded,
8
+ # and the per-unit views the presentation layer consumes.
9
+ #
10
+ # Instances are immutable: every collection is frozen at
11
+ # construction and all lookups are read-only. A unit with no applied
12
+ # record renders in its base form; a unit with applied records
13
+ # renders in the form given by its {State#effective} record.
14
+ class State
15
+ attr_reader :upto, :applied, :excluded
16
+
17
+ def initialize(upto:, applied:, excluded:)
18
+ @upto = upto
19
+ @applied = applied.freeze
20
+ @excluded = excluded.freeze
21
+ @effective = @applied.reverse_each
22
+ .each_with_object({}) { |record, hash| hash[record.anchor] ||= record }
23
+ .freeze
24
+ @anchors = @effective.keys.sort.freeze
25
+ @history = @applied.group_by(&:anchor)
26
+ .each_with_object({}) { |(anchor, records), hash| hash[anchor] = records.freeze }
27
+ .freeze
28
+ end
29
+
30
+ # Anchors carrying at least one applied record, sorted.
31
+ #
32
+ # @return [Array<String>]
33
+ def anchors
34
+ @anchors
35
+ end
36
+
37
+ # Whether +anchor+ carries at least one applied record, i.e. the
38
+ # unit is present in its amended form at this state.
39
+ #
40
+ # @param anchor [String]
41
+ # @return [Boolean]
42
+ def amended?(anchor)
43
+ @history.key?(anchor)
44
+ end
45
+
46
+ # The applied records for +anchor+, in sequence order; empty when
47
+ # the unit has no applied records (including unknown anchors).
48
+ #
49
+ # @param anchor [String]
50
+ # @return [Array<Record>]
51
+ def history(anchor)
52
+ @history[anchor] || []
53
+ end
54
+
55
+ # The latest applied record for +anchor+ — the at-N form of the
56
+ # unit; nil when the unit has no applied records.
57
+ #
58
+ # @param anchor [String]
59
+ # @return [Record, nil]
60
+ def effective(anchor)
61
+ @effective[anchor]
62
+ end
63
+
64
+ # Value equality on the publication content — the applied and
65
+ # excluded partitions. The target amendment number is provenance:
66
+ # targets beyond the last sequence yield the same publication
67
+ # state, so those folds compare equal.
68
+ #
69
+ # @return [Boolean]
70
+ def ==(other)
71
+ other.is_a?(State) &&
72
+ other.applied == applied && other.excluded == excluded
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Iho
5
+ # Amendment-state machinery: sequenced amendment records carried on
6
+ # the document model, folded up to a target amendment number into the
7
+ # publication state the presentation layer renders.
8
+ #
9
+ # The fold is a pure transform over the record set — no rendering, no
10
+ # mutation, no clock — so any state of the publication is
11
+ # reconstructible from the records alone.
12
+ module Amendment
13
+ autoload :Record, "metanorma/iho/amendment/record"
14
+ autoload :State, "metanorma/iho/amendment/state"
15
+ autoload :Fold, "metanorma/iho/amendment/fold"
16
+
17
+ # Applies +records+ in sequence up to amendment +upto+ and returns
18
+ # the resulting {State}. Amendment +0+ is the base publication: no
19
+ # records applied. Records whose sequence exceeds +upto+ are
20
+ # excluded; each touched unit renders in the form given by its
21
+ # latest applied record.
22
+ #
23
+ # @param records [Array<Record, Hash>] sequenced amendment records;
24
+ # hashes accept +:anchor+/:sequence top-level keys (strings or
25
+ # symbols), every other key becomes record payload
26
+ # @param upto [Integer] target amendment number, >= 0
27
+ # @return [State]
28
+ def self.fold(records, upto:)
29
+ Fold.call(records, upto: upto)
30
+ end
31
+
32
+ # The highest amendment sequence present in +records+; 0 when no
33
+ # records are given. Upper bound for iterating publication states.
34
+ def self.max_sequence(records)
35
+ Fold.max_sequence(records)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -10,16 +10,21 @@ module Metanorma
10
10
 
11
11
  def bibdata_docidentifier_i18n(isoxml)
12
12
  id, parts = bibdata_docidentifier_i18n_prep(isoxml)
13
- parts.empty? and return
13
+ (parts.empty? || id.nil?) and return
14
14
  id_alt = id.dup
15
15
  id.next = id_alt
16
- id_alt["type"] = "IHO-parent-document"
16
+ id["type"] and id_alt["type"] = "#{id["type"]}-parent-document"
17
17
  id_alt.delete("primary")
18
18
  bibdata_docidentifier_enhance(id, parts)
19
19
  end
20
20
 
21
21
  def bibdata_docidentifier_i18n_prep(isoxml)
22
- id = isoxml.at("//bibdata/docidentifier[@type = 'IHO']")
22
+ # Mutate the identifier the document actually carries
23
+ # (metanorma-iho#577): a document compiled under a taste carries
24
+ # that taste's organisation type on its primary docidentifier,
25
+ # so a hardcoded type string is not a legal match key.
26
+ id = isoxml.at("//bibdata/docidentifier[@primary = 'true']") ||
27
+ isoxml.at("//bibdata/docidentifier")
23
28
  parts = %w(appendixid annexid part supplementid)
24
29
  .each_with_object({}) do |w, m|
25
30
  dn = isoxml.at("//bibdata/ext/structuredidentifier/#{w}") and
@@ -15,6 +15,23 @@ module Metanorma
15
15
  Metanorma::Iho.configuration
16
16
  end
17
17
 
18
+ # A taste registers its own vocabulary through its metanorma.yml,
19
+ # handed to the converter as the :customize: document attribute
20
+ # (metanorma-iho#578). The generic implementation files it under
21
+ # the generic flavour's configuration, which nothing on this
22
+ # flavour's path reads: file it under this flavour's
23
+ # configuration instead, and re-register this flavour's
24
+ # processor. The taste's doctype vocabulary extends the base's
25
+ # rather than replacing it: a document of the base vocabulary
26
+ # stays legal under a taste that declares its own.
27
+ def read_config_file(path_to_config_file)
28
+ base_doctypes = configuration.doctypes || {}
29
+ configuration.set_default_values_from_yaml_file(path_to_config_file)
30
+ taste_doctypes = configuration.doctypes and
31
+ configuration.doctypes = base_doctypes.merge(taste_doctypes)
32
+ Metanorma::Registry.instance.register(Metanorma::Iho::Processor)
33
+ end
34
+
18
35
  # IHO M-3 (2026) development-stage vocabulary (metanorma-iho#553):
19
36
  # a `:status:` value may be the stage slug or its M-3 abbreviation;
20
37
  # both normalize to the slug with the abbreviation carried on the
@@ -17,6 +17,16 @@ module Metanorma
17
17
  end
18
18
  end
19
19
 
20
+ # The :urn: document attribute carries the document's URN; bibdata
21
+ # keeps it as a typed uri (metanorma-iho#579). Generating the URN
22
+ # through pubid belongs to the consuming taste; this is the
23
+ # generic attribute-to-bibdata propagation, inert when the
24
+ # attribute is absent.
25
+ def metadata_source(node, xml)
26
+ super
27
+ add_noko_elem(xml, "uri", node.attr("urn"), type: "urn")
28
+ end
29
+
20
30
  def metadata_ext(node, ext)
21
31
  # Compile probes run the converter on bare internal documents
22
32
  # without user attributes; only warn on real document headers.
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Iho
3
- VERSION = "1.4.2".freeze
3
+ VERSION = "1.4.4".freeze
4
4
  end
5
5
  end
data/lib/metanorma/iho.rb CHANGED
@@ -5,6 +5,7 @@ require "metanorma/iho/processor"
5
5
 
6
6
  module Metanorma
7
7
  module Iho
8
+ autoload :Amendment, "metanorma/iho/amendment"
8
9
  autoload :CitationStyle, "metanorma/iho/citation_style"
9
10
  autoload :M3Stages, "metanorma/iho/m3_stages"
10
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-iho
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-06 00:00:00.000000000 Z
11
+ date: 2026-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metanorma-generic
@@ -225,6 +225,10 @@ files:
225
225
  - lib/isodoc/iho/xref.rb
226
226
  - lib/metanorma-iho.rb
227
227
  - lib/metanorma/iho.rb
228
+ - lib/metanorma/iho/amendment.rb
229
+ - lib/metanorma/iho/amendment/fold.rb
230
+ - lib/metanorma/iho/amendment/record.rb
231
+ - lib/metanorma/iho/amendment/state.rb
228
232
  - lib/metanorma/iho/basicdoc.rng
229
233
  - lib/metanorma/iho/biblio-standoc.rng
230
234
  - lib/metanorma/iho/biblio.rng