metanorma-iho 1.4.3 → 1.4.5

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: 7e47e28ea024b8de6f8c7ffa8494f820dc0b085de8e8583fc68b05868dcd6ff8
4
- data.tar.gz: 34bf90352d30b8799e28fc1a2f36b68d38cc1bb178622a4c5d97a2e50572bf15
3
+ metadata.gz: 1f33ef5228d83dd32ae49aeebd1c33df8e80e0baed1f28c82c0ef4ab3e39ed2f
4
+ data.tar.gz: d8bc6786c13678a5196b5740c9244cc92158ab71405812e5b1361eda88a7e760
5
5
  SHA512:
6
- metadata.gz: b2c5c07e3394a6753824be091cc09cd81a77d1b0e89a58177d1394e2f3c158a0189dbbbb252eff00124db1ea37008f058a4abaf83e66c1c859b963ef9006f6c6
7
- data.tar.gz: 3c07104021dabcca471db89fde4ce63a4efb891160b3ded2369a53cd8b78730dd0902e1e5fb942b2dd101bc07ac4341a3878dc80e7e14d33779f2ff23836d44e
6
+ metadata.gz: 43e3cd5162ce846eb93cdc87cdbfff1138dcaada5509a56568f640549946f60165bb10557ecaf22e2b5b9dd6cfa10d4adba2432c52efb0662d2db5068ddad248
7
+ data.tar.gz: e478c371f40e813b25795fe652960efaddf0c575dde225f2c66e9ab5e4123cf00fca175e21f16b981e40ef362c1d124248d95b2ab9a9571797824ac104ec90c2
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Iho
3
- VERSION = "1.4.3".freeze
3
+ VERSION = "1.4.5".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
 
data/metanorma.yml CHANGED
@@ -68,6 +68,7 @@ doctypes:
68
68
  - specification
69
69
  - resolution
70
70
  - regulation
71
+ - report
71
72
  default_doctype: standard
72
73
  symbols_titles:
73
74
  - Abbreviations
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.3
4
+ version: 1.4.5
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-14 00:00:00.000000000 Z
11
+ date: 2026-11-15 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