pubid 2.0.0.pre.alpha.3 → 2.0.0.pre.alpha.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.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pubid/amca/identifier.rb +4 -23
  3. data/lib/pubid/amca/identifiers/base.rb +67 -30
  4. data/lib/pubid/amca/identifiers/interpretation.rb +0 -4
  5. data/lib/pubid/amca/identifiers/publication.rb +0 -4
  6. data/lib/pubid/amca/identifiers/standard.rb +0 -4
  7. data/lib/pubid/amca/renderer.rb +1 -1
  8. data/lib/pubid/amca/urn_generator.rb +2 -1
  9. data/lib/pubid/api/builder.rb +4 -0
  10. data/lib/pubid/api/identifier.rb +5 -1
  11. data/lib/pubid/api/identifiers/base.rb +2 -12
  12. data/lib/pubid/api/identifiers/mpms.rb +0 -4
  13. data/lib/pubid/api/identifiers/typeless_standard.rb +0 -3
  14. data/lib/pubid/api/single_identifier.rb +5 -8
  15. data/lib/pubid/ashrae/identifier.rb +7 -22
  16. data/lib/pubid/ashrae/identifiers/base.rb +28 -17
  17. data/lib/pubid/ashrae/parser.rb +4 -0
  18. data/lib/pubid/ashrae.rb +4 -0
  19. data/lib/pubid/asme/single_identifier.rb +3 -1
  20. data/lib/pubid/astm/single_identifier.rb +3 -1
  21. data/lib/pubid/bsi/identifier.rb +5 -31
  22. data/lib/pubid/bsi/identifiers/addendum_document.rb +0 -4
  23. data/lib/pubid/bsi/identifiers/adopted_european_norm.rb +0 -4
  24. data/lib/pubid/bsi/identifiers/adopted_international_standard.rb +0 -4
  25. data/lib/pubid/bsi/identifiers/aerospace_standard.rb +0 -3
  26. data/lib/pubid/bsi/identifiers/amendment.rb +0 -4
  27. data/lib/pubid/bsi/identifiers/british_industrial_practice.rb +0 -3
  28. data/lib/pubid/bsi/identifiers/bundled_identifier.rb +2 -5
  29. data/lib/pubid/bsi/identifiers/committee_document.rb +0 -3
  30. data/lib/pubid/bsi/identifiers/consolidated_identifier.rb +2 -5
  31. data/lib/pubid/bsi/identifiers/corrigendum.rb +0 -4
  32. data/lib/pubid/bsi/identifiers/detailed_specification.rb +0 -3
  33. data/lib/pubid/bsi/identifiers/disc.rb +0 -3
  34. data/lib/pubid/bsi/identifiers/draft_document.rb +0 -3
  35. data/lib/pubid/bsi/identifiers/electronic_book.rb +0 -3
  36. data/lib/pubid/bsi/identifiers/expert_commentary.rb +0 -4
  37. data/lib/pubid/bsi/identifiers/explanatory_supplement.rb +0 -3
  38. data/lib/pubid/bsi/identifiers/flex.rb +0 -3
  39. data/lib/pubid/bsi/identifiers/handbook.rb +0 -3
  40. data/lib/pubid/bsi/identifiers/index.rb +0 -3
  41. data/lib/pubid/bsi/identifiers/method.rb +0 -3
  42. data/lib/pubid/bsi/identifiers/national_annex.rb +0 -3
  43. data/lib/pubid/bsi/identifiers/practice_guide.rb +0 -3
  44. data/lib/pubid/bsi/identifiers/publicly_available_specification.rb +0 -3
  45. data/lib/pubid/bsi/identifiers/published_document.rb +0 -3
  46. data/lib/pubid/bsi/identifiers/section.rb +0 -3
  47. data/lib/pubid/bsi/identifiers/set.rb +2 -5
  48. data/lib/pubid/bsi/identifiers/standalone_amendment.rb +0 -3
  49. data/lib/pubid/bsi/identifiers/supplement_document.rb +0 -4
  50. data/lib/pubid/bsi/identifiers/supplementary_index.rb +0 -3
  51. data/lib/pubid/bsi/identifiers/technical_specification.rb +0 -3
  52. data/lib/pubid/bsi/identifiers/test_method.rb +0 -3
  53. data/lib/pubid/bsi/identifiers/value_added_publication.rb +0 -4
  54. data/lib/pubid/bsi/single_identifier.rb +32 -13
  55. data/lib/pubid/bsi.rb +8 -1
  56. data/lib/pubid/ccsds/identifier.rb +2 -14
  57. data/lib/pubid/cen_cenelec/identifier.rb +10 -8
  58. data/lib/pubid/cen_cenelec/identifiers/adopted_european_norm.rb +0 -4
  59. data/lib/pubid/cen_cenelec/identifiers/amendment.rb +0 -4
  60. data/lib/pubid/cen_cenelec/identifiers/base.rb +2 -9
  61. data/lib/pubid/cen_cenelec/identifiers/consolidated_identifier.rb +0 -4
  62. data/lib/pubid/cen_cenelec/identifiers/corrigendum.rb +0 -4
  63. data/lib/pubid/cen_cenelec/identifiers/european_prestandard.rb +0 -3
  64. data/lib/pubid/cen_cenelec/identifiers/fragment.rb +0 -4
  65. data/lib/pubid/cen_cenelec/single_identifier.rb +4 -7
  66. data/lib/pubid/cen_cenelec.rb +4 -0
  67. data/lib/pubid/cie/identifier.rb +4 -0
  68. data/lib/pubid/cie/single_identifier.rb +4 -4
  69. data/lib/pubid/cie.rb +4 -0
  70. data/lib/pubid/csa/identifier.rb +10 -1
  71. data/lib/pubid/csa/identifiers/base.rb +0 -3
  72. data/lib/pubid/csa/identifiers/cec.rb +0 -4
  73. data/lib/pubid/csa/identifiers/series.rb +0 -4
  74. data/lib/pubid/csa/single_identifier.rb +1 -1
  75. data/lib/pubid/csa.rb +4 -0
  76. data/lib/pubid/etsi/components/code.rb +1 -7
  77. data/lib/pubid/etsi/components/version.rb +0 -5
  78. data/lib/pubid/etsi/identifier.rb +4 -12
  79. data/lib/pubid/etsi/identifiers/base.rb +31 -24
  80. data/lib/pubid/etsi/identifiers/supplement_identifier.rb +0 -3
  81. data/lib/pubid/etsi.rb +3 -1
  82. data/lib/pubid/identifier.rb +90 -1
  83. data/lib/pubid/idf/identifier.rb +4 -0
  84. data/lib/pubid/idf.rb +4 -0
  85. data/lib/pubid/iec/identifier.rb +14 -14
  86. data/lib/pubid/iec/identifiers/base.rb +0 -4
  87. data/lib/pubid/iec/identifiers/consolidated_identifier.rb +0 -4
  88. data/lib/pubid/iec/identifiers/fragment_identifier.rb +1 -5
  89. data/lib/pubid/iec/identifiers/sheet_identifier.rb +1 -5
  90. data/lib/pubid/iec/identifiers/test_report_form.rb +0 -3
  91. data/lib/pubid/iec/identifiers/vap_identifier.rb +1 -5
  92. data/lib/pubid/iec/identifiers/working_document.rb +0 -4
  93. data/lib/pubid/iec.rb +4 -0
  94. data/lib/pubid/ieee/identifier.rb +5 -17
  95. data/lib/pubid/ieee/identifiers/adopted_standard.rb +0 -4
  96. data/lib/pubid/ieee/identifiers/base.rb +223 -201
  97. data/lib/pubid/ieee/identifiers/conformance_identifier.rb +0 -4
  98. data/lib/pubid/ieee/identifiers/corrigendum.rb +0 -4
  99. data/lib/pubid/ieee/identifiers/csa_dual_published.rb +0 -4
  100. data/lib/pubid/ieee/identifiers/dual_identifier.rb +0 -4
  101. data/lib/pubid/ieee/identifiers/dual_published.rb +0 -4
  102. data/lib/pubid/ieee/identifiers/iec_ieee_copublished.rb +0 -4
  103. data/lib/pubid/ieee/identifiers/interpretation_identifier.rb +0 -4
  104. data/lib/pubid/ieee/identifiers/multi_numbered_identifier.rb +0 -4
  105. data/lib/pubid/ieee/identifiers/parenthetical_identifier.rb +0 -4
  106. data/lib/pubid/ieee/identifiers/redlined_standard.rb +0 -4
  107. data/lib/pubid/ieee/identifiers/si_standard.rb +0 -4
  108. data/lib/pubid/ieee.rb +4 -0
  109. data/lib/pubid/iho/identifier.rb +7 -25
  110. data/lib/pubid/iho/identifiers/base.rb +62 -68
  111. data/lib/pubid/iho.rb +3 -1
  112. data/lib/pubid/iso/identifier.rb +15 -14
  113. data/lib/pubid/iso/single_identifier.rb +0 -4
  114. data/lib/pubid/iso.rb +4 -0
  115. data/lib/pubid/itu/components/code.rb +1 -7
  116. data/lib/pubid/itu/components/sector.rb +15 -4
  117. data/lib/pubid/itu/components/series.rb +0 -4
  118. data/lib/pubid/itu/identifier.rb +4 -18
  119. data/lib/pubid/itu/identifiers/base.rb +124 -122
  120. data/lib/pubid/itu.rb +3 -1
  121. data/lib/pubid/jcgm/identifiers/amendment.rb +0 -4
  122. data/lib/pubid/jcgm/identifiers/gum_guide.rb +0 -4
  123. data/lib/pubid/jcgm/single_identifier.rb +0 -4
  124. data/lib/pubid/jis/identifier.rb +2 -14
  125. data/lib/pubid/nist/identifier.rb +8 -23
  126. data/lib/pubid/nist/identifiers/base.rb +553 -544
  127. data/lib/pubid/nist/preprocessor.rb +12 -0
  128. data/lib/pubid/nist.rb +4 -0
  129. data/lib/pubid/oiml/builder.rb +21 -3
  130. data/lib/pubid/oiml/components/code.rb +7 -0
  131. data/lib/pubid/oiml/identifier.rb +44 -0
  132. data/lib/pubid/oiml/identifiers/annex.rb +10 -1
  133. data/lib/pubid/oiml/identifiers/errata.rb +15 -0
  134. data/lib/pubid/oiml/identifiers.rb +1 -1
  135. data/lib/pubid/oiml/parser.rb +59 -12
  136. data/lib/pubid/oiml/renderer.rb +27 -17
  137. data/lib/pubid/oiml/single_identifier.rb +58 -0
  138. data/lib/pubid/oiml/supplement_identifier.rb +30 -1
  139. data/lib/pubid/plateau/identifier.rb +4 -21
  140. data/lib/pubid/plateau/identifiers/base.rb +45 -36
  141. data/lib/pubid/plateau/identifiers/handbook.rb +0 -4
  142. data/lib/pubid/plateau/identifiers/technical_report.rb +0 -4
  143. data/lib/pubid/plateau/supplement_identifier.rb +0 -4
  144. data/lib/pubid/sae/identifier.rb +4 -12
  145. data/lib/pubid/sae/identifiers/base.rb +26 -17
  146. data/lib/pubid/version.rb +1 -1
  147. data/lib/pubid.rb +18 -2
  148. data/lib/tasks/export.rake +6 -5
  149. metadata +3 -4
  150. data/lib/pubid/identifier_facade.rb +0 -114
  151. data/lib/pubid/oiml/identifiers/base.rb +0 -21
@@ -10,9 +10,6 @@ module Pubid
10
10
  web: :electronic_book, title: "Electronic Publication", short: "EP" }
11
11
  end
12
12
 
13
- def to_s(lang: :en, lang_single: false)
14
- render(format: :human, lang: lang, lang_single: lang_single)
15
- end
16
13
  end
17
14
  end
18
15
  end
@@ -14,10 +14,6 @@ module Pubid
14
14
  attribute :format, :string # "full", "abbr", "abbr_with_topic"
15
15
  attribute :topic, :string # e.g., "Fire"
16
16
 
17
- def to_s
18
- render(format: :human)
19
- end
20
-
21
17
  def publisher
22
18
  base_identifier&.publisher
23
19
  end
@@ -29,9 +29,6 @@ module Pubid
29
29
  }
30
30
  end
31
31
 
32
- def to_s(lang: :en, lang_single: false)
33
- render(format: :human, lang: lang, lang_single: lang_single)
34
- end
35
32
  end
36
33
  end
37
34
  end
@@ -20,9 +20,6 @@ module Pubid
20
20
  { key: :flex, title: "BSI Flex", short: "BSI Flex" }
21
21
  end
22
22
 
23
- def to_s(lang: :en, lang_single: false)
24
- render(format: :human, lang: lang, lang_single: lang_single)
25
- end
26
23
  end
27
24
  end
28
25
  end
@@ -19,9 +19,6 @@ module Pubid
19
19
  }
20
20
  end
21
21
 
22
- def to_s(lang: :en, lang_single: false)
23
- render(format: :human, lang: lang, lang_single: lang_single)
24
- end
25
22
  end
26
23
  end
27
24
  end
@@ -24,9 +24,6 @@ module Pubid
24
24
  { key: :index, title: "Index", short: "Index" }
25
25
  end
26
26
 
27
- def to_s(lang: :en, lang_single: false)
28
- render(format: :human, lang: lang, lang_single: lang_single)
29
- end
30
27
  end
31
28
  end
32
29
  end
@@ -29,9 +29,6 @@ module Pubid
29
29
  { key: :method, title: "Method", short: "Method" }
30
30
  end
31
31
 
32
- def to_s(lang: :en, lang_single: false)
33
- render(format: :human, lang: lang, lang_single: lang_single)
34
- end
35
32
  end
36
33
  end
37
34
  end
@@ -42,9 +42,6 @@ module Pubid
42
42
  base_doc&.subpart || super
43
43
  end
44
44
 
45
- def to_s(lang: :en, lang_single: false)
46
- render(format: :human, lang: lang, lang_single: lang_single)
47
- end
48
45
  end
49
46
  end
50
47
  end
@@ -16,9 +16,6 @@ module Pubid
16
16
  }
17
17
  end
18
18
 
19
- def to_s(lang: :en, lang_single: false)
20
- render(format: :human, lang: lang, lang_single: lang_single)
21
- end
22
19
  end
23
20
  end
24
21
  end
@@ -21,9 +21,6 @@ module Pubid
21
21
  web: :publicly_available_specification, title: "Publicly Available Specification", short: "PAS" }
22
22
  end
23
23
 
24
- def to_s(lang: :en, lang_single: false)
25
- render(format: :human, lang: lang, lang_single: lang_single)
26
- end
27
24
  end
28
25
  end
29
26
  end
@@ -21,9 +21,6 @@ module Pubid
21
21
  web: :published_document, title: "Published Document", short: "PD" }
22
22
  end
23
23
 
24
- def to_s(lang: :en, lang_single: false)
25
- render(format: :human, lang: lang, lang_single: lang_single)
26
- end
27
24
  end
28
25
  end
29
26
  end
@@ -26,9 +26,6 @@ module Pubid
26
26
  { key: :section, title: "Section", short: "Section" }
27
27
  end
28
28
 
29
- def to_s(lang: :en, lang_single: false)
30
- render(format: :human, lang: lang, lang_single: lang_single)
31
- end
32
29
  end
33
30
  end
34
31
  end
@@ -13,13 +13,10 @@ module Pubid
13
13
  # BS ISO 20400 + BS ISO 44001+BS ISO 44002
14
14
  # BS ISO 9001+BS ISO 14001
15
15
  class Set < SingleIdentifier
16
- attribute :identifiers, ::Pubid::Identifier, collection: true, polymorphic: true
16
+ attribute :identifiers, ::Pubid::Identifier, collection: true,
17
+ polymorphic: true
17
18
  attribute :separators, :string, collection: true # Should all be " + "
18
19
 
19
- def to_s(lang: :en, lang_single: false)
20
- render(format: :human, lang: lang, lang_single: lang_single)
21
- end
22
-
23
20
  def <=>(other)
24
21
  return nil unless other.is_a?(Set)
25
22
 
@@ -25,9 +25,6 @@ module Pubid
25
25
  { key: :standalone_amendment, title: "Amendment", short: "AMD" }
26
26
  end
27
27
 
28
- def to_s(lang: :en, lang_single: false)
29
- render(format: :human, lang: lang, lang_single: lang_single)
30
- end
31
28
  end
32
29
  end
33
30
  end
@@ -20,10 +20,6 @@ module Pubid
20
20
  ":"
21
21
  } # Separator before Supplement (":" or " ")
22
22
 
23
- def to_s
24
- render(format: :human)
25
- end
26
-
27
23
  def publisher
28
24
  base_identifier&.publisher
29
25
  end
@@ -29,9 +29,6 @@ module Pubid
29
29
  }
30
30
  end
31
31
 
32
- def to_s(lang: :en, lang_single: false)
33
- render(format: :human, lang: lang, lang_single: lang_single)
34
- end
35
32
  end
36
33
  end
37
34
  end
@@ -28,9 +28,6 @@ module Pubid
28
28
  web: :technical_specification, title: "Technical Specification", short: "TS" }
29
29
  end
30
30
 
31
- def to_s(lang: :en, lang_single: false)
32
- render(format: :human, lang: lang, lang_single: lang_single)
33
- end
34
31
  end
35
32
  end
36
33
  end
@@ -29,9 +29,6 @@ module Pubid
29
29
  { key: :test_method, title: "Test Method", short: "BS" }
30
30
  end
31
31
 
32
- def to_s(lang: :en, lang_single: false)
33
- render(format: :human, lang: lang, lang_single: lang_single)
34
- end
35
32
  end
36
33
  end
37
34
  end
@@ -15,10 +15,6 @@ module Pubid
15
15
  attribute :base_identifier, ::Pubid::Identifier, polymorphic: true
16
16
  attribute :format, :string, values: ["PDF", "TC", "BOOK"]
17
17
 
18
- def to_s(lang: :en, lang_single: false)
19
- render(format: :human, lang: lang, lang_single: lang_single)
20
- end
21
-
22
18
  # Delegate common attributes to base_identifier
23
19
  def publisher
24
20
  base_identifier&.publisher
@@ -2,15 +2,34 @@
2
2
 
3
3
  module Pubid
4
4
  module Bsi
5
- class SingleIdentifier < Pubid::Identifier
6
- # Identity for the Pubid::Bsi::Identifier facade: SingleIdentifier is the
7
- # common ancestor of every concrete BSI identifier, so including the
8
- # facade module here makes them all `is_a?(Pubid::Bsi::Identifier)`.
9
- include Pubid::Bsi::Identifier
5
+ # BSI base class. Canonical name Pubid::Bsi::Identifier; SingleIdentifier is a
6
+ # back-compat alias (BSI's common ancestor there is no Identifiers::Base).
7
+ # Every concrete BSI identifier descends from it, so they are all
8
+ # `is_a?(Pubid::Bsi::Identifier)` natively and get the shared polymorphic
9
+ # `from_hash` (no facade needed).
10
+ class Identifier < ::Pubid::Identifier
11
+ def self.parse(string)
12
+ if string.length > Pubid::MAX_INPUT_LENGTH
13
+ raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE
14
+ end
15
+
16
+ # Delegate to IEC for bare IEC identifiers. This handles IEC-specific
17
+ # features like VAP suffixes (CSV, RLV, etc.) and consolidated
18
+ # supplements (+AMD1:2001).
19
+ if string.match?(/\bIEC\b/) &&
20
+ (string.match?(/\s+(CSV|CMV|RLV|SER|EXV|PAC|PRV)\b/) ||
21
+ string.match?(/\+AMD\d+:/) ||
22
+ string.match?(/\+COR\d+:/))
23
+ return Pubid::Iec.parse(string)
24
+ end
25
+
26
+ parser = Parser.new
10
27
 
11
- # Generate URN for this identifier
12
- #
13
- # @return [String] URN representation
28
+ parsed = parser.parse(string)
29
+ Builder.build(parsed)
30
+ rescue Parslet::ParseFailed => e
31
+ raise StandardError, "Failed to parse '#{string}': #{e.message}"
32
+ end
14
33
 
15
34
  attribute :publisher, Bsi::Components::Publisher, default: -> {
16
35
  Bsi::Components::Publisher.new(body: "BS")
@@ -34,12 +53,8 @@ module Pubid
34
53
  attribute :explicit_publisher, :boolean, default: -> { false }
35
54
  attribute :space_separated_part, :boolean, default: -> { false }
36
55
 
37
- def to_s(lang: :en, lang_single: false)
38
- render(format: :human, lang: lang, lang_single: lang_single)
39
- end
40
-
41
56
  def <=>(other)
42
- return nil unless other.is_a?(SingleIdentifier)
57
+ return nil unless other.is_a?(Pubid::Bsi::Identifier)
43
58
 
44
59
  # Compare by number first
45
60
  num_cmp = number.to_s <=> other.number.to_s
@@ -61,5 +76,9 @@ module Pubid
61
76
  end
62
77
  end
63
78
  end
79
+
80
+ # Backward-compatible alias: BSI's base class is Pubid::Bsi::Identifier.
81
+ # Concrete types declared as `< SingleIdentifier` continue to work.
82
+ SingleIdentifier = Identifier
64
83
  end
65
84
  end
data/lib/pubid/bsi.rb CHANGED
@@ -12,7 +12,10 @@ module Pubid
12
12
  autoload :Builder, "#{__dir__}/bsi/builder"
13
13
  autoload :Identifier, "#{__dir__}/bsi/identifier"
14
14
  autoload :Identifiers, "#{__dir__}/bsi/identifiers"
15
- autoload :Model, "#{__dir__}/bsi/model"
15
+ # NOTE: bsi/model.rb is legacy/unused (nothing references Pubid::Bsi::Model)
16
+ # and defines a conflicting `class Identifier < Lutaml::Model::Serializable`.
17
+ # It is intentionally NOT autoloaded so it can never clash with the real
18
+ # Pubid::Bsi::Identifier (single_identifier.rb).
16
19
  autoload :Parser, "#{__dir__}/bsi/parser"
17
20
  autoload :Renderer, "#{__dir__}/bsi/renderer"
18
21
  autoload :SingleIdentifier, "#{__dir__}/bsi/single_identifier"
@@ -203,6 +206,10 @@ module Pubid
203
206
  ].freeze
204
207
 
205
208
  def self.parse(string)
209
+ if string.length > Pubid::MAX_INPUT_LENGTH
210
+ raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE
211
+ end
212
+
206
213
  Identifier.parse(string)
207
214
  end
208
215
 
@@ -62,20 +62,8 @@ module Pubid
62
62
  raise "Failed to parse CCSDS identifier '#{identifier}': #{e.message}"
63
63
  end
64
64
 
65
- # Dispatch deserialization to the concrete class named by the stored
66
- # `_type`, so `from_hash` rebuilds a Corrigendum rather than a bare root
67
- # (lutaml resolves `_type` only for validation, not instantiation).
68
- # Mirrors Pubid::Jis::Identifier.from_hash. The `klass == self` guard lets
69
- # the matched subclass fall through to lutaml's inherited from_hash.
70
- def self.from_hash(data, options = {})
71
- type = data["_type"] || data[:_type]
72
- klass_name = CCSDS_TYPE_MAP[type]
73
- if klass_name
74
- klass = Object.const_get(klass_name)
75
- return klass.from_hash(data, options) unless klass == self
76
- end
77
- super
78
- end
65
+ # from_hash is the shared polymorphic dispatch on Pubid::Identifier.
66
+ # CCSDS_TYPE_MAP remains as the key_value polymorphic_map.
79
67
  end
80
68
  end
81
69
  end
@@ -1,16 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
-
4
3
  module Pubid
5
4
  module CenCenelec
6
- # `extend Pubid::IdentifierFacade` adds polymorphic `from_hash` and pairs
7
- # with `include Pubid::CenCenelec::Identifier` in Identifiers::Base for
8
- # identity (`is_a?`/`===`), so a consumer handed this module can deserialize
9
- # and identity-check CEN/CENELEC ids through it.
10
- module Identifier
11
- extend Pubid::IdentifierFacade
12
-
5
+ # Common base class for all CEN/CENELEC identifiers. CEN/CENELEC has a split
6
+ # hierarchy some concrete types descend from Identifiers::Base, others from
7
+ # SingleIdentifier so this class is the shared parent of BOTH, making every
8
+ # CEN/CENELEC identifier `is_a?(Pubid::CenCenelec::Identifier)` natively (and
9
+ # giving them the shared polymorphic `from_hash`). No facade needed.
10
+ class Identifier < ::Pubid::Identifier
13
11
  def self.parse(identifier)
12
+ if identifier.length > Pubid::MAX_INPUT_LENGTH
13
+ raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE
14
+ end
15
+
14
16
  parsed = Parser.parse(identifier)
15
17
  Builder.new.build(parsed)
16
18
  rescue Parslet::ParseFailed => e
@@ -19,10 +19,6 @@ module Pubid
19
19
  nil
20
20
  end
21
21
 
22
- def to_s(**opts)
23
- render(format: :human, **opts)
24
- end
25
-
26
22
  # Delegate common methods to adopted identifier
27
23
  def number
28
24
  adopted_identifier&.number
@@ -10,10 +10,6 @@ module Pubid
10
10
  attribute :amendment_number, :string
11
11
  attribute :amendment_year, :integer
12
12
 
13
- def to_s(**opts)
14
- render(format: :human, **opts)
15
- end
16
-
17
13
  def publisher
18
14
  base_identifier&.publisher
19
15
  end
@@ -3,12 +3,9 @@
3
3
  module Pubid
4
4
  module CenCenelec
5
5
  module Identifiers
6
- # Base CEN identifier
6
+ # Base CEN identifier (one of two roots; see Pubid::CenCenelec::Identifier).
7
7
  # Format: {PUBLISHER} NUMBER[-PART]:YEAR
8
- class Base < Pubid::Identifier
9
- # Identity for the Pubid::CenCenelec::Identifier facade (see its comment).
10
- include Pubid::CenCenelec::Identifier
11
-
8
+ class Base < Pubid::CenCenelec::Identifier
12
9
  # Generate URN for this identifier
13
10
  #
14
11
  # @return [String] URN representation
@@ -23,10 +20,6 @@ module Pubid
23
20
  attribute :adopted_identifier, Base, polymorphic: true # Nested identifier object (ISO, IEC, etc.)
24
21
  attribute :edition, :string # Edition number
25
22
 
26
- def to_s(**opts)
27
- render(format: :human, **opts)
28
- end
29
-
30
23
  def ==(other)
31
24
  return false unless other.is_a?(Base)
32
25
 
@@ -8,10 +8,6 @@ module Pubid
8
8
  class ConsolidatedIdentifier < Base
9
9
  attribute :identifiers, Base, polymorphic: true, collection: true
10
10
 
11
- def to_s(**opts)
12
- render(format: :human, **opts)
13
- end
14
-
15
11
  # Delegate to first identifier (base document)
16
12
  def publisher
17
13
  identifiers&.first&.publisher
@@ -11,10 +11,6 @@ module Pubid
11
11
  attribute :corrigendum_year, :integer
12
12
  attribute :corrigendum_month, :string
13
13
 
14
- def to_s(**opts)
15
- render(format: :human, **opts)
16
- end
17
-
18
14
  def publisher
19
15
  base_identifier&.publisher
20
16
  end
@@ -25,9 +25,6 @@ module Pubid
25
25
  web: :european_prestandard, title: "European Prestandard", short: "ENV" }
26
26
  end
27
27
 
28
- def to_s(lang: :en, lang_single: false, **opts)
29
- render(format: :human, lang: lang, lang_single: lang_single, **opts)
30
- end
31
28
  end
32
29
  end
33
30
  end
@@ -9,10 +9,6 @@ module Pubid
9
9
  attribute :base_identifier, Amendment
10
10
  attribute :fragment_number, :string
11
11
 
12
- def to_s(**opts)
13
- render(format: :human, **opts)
14
- end
15
-
16
12
  def publisher
17
13
  base_identifier&.base_identifier&.publisher
18
14
  end
@@ -2,13 +2,10 @@
2
2
 
3
3
  module Pubid
4
4
  module CenCenelec
5
- class SingleIdentifier < Pubid::Identifier
6
- # Identity for the Pubid::CenCenelec::Identifier facade. CEN/CENELEC
7
- # identifiers split between two roots (Identifiers::Base and this
8
- # SingleIdentifier), both direct subclasses of Pubid::Identifier, so the
9
- # facade module is included into each to cover every concrete type.
10
- include Pubid::CenCenelec::Identifier
11
-
5
+ # The second of CEN/CENELEC's two identifier roots (the other is
6
+ # Identifiers::Base); both descend from Pubid::CenCenelec::Identifier so every
7
+ # concrete type is `is_a?` it.
8
+ class SingleIdentifier < Pubid::CenCenelec::Identifier
12
9
  attribute :publisher, Components::Publisher, default: -> {
13
10
  Components::Publisher.new(body: "EN")
14
11
  }
@@ -141,6 +141,10 @@ module Pubid
141
141
  ).freeze
142
142
 
143
143
  def self.parse(identifier)
144
+ if identifier.length > Pubid::MAX_INPUT_LENGTH
145
+ raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE
146
+ end
147
+
144
148
  CenCenelec::Identifier.parse(identifier)
145
149
  end
146
150
 
@@ -11,6 +11,10 @@ module Pubid
11
11
  attribute :style, :string # "legacy" or "current"
12
12
 
13
13
  def self.parse(input)
14
+ if input.length > Pubid::MAX_INPUT_LENGTH
15
+ raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE
16
+ end
17
+
14
18
  parsed = Parser.parse(input)
15
19
  builder = Builder.new
16
20
  builder.build(parsed, original_string: input)
@@ -18,10 +18,10 @@ module Pubid
18
18
  # - Identical (identical to ISO publications)
19
19
  # - TutorialBundle (tutorial bundles)
20
20
  class SingleIdentifier < Identifier
21
- # CIE uses a fixed publisher string
22
- def publisher
23
- "CIE"
24
- end
21
+ # Stored as a plain string (always "CIE") so it round-trips through
22
+ # to_hash/from_hash. Was a `def publisher` method, which made lutaml
23
+ # serialize a String against the Components::Publisher attribute and raise.
24
+ attribute :publisher, :string, default: -> { "CIE" }
25
25
 
26
26
  attribute :year, :string
27
27
  attribute :date_separator, :string # "dash" or "colon"
data/lib/pubid/cie.rb CHANGED
@@ -19,6 +19,10 @@ module Pubid
19
19
  # Main entry point for CIE identifiers
20
20
  # Delegates to Identifier.parse
21
21
  def self.parse(input)
22
+ if input.length > Pubid::MAX_INPUT_LENGTH
23
+ raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE
24
+ end
25
+
22
26
  Identifier.parse(input)
23
27
  end
24
28
 
@@ -2,8 +2,17 @@
2
2
 
3
3
  module Pubid
4
4
  module Csa
5
- class Identifier
5
+ # Common base class for all CSA identifiers. SingleIdentifier (and the
6
+ # concrete Identifiers::* types through it) descends from it, so every CSA
7
+ # identifier is `is_a?(Pubid::Csa::Identifier)` natively and gets the shared
8
+ # polymorphic `from_hash`. (The Wrapper/Composite container models are
9
+ # separate Lutaml::Model types, not identifiers.)
10
+ class Identifier < ::Pubid::Identifier
6
11
  def self.parse(input)
12
+ if input.length > Pubid::MAX_INPUT_LENGTH
13
+ raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE
14
+ end
15
+
7
16
  # Filter out comments
8
17
  return nil if input.start_with?("#")
9
18
 
@@ -4,9 +4,6 @@ module Pubid
4
4
  module Csa
5
5
  module Identifiers
6
6
  class Base < SingleIdentifier
7
- def to_s(**opts)
8
- render(format: :human, **opts)
9
- end
10
7
  end
11
8
  end
12
9
  end
@@ -20,10 +20,6 @@ module Pubid
20
20
 
21
21
  @code ||= Components::Code.new(value: "#{cec_part.value}-#{no_number.value}")
22
22
  end
23
-
24
- def to_s(**opts)
25
- render(format: :human, **opts)
26
- end
27
23
  end
28
24
  end
29
25
  end
@@ -17,10 +17,6 @@ module Pubid
17
17
  class Series < Base
18
18
  # Series prefix (MH, RV, etc.) - optional
19
19
  attribute :series_prefix, :string
20
-
21
- def to_s(**opts)
22
- render(format: :human, **opts)
23
- end
24
20
  end
25
21
  end
26
22
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Pubid
4
4
  module Csa
5
- class SingleIdentifier < Pubid::Identifier
5
+ class SingleIdentifier < Identifier
6
6
  # Generate URN for this identifier
7
7
  #
8
8
  # @return [String] URN representation
data/lib/pubid/csa.rb CHANGED
@@ -15,6 +15,10 @@ module Pubid
15
15
  autoload :Components, "#{__dir__}/csa/components"
16
16
 
17
17
  def self.parse(identifier_string)
18
+ if identifier_string.length > Pubid::MAX_INPUT_LENGTH
19
+ raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE
20
+ end
21
+
18
22
  Identifier.parse(identifier_string)
19
23
  end
20
24
 
@@ -16,13 +16,7 @@ module Pubid
16
16
  class Code < Lutaml::Model::Serializable
17
17
  attribute :number, :string # Main number
18
18
  attribute :minor, :string # Optional minor part
19
- attribute :parts, :string, collection: true # Parts array
20
-
21
- def initialize(number:, minor: nil, parts: nil)
22
- @number = number
23
- @minor = minor
24
- @parts = parts || []
25
- end
19
+ attribute :parts, :string, collection: true, default: [] # Parts array
26
20
 
27
21
  # Render code with space for minor and dash-separated parts
28
22
  def to_s
@@ -13,11 +13,6 @@ module Pubid
13
13
  false
14
14
  } # true for ed.N format
15
15
 
16
- def initialize(version:, is_edition: false)
17
- @version = version
18
- @is_edition = is_edition
19
- end
20
-
21
16
  def to_s
22
17
  if is_edition
23
18
  "ed.#{version}"