pubid-iso 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +25 -0
- data/README.adoc +2 -0
- data/lib/pubid/iso/errors.rb +5 -0
- data/lib/pubid/iso/identifier.rb +46 -0
- data/lib/pubid/iso/parser.rb +103 -0
- data/lib/pubid/iso/transformer.rb +19 -0
- data/lib/pubid/iso/urn.rb +69 -0
- data/lib/pubid/iso/version.rb +5 -0
- data/lib/pubid/iso.rb +15 -0
- data/lib/pubid-iso.rb +3 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a1f95297e422efe82291fd2570ba264ca9daf1b6304dc3050ae7aebcff532739
|
4
|
+
data.tar.gz: '08f400bc76e43847ae0ae0b7d0c516de05a6a9bdc1dce60abd9b69ca9745b05e'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d2f14cbb013fc0e9097178bc9cf7c3b5255f21699c0e904cbd8bb4aec159464f451c679e5d2f4a24aee9c3c3397d8b882f3fbb89c096104c17da51bfe6cf4f7
|
7
|
+
data.tar.gz: 3d263a1fad953c7e508b2d1936fda41fd4d827f09eb81fecc6b3379acb23502d6852cdaa99860717714934af262eb01a13039b00871af2ef8f11cf97b738e3df
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
BSD 2-Clause License
|
2
|
+
|
3
|
+
Copyright (c) 2018, Ribose
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this
|
10
|
+
list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
20
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.adoc
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module Pubid::Iso
|
2
|
+
class Identifier
|
3
|
+
STAGES = { NP: 10,
|
4
|
+
WD: 20,
|
5
|
+
CD: 30,
|
6
|
+
DIS: 40,
|
7
|
+
FDIS: 50,
|
8
|
+
PRF: 50,
|
9
|
+
IS: 60,
|
10
|
+
Fpr: 50 }.freeze
|
11
|
+
|
12
|
+
attr_accessor :number, :publisher, :copublisher, :stage, :substage, :part,
|
13
|
+
:type, :year, :edition, :iteration, :supplements, :language
|
14
|
+
|
15
|
+
def initialize(stage: nil, supplements: nil, **opts)
|
16
|
+
if stage
|
17
|
+
@stage = STAGES[stage.to_sym]
|
18
|
+
@substage = 0
|
19
|
+
end
|
20
|
+
|
21
|
+
# XXX: temporary hack for ISO/IEC 19794-7:2014/Amd 1:2015/CD Cor 1 parsing
|
22
|
+
supplements&.each do |supplement|
|
23
|
+
if supplement[:stage]
|
24
|
+
@stage = STAGES[Transformer.new.apply(stage: supplement[:stage].to_s)[:stage].to_sym]
|
25
|
+
@substage = 0
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
@supplements = supplements
|
30
|
+
|
31
|
+
opts.each { |key, value| send("#{key}=", value.is_a?(Array) && value || value.to_s) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def urn
|
35
|
+
URN.new(self)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.parse(code)
|
39
|
+
new(**Parser.new.parse(code).map do |k, v|
|
40
|
+
Transformer.new.apply(k => v).to_a.first
|
41
|
+
end.to_h)
|
42
|
+
rescue Parslet::ParseFailed => failure
|
43
|
+
raise Pubid::Iso::Errors::ParseError, "#{failure.message}\ncause: #{failure.parse_failure_cause.ascii_tree}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# from https://github.com/relaton/relaton-iso/issues/47#issuecomment-512251416
|
2
|
+
# ISO {num}-{docpart}:{year} - docpart and year are optional. docpart is [\w-]+
|
3
|
+
# ISO/{stage} {num}-{docpart}:{year} or ISO/{subprefix} {stage} {num}:{year} - stages are WD, CD, DIS, FDIS, AWI
|
4
|
+
# ISO/{subprefix} {stage} {num}-{docpart}:{year} - subpefixes are IEC, IEEE, IEC/IEEE, TR, R. Any other?
|
5
|
+
# ISO {num}:{year}/{correction} {cornum}:{coryear} - corrections are Amd, DAmd, Cor. coryear is optional
|
6
|
+
# ISO {num}:{year}/{corstage} {correction} {cornum}:{coryear} - corstages are CD, NP, AWI, PRF, WD, DIS. Any others?
|
7
|
+
|
8
|
+
module Pubid::Iso
|
9
|
+
# ISO/IEC FDIS 7816-6
|
10
|
+
# ISO/IEC/IEEE 15289:2019
|
11
|
+
#
|
12
|
+
# Stage 10: NP (non-public)
|
13
|
+
# Stage 20: WD (non-public)
|
14
|
+
# Stage 30: CD
|
15
|
+
# Stage 40: DIS
|
16
|
+
# Stage 50: FDIS
|
17
|
+
# Stage 50.60: PRF ("proof") (non-public)
|
18
|
+
# Stage 60: IS
|
19
|
+
class Parser < Parslet::Parser
|
20
|
+
rule(:digits) do
|
21
|
+
match('\d').repeat(1)
|
22
|
+
end
|
23
|
+
|
24
|
+
rule(:stage) do
|
25
|
+
(str("NP") | str("WD") | str("CD") | str("DIS") | str("FDIS") | str("PRF") |
|
26
|
+
str("IS") | str("AWI") | str("FD") | str("D")).as(:stage)
|
27
|
+
end
|
28
|
+
|
29
|
+
# TYPES = {
|
30
|
+
# "TS" => "technical-specification",
|
31
|
+
# "TR" => "technical-report",
|
32
|
+
# "PAS" => "publicly-available-specification",
|
33
|
+
# "Guide" => "guide",
|
34
|
+
# }.freeze
|
35
|
+
# DATA|GUIDE|ISP|IWA|PAS|R|TR|TS|TTA
|
36
|
+
# # type = "data" / "guide" / "isp" / "iwa" /
|
37
|
+
# # "pas" / "r" / "tr" / "ts" / "tta"
|
38
|
+
rule(:type) do
|
39
|
+
(str("DATA") | str("ISP") | str("IWA") | str("R") | str("TTA") |
|
40
|
+
str("TS") | str("TR") | str("PAS") | str("Guide")).as(:type)
|
41
|
+
end
|
42
|
+
|
43
|
+
rule(:year) do
|
44
|
+
match('\d').repeat(4, 4)
|
45
|
+
end
|
46
|
+
|
47
|
+
rule(:part) do
|
48
|
+
(str("-") | str("/")) >> str(" ").maybe >>
|
49
|
+
(match['[\dA-Z]'] | str("-")).repeat(1).as(:part)
|
50
|
+
end
|
51
|
+
|
52
|
+
rule(:originator) do
|
53
|
+
organization.as(:publisher) >>
|
54
|
+
(str(" ").maybe >> str("/") >> organization.as(:copublisher)).maybe
|
55
|
+
end
|
56
|
+
|
57
|
+
rule(:organization) do
|
58
|
+
str("IEC/IEEE") | str("IEC") | str("IEEE") | str("CIW") | str("SAE") |
|
59
|
+
str("CIE") | str("ASME") | str("ASTM") | str("OECD") | str("ISO") |
|
60
|
+
str("IWA") | str("HL7")
|
61
|
+
end
|
62
|
+
|
63
|
+
rule(:edition) do
|
64
|
+
str(" ") >> ((str("ED") | str("Ed ") | str("Ed.")) >>
|
65
|
+
digits.as(:edition) | str("Ed").as(:edition))
|
66
|
+
end
|
67
|
+
|
68
|
+
rule(:iteration) do
|
69
|
+
str(".") >> digits.as(:iteration)
|
70
|
+
end
|
71
|
+
|
72
|
+
rule(:supplement) do
|
73
|
+
(str("/") | str(" ")).maybe >>
|
74
|
+
(str("Amd") | str("AMD") | str("Cor") | str("COR")).as(:supplement) >>
|
75
|
+
str(" ") >>
|
76
|
+
digits.as(:supplement_version) >>
|
77
|
+
(str(":") >> digits.as(:supplement_number)).maybe
|
78
|
+
end
|
79
|
+
|
80
|
+
rule(:language) do
|
81
|
+
str("(") >> match["a-z"].repeat(1).as(:language) >> str(")")
|
82
|
+
end
|
83
|
+
|
84
|
+
rule(:identifier) do
|
85
|
+
str("Fpr").as(:stage).maybe >>
|
86
|
+
# Withdrawn e.g: WD/ISO 10360-5:2000
|
87
|
+
str("WD/").maybe >>
|
88
|
+
originator >> ((str(" ") | str("/")) >>
|
89
|
+
# for ISO/FDIS
|
90
|
+
(type | stage)).maybe >>
|
91
|
+
# for ISO/IEC WD TS 25025
|
92
|
+
str(" ").maybe >> ((stage | type) >> str(" ")).maybe >>
|
93
|
+
digits.as(:number) >> part.maybe >> iteration.maybe >>
|
94
|
+
(str(" ").maybe >> str(":") >> year).maybe >>
|
95
|
+
((str("/") >> stage).maybe >>
|
96
|
+
supplement).repeat.as(:supplements) >>
|
97
|
+
edition.maybe >>
|
98
|
+
language.maybe
|
99
|
+
end
|
100
|
+
|
101
|
+
rule(:root) { identifier }
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Pubid::Iso
|
2
|
+
class Transformer < Parslet::Transform
|
3
|
+
rule(edition: "Ed") do
|
4
|
+
{ edition: "1" }
|
5
|
+
end
|
6
|
+
|
7
|
+
rule(stage: simple(:stage)) do
|
8
|
+
{ stage: case stage
|
9
|
+
when "D"
|
10
|
+
"DIS"
|
11
|
+
when "FD"
|
12
|
+
"FDIS"
|
13
|
+
else
|
14
|
+
stage
|
15
|
+
end
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Pubid::Iso
|
2
|
+
class URN
|
3
|
+
attr_accessor :identifier
|
4
|
+
|
5
|
+
def initialize(identifier)
|
6
|
+
@identifier = identifier
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
# docidentifier = originator [":" type] ":" docnumber [":" partnumber]
|
11
|
+
# [[":" status] ":" edition]
|
12
|
+
# [":" docversion] [":" language]
|
13
|
+
|
14
|
+
"urn:iso:std:#{originator}#{type}:#{identifier.number}#{part}#{stage}#{edition}#{supplement}#{language}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def part
|
18
|
+
":-#{identifier.part}" if identifier.part
|
19
|
+
end
|
20
|
+
|
21
|
+
def stage
|
22
|
+
":stage-#{identifier.stage}.#{sprintf('%02d', identifier.substage)}#{iteration}" if identifier.stage
|
23
|
+
end
|
24
|
+
|
25
|
+
def originator
|
26
|
+
# originator = "iso" / "iso-iec" / "iso-cie" / "iso-astm" /
|
27
|
+
# "iso-ieee" / "iec"
|
28
|
+
|
29
|
+
if identifier.copublisher
|
30
|
+
"#{identifier.publisher.downcase}-#{identifier.copublisher.downcase.gsub('/', '-')}"
|
31
|
+
else
|
32
|
+
identifier.publisher.downcase
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def edition
|
37
|
+
":ed-#{identifier.edition}" if identifier.edition
|
38
|
+
end
|
39
|
+
|
40
|
+
def iteration
|
41
|
+
".v#{identifier.iteration}" if identifier.iteration
|
42
|
+
end
|
43
|
+
|
44
|
+
def type
|
45
|
+
# type = "data" / "guide" / "isp" / "iwa" /
|
46
|
+
# "pas" / "r" / "tr" / "ts" / "tta"
|
47
|
+
|
48
|
+
if identifier.type
|
49
|
+
":#{identifier.type.downcase}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def supplement
|
54
|
+
identifier.supplements&.map do |supplement|
|
55
|
+
if supplement[:supplement_number]
|
56
|
+
":#{supplement[:supplement].to_s.downcase}:#{supplement[:supplement_number]}:v#{supplement[:supplement_version]}"
|
57
|
+
else
|
58
|
+
":#{supplement[:supplement].to_s.downcase}:v#{supplement[:supplement_version]}"
|
59
|
+
end
|
60
|
+
end&.join
|
61
|
+
end
|
62
|
+
|
63
|
+
def language
|
64
|
+
if identifier.language
|
65
|
+
":#{identifier.language}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/pubid/iso.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "parslet"
|
4
|
+
|
5
|
+
module Pubid
|
6
|
+
module Iso
|
7
|
+
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
require_relative "iso/errors"
|
12
|
+
require_relative "iso/parser"
|
13
|
+
require_relative "iso/transformer"
|
14
|
+
require_relative "iso/urn"
|
15
|
+
require_relative "iso/identifier"
|
data/lib/pubid-iso.rb
ADDED
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pubid-iso
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ribose Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-03-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '13.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '13.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: lightly
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: parslet
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Library to generate, parse and manipulate ISO PubID.
|
98
|
+
email:
|
99
|
+
- open.source@ribose.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files:
|
103
|
+
- README.adoc
|
104
|
+
- LICENSE.txt
|
105
|
+
files:
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.adoc
|
108
|
+
- lib/pubid-iso.rb
|
109
|
+
- lib/pubid/iso.rb
|
110
|
+
- lib/pubid/iso/errors.rb
|
111
|
+
- lib/pubid/iso/identifier.rb
|
112
|
+
- lib/pubid/iso/parser.rb
|
113
|
+
- lib/pubid/iso/transformer.rb
|
114
|
+
- lib/pubid/iso/urn.rb
|
115
|
+
- lib/pubid/iso/version.rb
|
116
|
+
homepage: https://github.com/metanorma/pubid-iso
|
117
|
+
licenses:
|
118
|
+
- BSD-2-Clause
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: 2.5.0
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubygems_version: 3.3.3
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Library to generate, parse and manipulate ISO PubID.
|
139
|
+
test_files: []
|