pubid-iso 0.1.2 → 0.1.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: b4b3d52e0c0c000893b1ed556782f8ad349a54c2d70fe2e1f81942b4699e67a9
4
- data.tar.gz: 3d82f5403447fe7a816a4913efd3fea16c37cc7c3e20ea8168ef21ab415996b2
3
+ metadata.gz: d0daa77a77b864f2c4799226d5a5d458a3a852ba5321bf243f5415082ca66d52
4
+ data.tar.gz: 2efd25c20e35d80cd14a2f286e435eab2d017a295b08fb16f7c05ff079fe8986
5
5
  SHA512:
6
- metadata.gz: ad4e1d604590a74fe504b7b5036cfe3bfe2696a7a145486470011ddfc148ca41265d79d8c2c0b171d9b26f8a0fb20186648a40d749ab9470afcf2f32cc9bb98d
7
- data.tar.gz: 62b3e37a7b82df4fdd5ca160e71380c15e4c28999b26b5eb6699cc1abdd1611182d38f66841d4cb0980bf21e25feefe4059e7c5860e773cbbcd312eb536ab317
6
+ metadata.gz: e740022023d24557f1650de284b22411176ac4fb09d6ecac8bb8c3a69a328dcaeeb79aadc0c3a5644840fadd1167699a010039dbedd5f5412f82387a7566c88c
7
+ data.tar.gz: 3d7437f44ed7e4fc6496b315d30940ea79bb3e4e275ea1bb1f973fe2a7927c339ec57758a90494a27afcba71c266dae4bf1d9cd61a7002a4e9bdb515e9ca6a49
@@ -3,7 +3,7 @@ module Pubid::Iso
3
3
  def identifier(with_date, with_language_code)
4
4
  if @type == "Guide"
5
5
  "Guide #{originator}#{stage} #{number}#{part}#{iteration}"\
6
- "#{with_date && year || ''}#{edition}#{supplements}#{language(with_language_code)}"
6
+ "#{with_date && rendered_year || ''}#{edition}#{supplements}#{language(with_language_code)}"
7
7
  else
8
8
  super
9
9
  end
@@ -20,7 +20,7 @@ module Pubid::Iso
20
20
  def identifier(with_date, with_language_code)
21
21
  if @type == "Guide"
22
22
  "Руководство #{originator}#{stage} #{number}#{part}#{iteration}"\
23
- "#{with_date && year || ''}#{edition}#{supplements}#{language(with_language_code)}"
23
+ "#{with_date && rendered_year || ''}#{edition}#{supplements}#{language(with_language_code)}"
24
24
  else
25
25
  super
26
26
  end
@@ -4,7 +4,9 @@ module Pubid::Iso
4
4
  :type, :year, :edition, :iteration, :supplements, :language,
5
5
  :amendment, :amendment_version, :amendment_number,
6
6
  :corrigendum, :corrigendum_version, :corrigendum_number,
7
- :amendment_stage, :corrigendum_stage, :joint_document
7
+ :amendment_stage, :corrigendum_stage, :joint_document,
8
+ :tctype, :sctype, :wgtype, :tcnumber, :scnumber, :wgnumber,
9
+ :urn_stage
8
10
 
9
11
  LANGUAGES = {
10
12
  "ru" => "R",
@@ -67,8 +69,40 @@ module Pubid::Iso
67
69
  end
68
70
 
69
71
  def identifier(with_date, with_language_code)
70
- "#{originator}#{type}#{stage} #{number}#{part}#{iteration}"\
71
- "#{with_date && year || ''}#{edition}#{supplements}#{language(with_language_code)}"
72
+ if @tctype
73
+ "#{originator} #{tctype} #{tcnumber}#{sctype}#{wgtype} N#{number}"
74
+ else
75
+ "#{originator}#{type}#{stage} #{number}#{part}#{iteration}"\
76
+ "#{with_date && rendered_year || ''}#{edition}#{supplements}#{language(with_language_code)}"
77
+ end
78
+ end
79
+
80
+ def tctype
81
+ return @tctype.join("/") if @tctype.is_a?(Array)
82
+
83
+ @tctype
84
+ end
85
+
86
+ # TC 184/SC/WG 4 - no wg number
87
+ # TC 184/SC 4/WG 12 - separate sc and wg number
88
+ def sctype
89
+ return unless @sctype
90
+
91
+ if @wgnumber || !@wgtype
92
+ "/#{@sctype} #{@scnumber}"
93
+ else
94
+ "/#{@sctype}"
95
+ end
96
+ end
97
+
98
+ def wgtype
99
+ return unless @wgtype
100
+
101
+ if @wgnumber
102
+ "/#{@wgtype} #{@wgnumber}"
103
+ else
104
+ "/#{@wgtype} #{@scnumber}"
105
+ end
72
106
  end
73
107
 
74
108
  def copublisher
@@ -97,8 +131,8 @@ module Pubid::Iso
97
131
  "-#{@part}" if @part
98
132
  end
99
133
 
100
- def year
101
- ":#{@year}" if @year
134
+ def rendered_year
135
+ @year && ":#{@year}"
102
136
  end
103
137
 
104
138
  def type
@@ -131,12 +165,12 @@ module Pubid::Iso
131
165
 
132
166
  def supplements
133
167
  result = ""
134
- if @amendment
168
+ if @amendment_version
135
169
  result += (@amendment_stage && "/#{@amendment_stage} ") || "/"
136
170
  result += amendment
137
171
  end
138
172
 
139
- if @corrigendum
173
+ if @corrigendum_version
140
174
  result += (@corrigendum_stage && "/#{@corrigendum_stage} ") || "/"
141
175
  result += corrigendum
142
176
  end
@@ -17,6 +17,9 @@ module Pubid::Iso
17
17
  # Stage 50.60: PRF ("proof") (non-public)
18
18
  # Stage 60: IS
19
19
  class Parser < Parslet::Parser
20
+ rule(:space) { str(" ") }
21
+ rule(:space?) { space.maybe }
22
+
20
23
  rule(:digits) do
21
24
  match('\d').repeat(1)
22
25
  end
@@ -51,18 +54,40 @@ module Pubid::Iso
51
54
  ).as(:type)
52
55
  end
53
56
 
57
+ rule(:tctype) do
58
+ # tc-types
59
+ str("TC") | str("JTC") | str("PC") | str("IT") | str("CAB") | str("CASCO") | str("COPOLCO") |
60
+ str("COUNCIL") | str("CPSG") | str("CS") | str("DEVCO") | str("GA") | str("GAAB") | str("INFCO") |
61
+ str("ISOlutions") | str("ITN") | str("REMCO") | str("TMB") | str("TMBG") | str("WMO") |
62
+ str("DMT") | str("JCG") | str("SGPM") | str("ATMG") | str("CCCC") | str("CCCC-TG") | str("JDMT") |
63
+ str("JSAG") | str("JSCTF-TF") | str("JTCG") | str("JTCG-TF") | str("SAG_Acc") | str("SAG_CRMI") |
64
+ str("SAG_CRMI_CG") | str("SAG_ESG") | str("SAG_ESG_CG") | str("SAG_MRS") | str("SAG SF") | str("SAG SF_CG") |
65
+ str("SMCC") | str("STMG") | str("MENA STAR")
66
+ end
67
+
68
+ rule(:sctype) do
69
+ str("SC")
70
+ end
71
+
72
+ rule(:wgtype) do
73
+ str("AG") | str("AHG") | str("AhG") | str("WG") | str("JWG") | str("QC") | str("TF") |
74
+ str("PPC") | str("CAG") | str("WG SGDG") | str("WG SR") | str("STAR") | str("STTF") | str("TIG") |
75
+ str("CPAG") | str("CSC") | str("ITSAG") | str("CSC/FIN") | str("CSC/NOM") | str("CSC/OVE") |
76
+ str("CSC/SP") | str("CSC/FIN") | str("JAG")
77
+ end
78
+
54
79
  rule(:year) do
55
80
  match('\d').repeat(4, 4).as(:year)
56
81
  end
57
82
 
58
83
  rule(:part) do
59
- (str("-") | str("/")) >> str(" ").maybe >>
60
- (match['[\dA-Z]'] | str("-")).repeat(1).as(:part)
84
+ (str("-") | str("/")) >> space? >>
85
+ (str("Amd") | str("Cor")).absent? >> (match['[\dA-Z]'] | str("-")).repeat(1).as(:part)
61
86
  end
62
87
 
63
88
  rule(:originator) do
64
89
  organization.as(:publisher) >>
65
- (str(" ").maybe >> str("/") >> organization.as(:copublisher)).repeat
90
+ (space? >> str("/") >> organization.as(:copublisher)).repeat
66
91
  end
67
92
 
68
93
  rule(:organization) do
@@ -75,7 +100,7 @@ module Pubid::Iso
75
100
  end
76
101
 
77
102
  rule(:edition) do
78
- str(" ") >> ((str("ED") | str("Ed ") | str("Ed.")) >>
103
+ space >> ((str("ED") | str("Ed ") | str("Ed.")) >>
79
104
  digits.as(:edition) | str("Ed").as(:edition))
80
105
  end
81
106
 
@@ -85,18 +110,18 @@ module Pubid::Iso
85
110
 
86
111
  rule(:amendment) do
87
112
  (str("/") >> stage.as(:amendment_stage)).maybe >>
88
- (str("/") | str(" ")).maybe >>
113
+ (str("/") | space).maybe >>
89
114
  (str("Amd") | str("AMD") | str("AM")).as(:amendment) >>
90
- (str(" ") | str(".")) >>
115
+ (space | str(".")) >>
91
116
  digits.as(:amendment_version) >>
92
117
  (str(":") >> digits.as(:amendment_number)).maybe
93
118
  end
94
119
 
95
120
  rule(:corrigendum) do
96
121
  (str("/") >> stage.as(:corrigendum_stage)).maybe >>
97
- (str("/") | str(" ")).maybe >>
122
+ (str("/") | space).maybe >>
98
123
  (str("Cor") | str("COR")).as(:corrigendum) >>
99
- (str(" ") | str(".")) >>
124
+ (space | str(".")) >>
100
125
  digits.as(:corrigendum_version) >>
101
126
  (str(":") >> digits.as(:corrigendum_number)).maybe
102
127
  end
@@ -115,31 +140,45 @@ module Pubid::Iso
115
140
  str("Guide") | str("GUIDE") | str("Руководство") | str("Руководства")
116
141
  end
117
142
 
118
- rule(:identifier) do
119
- str("Fpr").as(:stage).maybe >>
120
- # Withdrawn e.g: WD/ISO 10360-5:2000
121
- str("WD/").maybe >>
122
- # for French and Russian PubIDs starting with Guide type
123
- (guide_prefix.as(:type) >> str(" ")).maybe >>
124
- (stage.as(:stage) >> str(" ")).maybe >>
125
- originator >> ((str(" ") | str("/")) >>
126
- # for ISO/FDIS
127
- (type | stage.as(:stage))).maybe >>
143
+ # Parse technical committee documents
144
+ rule(:tc_document_body) do
145
+ (tctype.as(:tctype) >> str("/").maybe).repeat >> space >> digits.as(:tcnumber) >>
146
+ (str("/") >> (
147
+ ((sctype.as(:sctype) >> space >> digits.as(:scnumber) >> str("/")).maybe >>
148
+ wgtype.as(:wgtype) >> space >> digits.as(:wgnumber)) |
149
+ (sctype.as(:sctype) >> (space | str("/") >> wgtype.as(:wgtype) >> space) >> digits.as(:scnumber))
150
+ )).maybe >>
151
+ str(" N") >> space? >> digits.as(:number)
152
+ end
153
+
154
+ rule(:std_document_body) do
155
+ (type | stage.as(:stage)).maybe >>
128
156
  # for ISO/IEC WD TS 25025
129
- str(" ").maybe >> ((stage.as(:stage) | type) >> str(" ")).maybe >>
157
+ space? >> ((stage.as(:stage) | type) >> space).maybe >>
130
158
  digits.as(:number) >>
131
159
  # for identifiers like ISO 5537/IDF 26
132
- (str("|") >> (str("IDF") >> str(" ") >> digits).as(:joint_document)).maybe >>
160
+ (str("|") >> (str("IDF") >> space >> digits).as(:joint_document)).maybe >>
133
161
  part.maybe >> iteration.maybe >>
134
- (str(" ").maybe >> str(":") >> year).maybe >>
162
+ (space? >> str(":") >> year).maybe >>
135
163
  # stage before amendment
136
164
  (
137
- # stage before corrigendum
138
- ((amendment >> corrigendum.maybe) | corrigendum).maybe) >>
165
+ # stage before corrigendum
166
+ ((amendment >> corrigendum.maybe) | corrigendum).maybe) >>
139
167
  edition.maybe >>
140
168
  language.maybe
141
169
  end
142
170
 
171
+ rule(:identifier) do
172
+ str("Fpr").as(:stage).maybe >>
173
+ # Withdrawn e.g: WD/ISO 10360-5:2000
174
+ str("WD/").maybe >>
175
+ # for French and Russian PubIDs starting with Guide type
176
+ (guide_prefix.as(:type) >> space).maybe >>
177
+ (stage.as(:stage) >> space).maybe >>
178
+ originator >> (space | str("/")) >>
179
+ (tc_document_body | std_document_body)
180
+ end
181
+
143
182
  rule(:root) { identifier }
144
183
  end
145
184
  end
data/lib/pubid/iso/urn.rb CHANGED
@@ -1,11 +1,5 @@
1
1
  module Pubid::Iso
2
- class Urn
3
- attr_accessor :number, :publisher, :copublisher, :stage, :substage, :part,
4
- :type, :year, :edition, :iteration, :supplements, :language,
5
- :amendment, :amendment_version, :amendment_number,
6
- :corrigendum, :corrigendum_version, :corrigendum_number,
7
- :amendment_stage, :corrigendum_stage, :joint_document
8
-
2
+ class Urn < Identifier
9
3
 
10
4
  STAGES = { PWI: 0,
11
5
  NP: 10,
@@ -26,7 +20,33 @@ module Pubid::Iso
26
20
  # [[":" status] ":" edition]
27
21
  # [":" docversion] [":" language]
28
22
 
29
- "urn:iso:std:#{originator}#{type}:#{number}#{part}#{stage}#{edition}#{supplement}#{language}"
23
+ if tctype
24
+ "urn:iso:doc:#{originator}:#{tctype.downcase}:#{tcnumber}#{sctype}#{wgtype}:#{number}"
25
+ else
26
+ "urn:iso:std:#{originator}#{type}:#{number}#{part}#{stage}#{edition}#{supplement}#{language}"
27
+ end
28
+ end
29
+
30
+ def tctype
31
+ return @tctype.join(":") if @tctype.is_a?(Array)
32
+
33
+ @tctype
34
+ end
35
+
36
+ def sctype
37
+ return unless @sctype
38
+
39
+ ":#{@sctype.downcase}:#{@scnumber}"
40
+ end
41
+
42
+ def wgtype
43
+ return unless @wgtype
44
+
45
+ if @wgnumber
46
+ ":#{@wgtype.downcase}:#{@wgnumber}"
47
+ else
48
+ ":#{@wgtype.downcase}"
49
+ end
30
50
  end
31
51
 
32
52
  def part
@@ -34,10 +54,14 @@ module Pubid::Iso
34
54
  end
35
55
 
36
56
  def render_stage(stage)
57
+ return ":stage-#{sprintf('%05.2f', stage)}#{iteration}" if stage.is_a?(Float)
58
+
37
59
  ":stage-#{sprintf('%05.2f', STAGES[stage.to_sym])}#{iteration}"
38
60
  end
39
61
 
40
62
  def stage
63
+ return render_stage(@urn_stage) if @urn_stage
64
+
41
65
  return render_stage(@stage) if @stage
42
66
 
43
67
  return render_stage(@amendment_stage) if @amendment_stage
@@ -70,7 +94,6 @@ module Pubid::Iso
70
94
  def type
71
95
  # type = "data" / "guide" / "isp" / "iwa" /
72
96
  # "pas" / "r" / "tr" / "ts" / "tta"
73
-
74
97
  if @type
75
98
  ":#{@type.downcase}"
76
99
  end
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Iso
3
- VERSION = "0.1.2".freeze
3
+ VERSION = "0.1.5".freeze
4
4
  end
5
5
  end
data/lib/pubid/iso.rb CHANGED
@@ -11,7 +11,7 @@ end
11
11
  require_relative "iso/errors"
12
12
  require_relative "iso/parser"
13
13
  require_relative "iso/transformer"
14
- require_relative "iso/urn"
15
14
  require_relative "iso/identifier"
16
15
  require_relative "iso/identifier/french"
17
16
  require_relative "iso/identifier/russian"
17
+ require_relative "iso/urn"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubid-iso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.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: 2022-04-09 00:00:00.000000000 Z
11
+ date: 2022-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake