pubid-iec 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '092ecdd26535d1bf9d3b7c8aa11d9117ab2e0836d6a8659169f36979cdafcd54'
4
+ data.tar.gz: 228f27369cfdb0130cfcacfebb8befa3c902becb3f5f701e27f5f0b893669a09
5
+ SHA512:
6
+ metadata.gz: b7f2b20b4e841616c650403f940521c7d13ad42065479331987f7af91b19d4f80502f168ba1c4f537ff4174aa5ff5178d0f07170547765eee694015edd4c2853
7
+ data.tar.gz: cdbd7d923574793ade27a1523c4ff4c59dd14af8a8b50b04b9dc9f16086e537fb2314a27e24de89f23afc750eab3446cb4055abba77995845a0d838ff7bab1cf
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
+ = IEC publication identifiers ("IEC PubID")
2
+
3
+ == Purpose
4
+
5
+ This gem implements a mechanism to parse and utilize IEC publication
6
+ identifiers.
7
+
8
+ == Use cases to support
9
+
10
+ . generate updated PubID
11
+ . generate language specific PubID
12
+ . generate dated vs undated PubIDs
13
+
14
+ == IECEE TRF Format
15
+
16
+ The IECEE TRF pattern is:
17
+ [example]
18
+ ====
19
+ IECEE TRF {number-and-part}{trf-version}[{test-type}][:{year}]
20
+ ====
21
+ (Sample IECEE TRF PubID: IECEE TRF 60086-1&2A:2017)
22
+
23
+ Where
24
+
25
+ - `number-and-part` is the number and part of the IEC standard, e.g. `61000-3-33`. If there are multiple parts, the & ampersand separator is used. When parsing, we should accept the , character here, but when generating the PubID, the & separator must be used
26
+ - `trf-version` is typically the alphabet version of a single character length, where `A` is the first version, `B` is the second version and so on.
27
+
28
+ There are cases where the `trf-version` is `{version-alphabet}{sub-version}` where `sub-version` is a string, e.g. `F_II` (the `sub-version` is `_II`). In this case, the "full version" is considered to be the full string of `trf-version`, i.e. `F_II`. (in the case of `IECEE TRF 61058-1F_II:2019`)
29
+
30
+ - `test-type` is an optional string such as _EMC, _PS, _SOF that indicates a specialized type of TRF
31
+ - `year` is optional for edition year.
32
+
33
+ == IECEx TRF Format
34
+
35
+ The IECEx TRF pattern is:
36
+ [example]
37
+ ====
38
+ IECEx TRF {number-and-part}{either '_' or 'v'}{std-edition}{trf-version}
39
+ ====
40
+ Where
41
+
42
+ - `number-and-part` is the number and part of the IEC standard, e.g. `60079-0`. If there are multiple parts, the , comma separator is used.
43
+ - `either '\_' or 'v'` is either a `_` or `v` character. In the IEC Webstore, they use a v character, e.g. `IECEx TRF 60079-15v1:2002`, but in the official IECEx identifier pattern it is `_`.
44
+ - `std-edition` is the edition number of the underlying IEC standard, an integer.
45
+ - `trf-version` is typically the alphabet version of a single character length, where `A` is the first version, `B` is the second version and so on.
46
+ * There are cases where the `trf-version` is `{version-alphabet}{sub-version}` where `sub-version` is a string, e.g. `A_DS` (the `sub-version` is `_DS`) or `Arev4_ds` (the `sub-version` is `rev4_ds`). In this case, the "full version" is considered to be the full string of `trf-version`, i.e. `A_DS` or `Arev4_ds`.
@@ -0,0 +1,11 @@
1
+ module Pubid::Iec
2
+ class Amendment < Pubid::Core::Supplement
3
+ def render_pubid
4
+ "AMD#{render_pubid_number}"
5
+ end
6
+
7
+ def render_urn
8
+ ":amd#{render_urn_number}"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Pubid::Iec
2
+ class Corrigendum < Pubid::Core::Supplement
3
+ def render_pubid
4
+ "COR#{render_pubid_number}"
5
+ end
6
+
7
+ def render_urn
8
+ ":cor#{render_urn_number}"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ module Pubid::Iec
2
+ module Errors
3
+ class StageParseError < StandardError; end
4
+ class StageInvalidError < StandardError; end
5
+ class ParseTypeError < StandardError; end
6
+ class WrongTypeError < StandardError; end
7
+ end
8
+ end
@@ -0,0 +1,67 @@
1
+ module Pubid::Iec
2
+ class Identifier < Pubid::Core::Identifier
3
+
4
+ attr_accessor :vap, :database, :fragment, :version, :decision_sheet,
5
+ :conjuction_part, :part_version, :trf_publisher,
6
+ :trf_series, :trf_version, :test_type
7
+
8
+ # @param stage [String] stage eg. "PWI", "PNW"
9
+ def initialize(publisher: "IEC", stage: nil, vap: nil, database: nil,
10
+ fragment: nil, version: nil, decision_sheet: nil,
11
+ conjuction_part: nil, part_version: nil, trf_publisher: nil,
12
+ trf_series: nil, trf_version: nil, test_type: nil,
13
+ edition: nil, type: nil, **args)
14
+ # @stage = stage.to_s if stage
15
+ @stage = Stage.parse(stage) if stage
16
+ @vap = vap.to_s if vap
17
+ @database = database if database
18
+ @fragment = fragment if fragment
19
+ @version = version if version
20
+ @decision_sheet = decision_sheet if decision_sheet
21
+ @conjuction_part = conjuction_part if conjuction_part
22
+ @part_version = part_version if part_version
23
+ @trf_publisher = trf_publisher.to_s if trf_publisher
24
+ @trf_series = trf_series if trf_series
25
+ @trf_version = trf_version.to_s if trf_version
26
+ @test_type = test_type if test_type
27
+ @edition = edition.to_s if edition
28
+ @type = Type.parse(type) if type
29
+
30
+ super(**args.merge(publisher: publisher))
31
+ end
32
+
33
+ def urn
34
+ Renderer::Urn.new(get_params).render
35
+ end
36
+
37
+ class << self
38
+ def get_amendment_class
39
+ Amendment
40
+ end
41
+
42
+ def get_corrigendum_class
43
+ Corrigendum
44
+ end
45
+
46
+ def get_parser_class
47
+ Parser
48
+ end
49
+
50
+ def get_renderer_class
51
+ Renderer::Pubid
52
+ end
53
+
54
+ def get_transformer_class
55
+ Transformer
56
+ end
57
+
58
+ def get_update_codes
59
+ UPDATE_CODES
60
+ end
61
+ end
62
+
63
+ def database
64
+ @database || false
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,92 @@
1
+ require "pubid-core"
2
+
3
+ module Pubid::Iec
4
+ class Parser < Pubid::Core::Parser
5
+ rule(:organization) do
6
+ str("IECEE") | str("IECEx") | str("IECQ") | str("IEC") | str("ISO") |
7
+ str("IEEE") | str("CISPR")
8
+ end
9
+
10
+ rule(:stage) do
11
+ array_to_str(Renderer::Urn::STAGES.keys)
12
+ end
13
+
14
+ rule(:type) do
15
+ (str("IS") | str("TS") | str("TR") | str("PAS") | str("SRD") |
16
+ str("TEC") | str("STTR") | str("WP") | str("Guide") | str("GUIDE") | str("OD") |
17
+ str("CS") | str("CA")
18
+ ).as(:type)
19
+ end
20
+
21
+ rule(:part) do
22
+ (str("-") | str("/")) >> space? >>
23
+ (str("Amd") | str("Cor")).absent? >> (match['[\dA-Z]'] | str("-")).repeat(1).as(:part)
24
+ end
25
+
26
+ rule(:version) { digits >> (dot >> digits).maybe }
27
+
28
+ rule(:edition) do
29
+ (str(" Edition ") >> version.as(:edition) >> space >> year_month.as(:edtion_date) |
30
+ str(" ED") >> version.as(:edition) |
31
+ str("v") >> (digits >> (match("[A-Za-z]") >> str("rev").maybe >> digits.maybe).maybe).as(:version))
32
+ end
33
+
34
+ rule(:amendment) do
35
+ ((str("/") | str("+") | space).maybe >>
36
+ str("AMD") >>
37
+ digits.as(:number) >>
38
+ (str(":") >> digits.as(:year)).maybe).as(:amendments)
39
+ end
40
+
41
+ rule(:fragment) do
42
+ (str("/") >> str("FRAG") >> match('[\dA-Z]').repeat(1).as(:fragment)).maybe
43
+ end
44
+
45
+ rule(:corrigendum) do
46
+ ((str("/") | space).maybe >>
47
+ str("COR") >>
48
+ digits.as(:number) >>
49
+ (str(":") >> digits.as(:year)).maybe).as(:corrigendums)
50
+ end
51
+
52
+ rule(:conjuction_part) do
53
+ ((str(",") | str("&")) >> digits.as(:conjuction_part)).repeat(1)
54
+ end
55
+
56
+ rule(:number) do
57
+ (digits | str("SYMBOL") | str("SYCSMARTENERGY") | str("SyCLVDC") |
58
+ str("SYCLVDC") | str("SyCCOMM") | str("SyCAAL") | str("VIM")) >>
59
+ match("[A-Z]").maybe
60
+ end
61
+
62
+ rule(:std_document_body) do
63
+ (type >> space).maybe >>
64
+ number.as(:number) >>
65
+ edition.maybe >>
66
+ part.maybe >>
67
+ conjuction_part.maybe >>
68
+ (space? >> str(":") >> year).maybe >>
69
+ ((amendment >> corrigendum.maybe) | corrigendum).repeat >>
70
+ fragment.maybe
71
+ end
72
+
73
+ rule(:vap) do
74
+ space >> (str("CSV") | str("SER") | str("RLV") | str("CMV") | str("EXV") |
75
+ str("PAC") | str("PRV")).as(:vap)
76
+ end
77
+
78
+ rule(:database) do
79
+ space >> str("DB").as(:database)
80
+ end
81
+
82
+ rule(:identifier) do
83
+ (originator.maybe >> (space.maybe >> stage.as(:stage)).maybe >> (space | str("/")) >>
84
+ std_document_body >>
85
+ vap.maybe >> database.maybe >>
86
+ edition.maybe >>
87
+ (str(":") >> year).maybe)
88
+ end
89
+
90
+ rule(:root) { identifier }
91
+ end
92
+ end
@@ -0,0 +1,67 @@
1
+ module Pubid::Iec::Renderer
2
+ class Pubid < Pubid::Core::Renderer::Base
3
+ def render_identifier(params)
4
+ "%{publisher}%{type}%{stage} %{number}%{part}%{conjuction_part}"\
5
+ "%{part_version}%{version}%{iteration}"\
6
+ "%{year}%{amendments}%{corrigendums}%{fragment}%{vap}%{edition}%{language}%{database}" % params
7
+ end
8
+
9
+ def render_type(type, _opts, _params)
10
+ " #{type}"
11
+ end
12
+
13
+ def render_vap(vap, _opts, _params)
14
+ " #{vap}"
15
+ end
16
+
17
+ def render_stage(stage, _opts, _params)
18
+ " #{stage}"
19
+ end
20
+
21
+ def render_fragment(fragment, _opts, _params)
22
+ "/FRAG#{fragment}"
23
+ end
24
+
25
+ def render_database(database, _opts, _params)
26
+ " DB" if database
27
+ end
28
+
29
+ def supplement_prefix(params)
30
+ params[:vap] == "CSV" && "+" || "/"
31
+ end
32
+
33
+ def render_amendments(amendments, _opts, params)
34
+ supplement_prefix(params) + super
35
+ end
36
+
37
+ def render_corrigendums(corrigendums, _opts, params)
38
+ supplement_prefix(params) + super
39
+ end
40
+
41
+ def render_version(version, _opts, params)
42
+ "v#{params[:edition]}#{version}"
43
+ end
44
+
45
+ def render_edition(edition, _opts, params)
46
+ " ED#{edition}" unless params[:version]
47
+ end
48
+
49
+ def render_conjuction_part(conjuction_parts, _opts, _params)
50
+ conjunction_symbol = case _params[:publisher]
51
+ when "IECEE"
52
+ # IECEE TRFs use '&' as parts separator (IECEE OD-2020)
53
+ "&"
54
+ else
55
+ # when "IECEx"
56
+ # IECEx TRFs use ',' as parts separator (IECEx OD-010-1)
57
+ ","
58
+ end
59
+
60
+ if conjuction_parts.is_a?(Array)
61
+ conjuction_parts.map(&:to_i).sort.map { |conjuction_part| "#{conjunction_symbol}#{conjuction_part}" }.join
62
+ else
63
+ "#{conjunction_symbol}#{conjuction_parts}"
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,43 @@
1
+ module Pubid::Iec::Renderer
2
+ class TrfPubid < Pubid
3
+ def render_identifier(params)
4
+ "%{publisher}%{copublisher} TRF%{trf_publisher} %{number}%{part}%{conjuction_part}"\
5
+ "%{part_version}%{version}%{trf_version}%{decision_sheet}%{trf_series}%{test_type}"\
6
+ "%{year}%{vap}" % params
7
+ end
8
+
9
+ def render_vap(vap, _opts, _params)
10
+ " #{vap}"
11
+ end
12
+
13
+ def render_conjuction_part(conjuction_parts, _opts, _params)
14
+ conjunction_symbol = case _params[:publisher]
15
+ when "IECEE"
16
+ # IECEE TRFs use '&' as parts separator (IECEE OD-2020)
17
+ "&"
18
+ else
19
+ # when "IECEx"
20
+ # IECEx TRFs use ',' as parts separator (IECEx OD-010-1)
21
+ ","
22
+ end
23
+
24
+ if conjuction_parts.is_a?(Array)
25
+ conjuction_parts.map(&:to_i).sort.map { |conjuction_part| "#{conjunction_symbol}#{conjuction_part}" }.join
26
+ else
27
+ "#{conjunction_symbol}#{conjuction_parts}"
28
+ end
29
+ end
30
+
31
+ def render_trf_publisher(trf_publisher, _opts, _params)
32
+ " #{trf_publisher}"
33
+ end
34
+
35
+ def render_test_type(test_type, _opts, _params)
36
+ "_#{test_type}"
37
+ end
38
+
39
+ def render_trf_series(trf_series, _opts, _params)
40
+ "_SE"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,19 @@
1
+ module Pubid::Iec::Renderer
2
+ class TrfUrn < Urn
3
+
4
+ def render_identifier(params)
5
+ "urn:iec:std:%{publisher}%{copublisher}:trf%{trf_publisher}:%{number}"\
6
+ "%{part}%{conjuction_part}%{year}%{vap}"\
7
+ "%{version}%{part_version}"\
8
+ "%{trf_version}" % params
9
+ end
10
+
11
+ def render_trf_version(trf_version, _opts, _params)
12
+ ":v#{trf_version}" unless trf_version.empty?
13
+ end
14
+
15
+ def render_trf_publisher(trf_publisher, _opts, _params)
16
+ ":#{trf_publisher.downcase}"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,98 @@
1
+ module Pubid::Iec::Renderer
2
+ class Urn < ::Pubid::Core::Renderer::Urn
3
+ STAGES = { ACD: 20.99,
4
+ ACDV: 30.99,
5
+ ADTR: 40.99,
6
+ ADTS: 40.99,
7
+ AFDIS: 40.99,
8
+ APUB: 50.99,
9
+ BPUB: 60,
10
+ CAN: 30.98,
11
+ CCDV: 40.20,
12
+ CD: 30.20,
13
+ CDISH: 50.20,
14
+ CDM: 30.60,
15
+ CDPAS: 50.20,
16
+ CDTR: 50.20,
17
+ CDTS: 50.20,
18
+ CDVM: 40.91,
19
+ CFDIS: 50.20,
20
+ DECDISH: 50.00,
21
+ DECFDIS: 50.00,
22
+ DECPUB: 60.00,
23
+ DEL: 10.98,
24
+ DELPUB: 99.60,
25
+ DTRM: 50.92,
26
+ DTSM: 50.92,
27
+ MERGED: 30.97,
28
+ NCDV: 40.91,
29
+ NDTR: 50.92,
30
+ NDTS: 50.92,
31
+ NFDIS: 50.92,
32
+ PCC: 30.60,
33
+ PNW: 10.20,
34
+ PPUB: 60.60,
35
+ PRVC: 40.60,
36
+ PRVD: 50.60,
37
+ PRVDISH: 50.60,
38
+ PRVDPAS: 50.60,
39
+ PRVDTR: 50.60,
40
+ PRVDTS: 50.60,
41
+ PRVN: 10.60,
42
+ PWI: 0,
43
+ RDISH: 50.00,
44
+ RFDIS: 50.00,
45
+ RPUB: 60.00,
46
+ SPLIT: 30.96,
47
+ TCDV: 40.00,
48
+ TDISH: 50.00,
49
+ TDTR: 50.00,
50
+ TDTS: 50.00,
51
+ TPUB: 60.00,
52
+ WPUB: 95.99
53
+ }.freeze
54
+
55
+ def render_identifier(params)
56
+ "urn:iec:std:%{publisher}%{copublisher}%{type}:%{number}"\
57
+ "%{part}%{conjuction_part}%{year}%{stage}%{vap}"\
58
+ "%{urn_stage}%{corrigendum_stage}%{iteration}%{version}%{part_version}"\
59
+ "%{edition}%{amendments}%{corrigendums}%{fragment}%{language}" % params
60
+ end
61
+
62
+ def render_number(number, _opts, _params)
63
+ number.to_s.downcase
64
+ end
65
+
66
+ def render_vap(vap, _opts, _params)
67
+ ":#{vap.downcase}"
68
+ end
69
+
70
+ def render_fragment(fragment, _opts, _params)
71
+ ":frag:#{fragment}"
72
+ end
73
+
74
+ def render_version(version, _opts, _params)
75
+ ":v#{version}"
76
+ end
77
+
78
+ def render_part_version(part_version, _opts, _params)
79
+ ":v#{part_version}"
80
+ end
81
+
82
+ def render_conjuction_part(conjuction_parts, _opts, _params)
83
+ if conjuction_parts.is_a?(Array)
84
+ conjuction_parts.map(&:to_i).sort.map { |conjuction_part| ",#{conjuction_part}" }.join
85
+ else
86
+ ",#{conjuction_parts}"
87
+ end
88
+ end
89
+
90
+ def render_stage(stage, _opts, params)
91
+ ":stage-#{sprintf('%05.2f', stage.to_s(:urn))}"
92
+ end
93
+
94
+ def render_type(type, _, _)
95
+ ":#{type.type.to_s}"
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,84 @@
1
+ module Pubid::Iec
2
+ class Stage
3
+ STAGES = { ACD: "20.99",
4
+ ACDV: "30.99",
5
+ ADTR: "40.99",
6
+ ADTS: "40.99",
7
+ AFDIS: "40.99",
8
+ APUB: "50.99",
9
+ BPUB: "60.00",
10
+ CAN: "30.98",
11
+ CCDV: "40.20",
12
+ CD: "30.20",
13
+ CDISH: "50.20",
14
+ CDM: "30.60",
15
+ CDPAS: "50.20",
16
+ CDTR: "50.20",
17
+ CDTS: "50.20",
18
+ CDVM: "40.91",
19
+ CFDIS: "50.20",
20
+ DECDISH: "50.00",
21
+ DECFDIS: "50.00",
22
+ DECPUB: "60.00",
23
+ DEL: "10.98",
24
+ DELPUB: "99.60",
25
+ DTRM: "50.92",
26
+ DTSM: "50.92",
27
+ MERGED: "30.97",
28
+ NCDV: "40.91",
29
+ NDTR: "50.92",
30
+ NDTS: "50.92",
31
+ NFDIS: "50.92",
32
+ PCC: "30.60",
33
+ PNW: "10.20",
34
+ PPUB: "60.60",
35
+ PRVC: "40.60",
36
+ PRVD: "50.60",
37
+ PRVDISH: "50.60",
38
+ PRVDPAS: "50.60",
39
+ PRVDTR: "50.60",
40
+ PRVDTS: "50.60",
41
+ PRVN: "10.60",
42
+ PWI: "00.00",
43
+ RDISH: "50.00",
44
+ RFDIS: "50.00",
45
+ RPUB: "60.00",
46
+ SPLIT: "30.96",
47
+ TCDV: "40.00",
48
+ TDISH: "50.00",
49
+ TDTR: "50.00",
50
+ TDTS: "50.00",
51
+ TPUB: "60.00",
52
+ WPUB: "95.99"
53
+ }.freeze
54
+
55
+ attr_accessor :stage
56
+
57
+ def initialize(stage)
58
+ raise Errors::StageInvalidError, "#{stage} is not valid stage" unless STAGES.key?(stage.to_sym)
59
+
60
+ @stage = stage
61
+ end
62
+
63
+ def to_s(format = :short)
64
+ return "" if nil?
65
+
66
+ case format
67
+ when :short
68
+ @stage
69
+ else
70
+ STAGES[@stage.to_sym]
71
+ end
72
+ end
73
+
74
+ def nil?
75
+ @stage.nil?
76
+ end
77
+
78
+ def self.parse(stage)
79
+ raise Errors::StageInvalidError unless stage.is_a?(Symbol) || stage.is_a?(String) || stage.is_a?(Parslet::Slice)
80
+
81
+ Stage.new(stage.to_s)
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,21 @@
1
+ module Pubid::Iec
2
+ class Transformer < Pubid::Core::Transformer
3
+ def initialize
4
+ super
5
+
6
+ rule(database: "DB") do
7
+ { database: true }
8
+ end
9
+ end
10
+
11
+ class << self
12
+ def get_amendment_class
13
+ Amendment
14
+ end
15
+
16
+ def get_corrigendum_class
17
+ Corrigendum
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ module Pubid::Iec
2
+ class TrfIdentifier < Identifier
3
+
4
+ attr_accessor :version, :decision_sheet,
5
+ :conjuction_part, :part_version, :trf_publisher,
6
+ :trf_series, :trf_version, :test_type
7
+
8
+ def initialize(publisher: "IEC", decision_sheet: nil, trf_publisher: nil,
9
+ trf_series: nil, trf_version: nil, test_type: nil,
10
+ **args)
11
+ @decision_sheet = decision_sheet if decision_sheet
12
+ @trf_publisher = trf_publisher.to_s if trf_publisher
13
+ @trf_series = trf_series if trf_series
14
+ @trf_version = trf_version.to_s if trf_version
15
+ @test_type = test_type if test_type
16
+
17
+ super(**args.merge(publisher: publisher))
18
+ end
19
+
20
+ def urn
21
+ Renderer::TrfUrn.new(get_params).render
22
+ end
23
+
24
+ class << self
25
+ def get_parser_class
26
+ TrfParser
27
+ end
28
+
29
+ def get_renderer_class
30
+ Renderer::TrfPubid
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,60 @@
1
+ require "pubid-core"
2
+
3
+ module Pubid::Iec
4
+ class TrfParser < Parser
5
+ rule(:trf_version) do
6
+ (match["A-Z"].maybe >> (str("_") >> match["IVX"].repeat(1)).maybe).as(:trf_version)
7
+ end
8
+
9
+ rule(:decision_sheet) do
10
+ (str("_DS") | str("_ds")).as(:decision_sheet)
11
+ end
12
+
13
+ rule(:test_type) do
14
+ str("_") >> (str("EMC") | str("SOF") | str("PS")).as(:test_type)
15
+ end
16
+
17
+ rule(:part) do
18
+ (str("-") | str("/")) >> space? >> (match['[\d]'] | str("-")).repeat(1).as(:part)
19
+ end
20
+
21
+ rule(:trf_series) do
22
+ str("_SE").as(:trf_series)
23
+ end
24
+
25
+ rule(:iecee_document_body) do
26
+ str("TRF").as(:type) >> space >>
27
+ (organization.as(:trf_publisher) >> space).maybe >>
28
+ ((digits | str("SYMBOL")) >> match("[A-Z]").maybe).as(:number) >>
29
+ part.maybe >>
30
+ conjuction_part.maybe >>
31
+ trf_version.maybe >>
32
+ test_type.maybe >>
33
+ trf_series.maybe >>
34
+ (space? >> str(":") >> year).maybe
35
+ end
36
+
37
+ rule(:iecex_document_body) do
38
+ str("TRF").as(:type) >> space >>
39
+ (organization.as(:trf_publisher) >> space).maybe >>
40
+ ((digits | str("SYMBOL")) >> match("[A-Z]").maybe).as(:number) >>
41
+ part.maybe >>
42
+ edition.maybe >>
43
+ trf_version.maybe >>
44
+ test_type.maybe >>
45
+ decision_sheet.maybe >>
46
+ (space? >> str(":") >> year).maybe
47
+ end
48
+
49
+ rule(:identifier) do
50
+ ((str("IECEx").as(:publisher) >> space >> iecex_document_body) |
51
+ (str("IECEE").as(:publisher) >> space >> iecee_document_body)) #>>
52
+ # decision_sheet.maybe >>
53
+ # trf_series.maybe >>
54
+ # edition.maybe >>
55
+ # (str(":") >> year).maybe
56
+ end
57
+
58
+ rule(:root) { identifier }
59
+ end
60
+ end
@@ -0,0 +1,75 @@
1
+ module Pubid::Iec
2
+ class Type
3
+ attr_accessor :type
4
+
5
+ TYPE_NAMES = {
6
+ is: {
7
+ long: "International Standard",
8
+ short: "IS",
9
+ },
10
+ ts: {
11
+ long: "Technical Specification",
12
+ short: "TS",
13
+ },
14
+ tr: {
15
+ long: "Technical Report",
16
+ short: "TR",
17
+ },
18
+ pas: {
19
+ long: "Publicly Available Specification",
20
+ short: "PAS",
21
+ },
22
+ srd: {
23
+ short: "SRD",
24
+ },
25
+ tec: {
26
+ short: "TEC",
27
+ },
28
+ sttr: {
29
+ short: "STTR",
30
+ },
31
+ wp: {
32
+ short: "WP",
33
+ },
34
+ guide: {
35
+ long: "Guide",
36
+ short: "Guide",
37
+ },
38
+ od: {
39
+ short: "OD",
40
+ },
41
+ cs: {
42
+ short: "CS",
43
+ },
44
+ ca: {
45
+ short: "CA",
46
+ },
47
+ trf: {
48
+ long: "Test Report Form",
49
+ short: "TRF",
50
+ }
51
+
52
+ }.freeze
53
+
54
+ # Create new type
55
+ # @param type [Symbol]
56
+ def initialize(type = :is)
57
+ type = type.to_s.downcase.to_sym unless type.is_a?(Symbol)
58
+
59
+ raise Errors::WrongTypeError, "#{type} type is not available" unless TYPE_NAMES.key?(type)
60
+
61
+ @type = type
62
+ end
63
+
64
+ def self.parse(type_string)
65
+ TYPE_NAMES.each do |type, values|
66
+ return new(type) if values[:short].upcase == type_string.to_s.upcase
67
+ end
68
+ raise Errors::ParseTypeError, "Cannot parse '#{type_string}' type"
69
+ end
70
+
71
+ def to_s(format = :short)
72
+ TYPE_NAMES[type][format]
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,5 @@
1
+ module Pubid
2
+ module Iec
3
+ VERSION = "0.1.1".freeze
4
+ end
5
+ end
data/lib/pubid/iec.rb ADDED
@@ -0,0 +1,23 @@
1
+ require "parslet"
2
+ require "yaml"
3
+
4
+ module Pubid
5
+ module Iec
6
+ UPDATE_CODES = YAML.load_file(File.join(File.dirname(__FILE__), "../../update_codes.yaml"))
7
+ end
8
+ end
9
+
10
+ require_relative "iec/errors"
11
+ require_relative "iec/stage"
12
+ require_relative "iec/type"
13
+ require_relative "iec/parser"
14
+ require_relative "iec/trf_parser"
15
+ require_relative "iec/amendment"
16
+ require_relative "iec/corrigendum"
17
+ require_relative "iec/renderer/pubid"
18
+ require_relative "iec/renderer/trf_pubid"
19
+ require_relative "iec/renderer/urn"
20
+ require_relative "iec/renderer/trf_urn"
21
+ require_relative "iec/transformer"
22
+ require_relative "iec/identifier"
23
+ require_relative "iec/trf_identifier"
data/lib/pubid-iec.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "pubid/iec"
data/update_codes.yaml ADDED
@@ -0,0 +1,59 @@
1
+ IECEx TRF 60079-11v3-4:2002: IECEx TRF 60079-11v4C:2002
2
+ IECEE TRF cispr 15N:2022: IECEE TRF CISPR 15N:2022
3
+ IECEE TRF cispr 15M:2021: IECEE TRF CISPR 15M:2021
4
+ IECEE TRF cispr 15L:2020: IECEE TRF CISPR 15L:2020
5
+ IECEE TRF cispr 14-1A:2022: IECEE TRF CISPR 14-1A:2022
6
+ IECEE TRF cispr 14-1J:2022: IECEE TRF CISPR 14-1J:2022
7
+ IECEE TRF cispr 14-1,2B:2021: IECEE TRF CISPR 14-1,2B:2021
8
+ IECEE TRF cispr 14-1,2I:2020: IECEE TRF CISPR 14-1,2I:2020
9
+ IECEE TRF 60127-2-IA_I:2008: IECEE TRF 60127-2A_I:2008
10
+ IECEE TRF 60127-2-IIA_II:2008: IECEE TRF 60127-2A_II:2008
11
+ IECEE TRF 60127-2-IIIAIII:2008: IECEE TRF 60127-2A_III:2008
12
+ IECEE TRF 60127-2-IVIV:2008: IECEE TRF 60127-2A_IV:2008
13
+ IECEE TRF 60127-2-iBI:2011: IECEE TRF 60127-2B_I:2011
14
+ IECEE TRF 60127-2-iiBII:2011: IECEE TRF 60127-2B_II:2011
15
+ IECEE TRF 60127-2-iiiBIII:2011: IECEE TRF 60127-2B_III:2011
16
+ IECEE TRF 60127-2-ivBIV:2011: IECEE TRF 60127-2B_IV:2011
17
+ IECEE TRF 60127-2-iCI:2013: IECEE TRF 60127-2C_I:2013
18
+ IECEE TRF 60127-2-iiCII:2013: IECEE TRF 60127-2C_II:2013
19
+ IECEE TRF 60127-2-iiiCIII:2013: IECEE TRF 60127-2C_III:2013
20
+ IECEE TRF 60127-2-ivCIV:2013: IECEE TRF 60127-2C_IV:2013
21
+ IECEE TRF 60127-2-iD_I:2015: IECEE TRF 60127-2D_I:2015
22
+ IECEE TRF 60127-2-iiD_II:2015: IECEE TRF 60127-2D_II:2015
23
+ IECEE TRF 60127-2-iiiD_III:2015: IECEE TRF 60127-2D_III:2015
24
+ IECEE TRF 60127-2-ivD_IV:2019: IECEE TRF 60127-2D_IV:2019
25
+ IECEE TRF 60127-3-IA_I:2009: IECEE TRF 60127-3A_I:2009
26
+ IECEE TRF 60127-3-IIAII:2009: IECEE TRF 60127-3A_II:2009
27
+ IECEE TRF 60127-3-IIIAIII:2009: IECEE TRF 60127-3A_III:2009
28
+ IECEE TRF 60127-3-IVAIV:2009: IECEE TRF 60127-3A_IV:2009
29
+ IECEE TRF 60127-3-iBI:2013: IECEE TRF 60127-3B_I:2013
30
+ IECEE TRF 60127-3-iiBII:2013: IECEE TRF 60127-3B_II:2013
31
+ IECEE TRF 60127-3-iiiBIII:2013: IECEE TRF 60127-3B_III:2013
32
+ IECEE TRF 60127-3-ivBIV:2013: IECEE TRF 60127-3B_IV:2013
33
+ IECEE TRF 60127-3-iCI:2015: IECEE TRF 60127-3C_I:2015
34
+ IECEE TRF 60127-3-iiCII:2015: IECEE TRF 60127-3C_II:2015
35
+ IECEE TRF 60127-3-iiiCIII:2015: IECEE TRF 60127-3C_III:2015
36
+ IECEE TRF 60127-3-ivCIV:2015: IECEE TRF 60127-3C_IV:2015
37
+ IECEE TRF 60127-3-iD_I:2022: IECEE TRF 60127-3D_I:2022
38
+ IECEE TRF 60127-3-iiD_II:2022: IECEE TRF 60127-3D_II:2022
39
+ IECEE TRF 60127-3-iiiD_III:2022: IECEE TRF 60127-3D_III:2022
40
+ IECEE TRF 60127-3-ivD_IV:2022: IECEE TRF 60127-3D_IV:2022
41
+ IECEE TRF 60127-4-IAI:2009: IECEE TRF 60127-4A_I:2009
42
+ IECEE TRF 60127-4-IIAII:2009: IECEE TRF 60127-4A_II:2009
43
+ IECEE TRF 60127-4-IIIAIII:2009: IECEE TRF 60127-4A_III:2009
44
+ IECEE TRF 60127-4-iBI:2013: IECEE TRF 60127-4B_I:2013
45
+ IECEE TRF 60127-4-iiBII:2013: IECEE TRF 60127-4B_II:2013
46
+ IECEE TRF 60127-4-iiiBIII:2013: IECEE TRF 60127-4B_III:2013
47
+ IECEE TRF 60127-4-iCI:2015: IECEE TRF 60127-4C_I:2015
48
+ IECEE TRF 60127-4-iiCII:2015: IECEE TRF 60127-4C_II:2015
49
+ IECEE TRF 60127-4-iiiCIII:2015: IECEE TRF 60127-4C_III:2015
50
+ IECEE TRF 60127-4-iD_I:2022: IECEE TRF 60127-4D_I:2022
51
+ IECEE TRF 60127-4-iiD_II:2022: IECEE TRF 60127-4D_II:2022
52
+ IECEE TRF 60127-4-iiD_III:2022: IECEE TRF 60127-4D_III:2022
53
+ IECEE TRF 60730-1KSOF:2020: IECEE TRF 60730-1K_SOF:2020
54
+ IECEE TRF 60730-1KEMC:2020: IECEE TRF 60730-1K_EMC:2020
55
+ IECEE TRF 60730-1ISOF:2018: IECEE TRF 60730-1I_SOF:2018
56
+ IECEE TRF 60730-1HSOF:2014: IECEE TRF 60730-1H_SOF:2014
57
+ IECEE TRF 60730-1HEMC:2014: IECEE TRF 60730-1H_EMC:2014
58
+ IECEE TRF 60730-2-1IEMC:2019: IECEE TRF 60730-2-1I_EMC:2019
59
+ IECEE TRF 60601-1-2CEMC:2011: IECEE TRF 60601-1-2C_EMC:2011
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pubid-iec
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: 2023-03-09 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: parslet
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: pubid-core
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.4.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.4.0
69
+ description: Library to generate, parse and manipulate IEC PubID.
70
+ email:
71
+ - open.source@ribose.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files:
75
+ - README.adoc
76
+ - LICENSE.txt
77
+ files:
78
+ - LICENSE.txt
79
+ - README.adoc
80
+ - lib/pubid-iec.rb
81
+ - lib/pubid/iec.rb
82
+ - lib/pubid/iec/amendment.rb
83
+ - lib/pubid/iec/corrigendum.rb
84
+ - lib/pubid/iec/errors.rb
85
+ - lib/pubid/iec/identifier.rb
86
+ - lib/pubid/iec/parser.rb
87
+ - lib/pubid/iec/renderer/pubid.rb
88
+ - lib/pubid/iec/renderer/trf_pubid.rb
89
+ - lib/pubid/iec/renderer/trf_urn.rb
90
+ - lib/pubid/iec/renderer/urn.rb
91
+ - lib/pubid/iec/stage.rb
92
+ - lib/pubid/iec/transformer.rb
93
+ - lib/pubid/iec/trf_identifier.rb
94
+ - lib/pubid/iec/trf_parser.rb
95
+ - lib/pubid/iec/type.rb
96
+ - lib/pubid/iec/version.rb
97
+ - update_codes.yaml
98
+ homepage: https://github.com/metanorma/pubid-iec
99
+ licenses:
100
+ - BSD-2-Clause
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 2.5.0
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubygems_version: 3.0.3.1
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Library to generate, parse and manipulate IEC PubID.
121
+ test_files: []