metanorma-iho 1.4.3 → 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 +4 -4
- data/lib/isodoc/iho/xref.rb +6 -0
- data/lib/metanorma/iho/amendment/fold.rb +86 -0
- data/lib/metanorma/iho/amendment/record.rb +17 -0
- data/lib/metanorma/iho/amendment/state.rb +77 -0
- data/lib/metanorma/iho/amendment.rb +39 -0
- data/lib/metanorma/iho/version.rb +1 -1
- data/lib/metanorma/iho.rb +1 -0
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a3da18a8be2e40f16e10a09308744537a593c03099e4d395c9a4004273545877
|
|
4
|
+
data.tar.gz: 5a7f3901c4cc3dc78854ece02de179f4231ae1ed437d93efa9c9ce41b5f622f0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 916280944560415e3eb66ae34e509c1616effe6c585bd67daab375c63e95d82b35157e3210c0311bc62a281c7a76f1e1a4ad707fec72e3dc95215e2eec636f17
|
|
7
|
+
data.tar.gz: a0f6442cf4d0e9beab353784ff3824c1b3c3beaa7c837459d16dafd79262d05cd171b2d2f2e2ddeba19f7d12303c1629a6447d2e1f653e636d51e24ef15ed15b
|
data/lib/isodoc/iho/xref.rb
CHANGED
|
@@ -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
|
data/lib/metanorma/iho.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: metanorma-iho
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.4.
|
|
4
|
+
version: 1.4.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -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
|