pubid-iho 1.15.14

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: 01f5399345d0c833d5ad0242b5fd0c6d81e32d302816bdcfbf9066afb7b35850
4
+ data.tar.gz: b367f737353afc92cbc93d61fc92c6d4f47296db7edd054a7a8d61f1b710fd92
5
+ SHA512:
6
+ metadata.gz: 4676d43aaa9349f610d54e5ab9a566719485e4cbf7e354954269782410e3cf673d1b5339d2add2886d9de97ef4472b6895a36a31cc8f72ee1685b3c837391264
7
+ data.tar.gz: 1d934efc20a0f636cc0b7b7a04ac3c853a4927704c2cdc78df25f8a3bed7c58b069d399ec3c8d7d54528960c49fc05fbe17bb4e7c1fc807dac2a00681e3e69f2
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,44 @@
1
+ = IHO publication identifiers ("IHO PubID")
2
+
3
+ == Purpose
4
+
5
+ This gem implements a mechanism to parse and render IHO (International
6
+ Hydrographic Organization) publication identifiers.
7
+
8
+ == Usage
9
+
10
+ === Parsing
11
+
12
+ [source,ruby]
13
+ ----
14
+ require "pubid-iho"
15
+
16
+ pubid = Pubid::Iho::Identifier.parse("IHO S-100 5.2.0")
17
+ pubid.to_s
18
+ # => "IHO S-100 5.2.0"
19
+
20
+ pubid = Pubid::Iho::Identifier.parse("IHO S-100 Part 1 1.0.0")
21
+ pubid.to_s
22
+ # => "IHO S-100 Part 1 1.0.0"
23
+
24
+ pubid = Pubid::Iho::Identifier.parse("IHO S-65 Ap. B 1.2.0")
25
+ pubid.to_s
26
+ # => "IHO S-65 Ap. B 1.2.0"
27
+ ----
28
+
29
+ The `IHO` prefix is optional on input and added on render:
30
+
31
+ [source,ruby]
32
+ ----
33
+ Pubid::Iho::Identifier.parse("S-44 5.0.0").to_s
34
+ # => "IHO S-44 5.0.0"
35
+ ----
36
+
37
+ === Identifier creation
38
+
39
+ [source,ruby]
40
+ ----
41
+ pubid = Pubid::Iho::Identifier.create(type: "S", number: "100", part: "1", version: "1.0.0")
42
+ pubid.to_s
43
+ # => "IHO S-100 Part 1 1.0.0"
44
+ ----
@@ -0,0 +1,4 @@
1
+ module Pubid::Iho
2
+ module Errors
3
+ end
4
+ end
@@ -0,0 +1,42 @@
1
+ module Pubid::Iho
2
+ module Identifier
3
+ class Base < Pubid::Core::Identifier::Base
4
+ attr_accessor :version, :appendix
5
+
6
+ def self.type
7
+ { key: :iho }
8
+ end
9
+
10
+ def initialize(type:, publisher: "IHO", version: nil, part: nil, appendix: nil, **opts)
11
+ super(**opts.merge(publisher: publisher))
12
+ @part = part.to_s if part
13
+ @version = version.to_s if version
14
+ @appendix = appendix.to_s if appendix
15
+ if type
16
+ unless Identifier.config.type_names.map { |_, v| v[:short] }.include?(type.to_s)
17
+ raise Pubid::Core::Errors::WrongTypeError, "Type '#{type}' is not available"
18
+ end
19
+ @type = type.to_s
20
+ end
21
+ end
22
+
23
+ class << self
24
+ def transform(params)
25
+ identifier_params = params.map do |k, v|
26
+ get_transformer_class.new.apply(k => v)
27
+ end.inject({}, :merge)
28
+
29
+ Identifier.create(**identifier_params)
30
+ end
31
+
32
+ def get_parser_class
33
+ Parser
34
+ end
35
+
36
+ def get_renderer_class
37
+ Renderer::Base
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ module Pubid::Iho
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
+ end
23
+ end
24
+ end
@@ -0,0 +1,34 @@
1
+ module Pubid::Iho
2
+ class Parser < Pubid::Core::Parser
3
+ rule(:series) do
4
+ array_to_str(%w[S P M B C]).as(:type)
5
+ end
6
+
7
+ rule(:number_suffix) do
8
+ (str(":") >> digits) | (str("/") >> digits) | (dash >> digits) | match("[A-Z]")
9
+ end
10
+
11
+ rule(:number) do
12
+ (digits >> number_suffix.maybe).as(:number)
13
+ end
14
+
15
+ rule(:appendix) do
16
+ space >> str("Ap.") >> space >> (digits | match("[A-Z]")).as(:appendix)
17
+ end
18
+
19
+ rule(:part) do
20
+ space >> str("Part") >> space >> (digits | match("[A-Z]")).as(:part)
21
+ end
22
+
23
+ rule(:version) do
24
+ space >> (digits >> dot >> digits >> dot >> digits).as(:version)
25
+ end
26
+
27
+ rule(:identifier) do
28
+ (str("IHO") >> space).maybe >> series >> dash >> number >>
29
+ appendix.maybe >> part.maybe >> version.maybe
30
+ end
31
+
32
+ rule(:root) { identifier }
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ module Pubid::Iho::Renderer
2
+ class Base < Pubid::Core::Renderer::Base
3
+ def render_identifier(params)
4
+ "%{publisher} %{type}-%{number}%{appendix}%{part}%{version}" % params
5
+ end
6
+
7
+ def render_part(part, _opts, _params)
8
+ " Part #{part}"
9
+ end
10
+
11
+ def render_appendix(appendix, _opts, _params)
12
+ " Ap. #{appendix}"
13
+ end
14
+
15
+ def render_version(version, _opts, _params)
16
+ " #{version}"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module Pubid
2
+ module Iho
3
+ VERSION = "1.15.14".freeze
4
+ end
5
+ end
data/lib/pubid/iho.rb ADDED
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "parslet"
4
+
5
+ module Pubid
6
+ module Iho
7
+ end
8
+ end
9
+
10
+ require "pubid-core"
11
+
12
+ require_relative "iho/version"
13
+ require_relative "iho/errors"
14
+ require_relative "iho/identifier"
15
+ require_relative "iho/identifier/base"
16
+ require_relative "iho/renderer/base"
17
+
18
+ config = Pubid::Core::Configuration.new
19
+ config.default_type = Pubid::Iho::Identifier::Base
20
+ config.types = [Pubid::Iho::Identifier::Base]
21
+
22
+ config.type_names = {
23
+ s: {
24
+ long: "Standards and Specifications",
25
+ short: "S",
26
+ },
27
+ p: {
28
+ long: "Publication",
29
+ short: "P",
30
+ },
31
+ m: {
32
+ long: "Miscellaneous Publication",
33
+ short: "M",
34
+ },
35
+ b: {
36
+ long: "Bibliographic Publication",
37
+ short: "B",
38
+ },
39
+ c: {
40
+ long: "Circular Letter",
41
+ short: "C",
42
+ },
43
+ }
44
+ Pubid::Iho::Identifier.set_config(config)
45
+
46
+ require_relative "iho/parser"
data/lib/pubid-iho.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "pubid/iho"
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pubid-iho
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.15.14
5
+ platform: ruby
6
+ authors:
7
+ - Ribose Inc.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parslet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pubid-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.15.14
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.15.14
41
+ description: Library to generate, parse and manipulate IHO PubID.
42
+ email:
43
+ - open.source@ribose.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - README.adoc
48
+ - LICENSE.txt
49
+ files:
50
+ - LICENSE.txt
51
+ - README.adoc
52
+ - lib/pubid-iho.rb
53
+ - lib/pubid/iho.rb
54
+ - lib/pubid/iho/errors.rb
55
+ - lib/pubid/iho/identifier.rb
56
+ - lib/pubid/iho/identifier/base.rb
57
+ - lib/pubid/iho/parser.rb
58
+ - lib/pubid/iho/renderer/base.rb
59
+ - lib/pubid/iho/version.rb
60
+ homepage: https://github.com/metanorma/pubid-iho
61
+ licenses:
62
+ - BSD-2-Clause
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 2.5.0
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubygems_version: 3.5.22
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Library to generate, parse and manipulate IHO PubID.
83
+ test_files: []