pubid-etsi 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: accb82a61ec1980ce258834e0a471599f1efea7bcda45d7aecf192c050b25d60
4
+ data.tar.gz: 3660ac602ce7823b64e543dbd514ca1fb58f4e24438740097e7bd898dbfccfad
5
+ SHA512:
6
+ metadata.gz: dc4e5e2b684c156a3aa8bbb9086866dcf995e4a39be44456098a55aacdd39da8c7e5279ca13b3e9855edef8d4f06d5ebaba8dd8d6e8ebdf594657a16f498e691
7
+ data.tar.gz: 938a8735a7dd5cad1e67638b3523e7e4d5b82d36d0643e3073f631bd336e54daac4678d3d743d78b7b0c9a0ac3df04840805ba1bfcf16d96717ad01eb997aefc
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,26 @@
1
+ = ETSI publication identifiers ("ETSI PubID")
2
+
3
+ == Purpose
4
+
5
+ This gem implements a mechanism to parse and utilize ETSI publication
6
+ identifiers.
7
+
8
+ == Use cases to support
9
+
10
+ . generate updated PubID
11
+
12
+ == Usage
13
+
14
+ === Identifier creation
15
+
16
+ Basic usage of the pubid-ccsds gem starts with the `Identifier#create` method.
17
+
18
+ [source,ruby]
19
+ ----
20
+ require "pubid-etsi"
21
+
22
+ pubid = Pubid::Etsi::Identifier.create(type: "EN", number: 1234, minor: 123, part: 4, version: "1.2.3", date: "1999-01")
23
+ pubid.to_s
24
+
25
+ => "ETSI EN 1234 123-4 V1.2.3 (1999-01)"
26
+ ----
@@ -0,0 +1,5 @@
1
+ module Pubid::Etsi
2
+ module Errors
3
+
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module Pubid::Etsi
2
+ module Identifier
3
+ class Amendment < Supplement
4
+ def_delegators 'Pubid::Etsi::Identifier::Amendment', :type
5
+
6
+ def self.type
7
+ { key: :amendment, title: "Amendment" }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,60 @@
1
+ require 'forwardable'
2
+
3
+ module Pubid::Etsi
4
+ module Identifier
5
+ class Base < Pubid::Core::Identifier::Base
6
+ extend Forwardable
7
+
8
+ attr_accessor :version, :published
9
+
10
+ def self.type
11
+ { key: :etsi }
12
+ end
13
+
14
+ def initialize(type:, published:, publisher: "ETSI", version: nil, part: nil, **opts)
15
+ super(**opts.merge(publisher: publisher))
16
+ @published = published
17
+ @version = version
18
+ @part = part
19
+ if type
20
+ unless Identifier.config.type_names.map { |_, v| v[:short] }.include?(type)
21
+ raise Pubid::Core::Errors::WrongTypeError, "Type '#{type}' is not available"
22
+ end
23
+ @type = type
24
+ end
25
+ end
26
+
27
+ class << self
28
+ def transform_supplements(type, identifier_params)
29
+ Identifier.create(
30
+ type: type,
31
+ base: transform(
32
+ **identifier_params.dup.tap { |h| h.delete(type) },
33
+ ),
34
+ **identifier_params[type],
35
+ )
36
+ end
37
+
38
+ # Use Identifier#create to resolve identifier's type class
39
+ def transform(params)
40
+ identifier_params = params.map do |k, v|
41
+ get_transformer_class.new.apply(k => v)
42
+ end.inject({}, :merge)
43
+
44
+ %i(amendment corrigendum).each do |type|
45
+ return transform_supplements(type, identifier_params) if identifier_params[type]
46
+ end
47
+ Identifier.create(**identifier_params)
48
+ end
49
+
50
+ def get_parser_class
51
+ Parser
52
+ end
53
+
54
+ def get_renderer_class
55
+ Renderer::Base
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,11 @@
1
+ module Pubid::Etsi
2
+ module Identifier
3
+ class Corrigendum < Supplement
4
+ def_delegators 'Pubid::Etsi::Identifier::Corrigendum', :type
5
+
6
+ def self.type
7
+ { key: :corrigendum, title: "Corrigendum" }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ module Pubid::Etsi
2
+ module Identifier
3
+ class Supplement < Base
4
+ attr_accessor :base
5
+
6
+ def initialize(base:, number:)
7
+ @base = base
8
+ @number = number
9
+ end
10
+
11
+ def to_h
12
+ @base.to_h.merge(self.type[:key] => super)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ module Pubid::Etsi
2
+ module Identifier
3
+ class << self
4
+ include Pubid::Core::Identifier
5
+
6
+ # @see Pubid::Identifier::Base.parse
7
+ def parse(*args)
8
+ Base.parse(*args)
9
+ end
10
+
11
+ def resolve_identifier(parameters = {})
12
+ return @config.default_type.new(**parameters) if parameters[:type].nil?
13
+
14
+ @config.types.each do |identifier_type|
15
+ if identifier_type.type_match?(parameters)
16
+ return identifier_type.new(**parameters.reject { |k, _| k == :type })
17
+ end
18
+ end
19
+
20
+ @config.default_type.new(**parameters)
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,58 @@
1
+ module Pubid::Etsi
2
+ class Parser < Pubid::Core::Parser
3
+ TYPE_NAMES = Identifier.config.type_names.map { |_, v| v[:short] }
4
+ rule(:edition) do
5
+ dash >> (digits >> (dot >> digits).maybe).as(:edition)
6
+ end
7
+
8
+ rule(:part) do
9
+ (dash.ignore >> (digits | match("[A-Z]").repeat(3, 3))).as(:part).repeat(1)
10
+ end
11
+
12
+ rule(:type) do
13
+ array_to_str(TYPE_NAMES).as(:type)
14
+ end
15
+
16
+ rule(:version) do
17
+ str("V") >> match("[0-9\.]").repeat(1).as(:version)
18
+ end
19
+
20
+ rule(:published_date) do
21
+ str("(") >> (year_digits >> dash >> month_digits).as(:published) >> str(")")
22
+ end
23
+
24
+ rule(:edition) do
25
+ str("ed.") >> digits.as(:edition)
26
+ end
27
+
28
+ rule(:amendment) do
29
+ str("/A") >> digits.as(:number).as(:amendment)
30
+ end
31
+
32
+ rule(:corrigendum) do
33
+ str("/C") >> digits.as(:number).as(:corrigendum)
34
+ end
35
+
36
+ rule(:number) do
37
+ (
38
+ # for identifiers like ETSI GTS GSM 02.01 V5.5.0
39
+ (str("GSM ").maybe.ignore >> match('[\d]').repeat(2, 2) >> dot >>
40
+ match('[\d]').repeat(2, 2)) |
41
+ (match('[A-Za-z\d]').repeat(3, 3) >>
42
+ (dash >> match("[A-Z]").repeat(3, 3)).maybe >>
43
+ (space >> match('\d').repeat(3, 3)).maybe)
44
+ ).as(:number)
45
+ end
46
+
47
+ # ETSI ETR 299-1 ed.1 (1996-09)
48
+ # ETSI ETR 298 ed.1 (1996-09)
49
+ #
50
+ rule(:identifier) do
51
+ str("ETSI") >> space >> type >> space >>
52
+ number >> part.maybe >> amendment.maybe >> corrigendum.maybe >> space >>
53
+ (version | edition) >> space >> published_date
54
+ end
55
+
56
+ rule(:root) { identifier }
57
+ end
58
+ end
@@ -0,0 +1,37 @@
1
+ module Pubid::Etsi::Renderer
2
+ class Base < Pubid::Core::Renderer::Base
3
+ TYPE = "".freeze
4
+
5
+ def render_identifier(params)
6
+ "%{publisher} %{type} %{number}%{part}%{amendment}%{corrigendum}%{version}%{edition}%{published}" % params
7
+ end
8
+
9
+ def render_version(version, _opts, _params)
10
+ " V#{version}"
11
+ end
12
+
13
+ def render_published(published, _opts, _params)
14
+ " (#{published})"
15
+ end
16
+
17
+ def render_edition(edition, _opts, _params)
18
+ " ed.#{edition}"
19
+ end
20
+
21
+ def render_part(part, _opts, _params)
22
+ if part.is_a?(Array)
23
+ "-#{part.join("-")}"
24
+ else
25
+ "-#{part}"
26
+ end
27
+ end
28
+
29
+ def render_amendment(amendment, _opts, _params)
30
+ "/A#{amendment[:number]}"
31
+ end
32
+
33
+ def render_corrigendum(corrigendum, _opts, _params)
34
+ "/C#{corrigendum[:number]}"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ module Pubid
2
+ module Etsi
3
+ VERSION = "0.0.2".freeze
4
+ end
5
+ end
data/lib/pubid/etsi.rb ADDED
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "parslet"
4
+ require "yaml"
5
+
6
+ module Pubid
7
+ module Etsi
8
+
9
+ end
10
+ end
11
+
12
+ require "pubid-core"
13
+
14
+ require_relative "etsi/identifier"
15
+ require_relative "etsi/identifier/base"
16
+ require_relative "etsi/identifier/supplement"
17
+ require_relative "etsi/identifier/amendment"
18
+ require_relative "etsi/identifier/corrigendum"
19
+ require_relative "etsi/renderer/base"
20
+
21
+ config = Pubid::Core::Configuration.new
22
+ config.default_type = Pubid::Etsi::Identifier::Base
23
+ config.types = [Pubid::Etsi::Identifier::Base,
24
+ Pubid::Etsi::Identifier::Amendment,
25
+ Pubid::Etsi::Identifier::Corrigendum]
26
+
27
+ config.type_names = {
28
+ en: {
29
+ long: "European Standard",
30
+ short: "EN",
31
+ },
32
+ es: {
33
+ long: "ETSI Standard",
34
+ short: "ES",
35
+ },
36
+ eg: {
37
+ long: "ETSI Guide",
38
+ short: "EG",
39
+ },
40
+ ts: {
41
+ long: "Technical Specification",
42
+ short: "TS",
43
+ },
44
+ etr: {
45
+ long: "European telecommunications report",
46
+ short: "ETR",
47
+ },
48
+ ets: {
49
+ long: "European telecommunications standard",
50
+ short: "ETS",
51
+ },
52
+ iets: {
53
+ long: "Provisional ETS",
54
+ short: "I-ETS",
55
+ },
56
+ tbr: {
57
+ long: "Technical Basis for Regulation",
58
+ short: "TBR",
59
+ },
60
+ tcrtr: {
61
+ long: "Technical Committee Report - Technical Report",
62
+ short: "TCRTR",
63
+ },
64
+ net: {
65
+ long: "Norme Européenne de Télécommunication",
66
+ short: "NET",
67
+ },
68
+ gr: {
69
+ long: "Group Report",
70
+ short: "GR",
71
+ },
72
+ gs: {
73
+ long: "Group Specification",
74
+ short: "GS",
75
+ },
76
+ sr: {
77
+ long: "Special Report",
78
+ short: "SR",
79
+ },
80
+ tr: {
81
+ long: "Technical Report",
82
+ short: "TR",
83
+ },
84
+ gts: {
85
+ long: "GSM Technical Specification",
86
+ short: "GTS",
87
+ }
88
+ }
89
+ Pubid::Etsi::Identifier.set_config(config)
90
+
91
+ require_relative "etsi/parser"
data/lib/pubid-etsi.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "pubid/etsi"
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pubid-etsi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Ribose Inc.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-11-13 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.10.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.10.3
69
+ description: Library to generate, parse and manipulate ETSI 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-etsi.rb
81
+ - lib/pubid/etsi.rb
82
+ - lib/pubid/etsi/errors.rb
83
+ - lib/pubid/etsi/identifier.rb
84
+ - lib/pubid/etsi/identifier/amendment.rb
85
+ - lib/pubid/etsi/identifier/base.rb
86
+ - lib/pubid/etsi/identifier/corrigendum.rb
87
+ - lib/pubid/etsi/identifier/supplement.rb
88
+ - lib/pubid/etsi/parser.rb
89
+ - lib/pubid/etsi/renderer/base.rb
90
+ - lib/pubid/etsi/version.rb
91
+ homepage: https://github.com/metanorma/pubid-etsi
92
+ licenses:
93
+ - BSD-2-Clause
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 2.5.0
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubygems_version: 3.3.26
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Library to generate, parse and manipulate ETSI PubID.
114
+ test_files: []