pubid-jis 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: aaeab5258bdddf833c4ab9918d0973abfb23993ac3e6433b9fd73e4c9c6b2f6d
4
+ data.tar.gz: ef707e6ec8b8d989b2376a46266388c4a9fdb1f577b25b991accf56dcc772877
5
+ SHA512:
6
+ metadata.gz: 450467f6397bad16e962d7b15628d1cb8b91d169cf5d6d76b551593b63a99df3a1910bfd415b97ac805964c6b31eb3ca76649f3c0c3d9caeb599fc1e55d4c1dc
7
+ data.tar.gz: 1a1ba91e716740b9d1e9b135a9c72e3dca0f351ce0682d9fc92bf763e3438df6d706be880f15f6e5f2821c14032c273ebe45de0c36d89ce02a681aadca7797d7
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
+ = JIS publication identifiers ("JIS PubID")
2
+
3
+ == Purpose
4
+
5
+ This gem implements a mechanism to parse and utilize JIS 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-jis gem starts with the `Identifier#create` method.
17
+
18
+ [source,ruby]
19
+ ----
20
+ require "pubid-jis"
21
+
22
+ pubid = Pubid::Jis::Identifier.create(number: 1234, series: "A", part: 1, year: 1999, language: "E")
23
+ pubid.to_s
24
+
25
+ => "JIS A 1234-1:1999(E)"
26
+ ----
@@ -0,0 +1,6 @@
1
+ module Pubid::Bsi
2
+ module Errors
3
+ class ParseTypeError < StandardError; end
4
+ class SupplementParsingError < StandardError; end
5
+ end
6
+ end
@@ -0,0 +1,24 @@
1
+ require_relative "../renderer/amendment"
2
+
3
+ module Pubid::Jis
4
+ module Identifier
5
+ class Amendment < Base
6
+ attr_accessor :base
7
+
8
+ def_delegators 'Pubid::Jis::Identifier::Amendment', :type
9
+
10
+ def initialize(base: nil, **opts)
11
+ super(**opts)
12
+ @base = base
13
+ end
14
+
15
+ def self.type
16
+ { key: :amd, title: "Amendment", short: "AMD" }
17
+ end
18
+
19
+ def self.get_renderer_class
20
+ Renderer::Amendment
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,73 @@
1
+ require 'forwardable'
2
+
3
+ module Pubid::Jis
4
+ module Identifier
5
+ class Base < Pubid::Core::Identifier::Base
6
+ attr_accessor :series, :all_parts
7
+ extend Forwardable
8
+
9
+ def self.type
10
+ { key: :jis, title: "Japanese Industrial Standard" }
11
+ end
12
+
13
+ # @param month [Integer] document's month
14
+ # @param edition [String] document's edition version, e.g. "3.0", "1.0"
15
+ def initialize(publisher: "JIS", series: nil, part: nil, all_parts: false, **opts)
16
+ super(**opts.merge(publisher: publisher))
17
+ @series = series if series
18
+ @part = part if part
19
+ @all_parts = all_parts
20
+ end
21
+
22
+ def all_parts?
23
+ all_parts
24
+ end
25
+
26
+ def ==(other)
27
+ if all_parts? || other.all_parts?
28
+ return get_params.reject { |k, _| [:part, :all_parts].include?(k) } ==
29
+ other.get_params.reject { |k, _| [:part, :all_parts].include?(k) }
30
+ end
31
+
32
+ super
33
+ end
34
+
35
+ class << self
36
+ def transform_supplements(supplements_params, base_params)
37
+ supplements = supplements_params.map do |supplement|
38
+ Identifier.create(number: supplement[:number], year: supplement[:year],
39
+ type: supplement[:type], base: Identifier.create(**base_params))
40
+ end
41
+
42
+ return supplements.first if supplements.count == 1
43
+
44
+ raise Errors::SupplementParsingError, "more than one or none supplements provided"
45
+ end
46
+
47
+ # Use Identifier#create to resolve identifier's type class
48
+ def transform(params)
49
+ identifier_params = params.map do |k, v|
50
+ get_transformer_class.new.apply(k => v)
51
+ end.inject({}, :merge)
52
+
53
+ if identifier_params[:supplements]
54
+ return transform_supplements(
55
+ identifier_params[:supplements],
56
+ identifier_params.dup.tap { |h| h.delete(:supplements) }
57
+ )
58
+ end
59
+
60
+ Identifier.create(**identifier_params)
61
+ end
62
+
63
+ def get_parser_class
64
+ Parser
65
+ end
66
+
67
+ def get_renderer_class
68
+ Renderer::Base
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,17 @@
1
+ require_relative "../renderer/technical_report"
2
+
3
+ module Pubid::Jis
4
+ module Identifier
5
+ class TechnicalReport < Base
6
+ def_delegators 'Pubid::Jis::Identifier::TechnicalReport', :type
7
+
8
+ def self.type
9
+ { key: :tr, title: "Technical Report", short: "TR" }
10
+ end
11
+
12
+ def self.get_renderer_class
13
+ Renderer::TechnicalReport
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require_relative "../renderer/technical_specification"
2
+
3
+ module Pubid::Jis
4
+ module Identifier
5
+ class TechnicalSpecification < Base
6
+ def_delegators 'Pubid::Jis::Identifier::TechnicalSpecification', :type
7
+
8
+ def self.type
9
+ { key: :ts, title: "Technical Specification", short: "TS" }
10
+ end
11
+
12
+ def self.get_renderer_class
13
+ Renderer::TechnicalSpecification
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module Pubid::Jis
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
+ end
11
+ end
12
+ end
@@ -0,0 +1,48 @@
1
+ module Pubid::Jis
2
+ class Parser < Pubid::Core::Parser
3
+
4
+ rule(:type) do
5
+ str("/").maybe >>
6
+ array_to_str(Identifier.config.types.map { |type| type.type[:short] }.compact).as(:type)
7
+ end
8
+
9
+ rule(:space) do
10
+ str(" ") | str(" ")
11
+ end
12
+
13
+ rule(:dash) do
14
+ str("-") | str("ー")
15
+ end
16
+
17
+ rule(:colon) do
18
+ str(":") | str(":")
19
+ end
20
+
21
+ rule(:series) do
22
+ match("[A-Z]").as(:series)
23
+ end
24
+
25
+ rule(:part) do
26
+ (dash >> digits.as(:part)).repeat
27
+ end
28
+
29
+ rule(:all_parts) do
30
+ (str("(規格群)") | str("(規格群)")).as(:all_parts)
31
+ end
32
+
33
+ rule(:language) do
34
+ str("(") >> match("[A-Z]").as(:language) >> str(")")
35
+ end
36
+
37
+ rule(:amendment) do
38
+ (str("/") >> str("AMD").as(:type) >> space >> digits.as(:number) >> colon >> year).repeat(1).as(:supplements)
39
+ end
40
+
41
+ rule(:identifier) do
42
+ str("JIS").maybe >> space? >> type.maybe >> space? >> series >> space? >> digits.as(:number) >> part >>
43
+ (colon >> year).maybe >> language.maybe >> all_parts.maybe >> amendment.maybe
44
+ end
45
+
46
+ rule(:root) { identifier }
47
+ end
48
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "base"
2
+
3
+ module Pubid::Jis::Renderer
4
+ class Amendment < Base
5
+ def render_identifier(params)
6
+ "%{base}/AMD %{number}%{year}" % params
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ module Pubid::Jis::Renderer
2
+ class Base < Pubid::Core::Renderer::Base
3
+ TYPE = "".freeze
4
+
5
+ def render_identifier(params)
6
+ "%{publisher}%{series} %{number}%{part}%{year}%{all_parts}" % params
7
+ end
8
+
9
+ def render_series(series, _opts, _params)
10
+ " #{series}"
11
+ end
12
+
13
+ def render_part(part, opts, _params)
14
+ return "-#{part.reverse.join('-')}" if part.is_a?(Array)
15
+
16
+ "-#{part}"
17
+ end
18
+
19
+ def render_all_parts(all_parts, _opts, _params)
20
+ "(規格群)" if all_parts
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "base"
2
+
3
+ module Pubid::Jis::Renderer
4
+ class TechnicalReport < Base
5
+ def render_identifier(params)
6
+ "%{publisher} TR%{series} %{number}%{part}%{year}%{all_parts}" % params
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "base"
2
+
3
+ module Pubid::Jis::Renderer
4
+ class TechnicalSpecification < Base
5
+ def render_identifier(params)
6
+ "%{publisher} TS%{series} %{number}%{part}%{year}%{all_parts}" % params
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Pubid
2
+ module Jis
3
+ VERSION = "0.1.1".freeze
4
+ end
5
+ end
data/lib/pubid/jis.rb ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "parslet"
4
+
5
+ module Pubid
6
+ end
7
+
8
+ require "pubid-core"
9
+
10
+ require_relative "jis/errors"
11
+ require_relative "jis/identifier/base"
12
+ require_relative "jis/identifier/technical_report"
13
+ require_relative "jis/identifier/technical_specification"
14
+ require_relative "jis/identifier/amendment"
15
+ require_relative "jis/renderer/base"
16
+ require_relative "jis/renderer/technical_report"
17
+ require_relative "jis/renderer/technical_specification"
18
+ require_relative "jis/renderer/amendment"
19
+ require_relative "jis/parser"
20
+ require_relative "jis/identifier"
21
+
22
+ config = Pubid::Core::Configuration.new
23
+ config.default_type = Pubid::Jis::Identifier::Base
24
+ config.types = [Pubid::Jis::Identifier::Base, Pubid::Jis::Identifier::TechnicalReport,
25
+ Pubid::Jis::Identifier::TechnicalSpecification, Pubid::Jis::Identifier::Amendment]
26
+ config.type_names = {}.freeze
27
+ Pubid::Jis::Identifier.set_config(config)
data/lib/pubid-jis.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "pubid/jis"
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pubid-jis
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-04-01 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
+ - !ruby/object:Gem::Dependency
98
+ name: pubid-core
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.8.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.8.0
111
+ description: Library to generate, parse and manipulate JIS PubID.
112
+ email:
113
+ - open.source@ribose.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files:
117
+ - README.adoc
118
+ - LICENSE.txt
119
+ files:
120
+ - LICENSE.txt
121
+ - README.adoc
122
+ - lib/pubid-jis.rb
123
+ - lib/pubid/jis.rb
124
+ - lib/pubid/jis/errors.rb
125
+ - lib/pubid/jis/identifier.rb
126
+ - lib/pubid/jis/identifier/amendment.rb
127
+ - lib/pubid/jis/identifier/base.rb
128
+ - lib/pubid/jis/identifier/technical_report.rb
129
+ - lib/pubid/jis/identifier/technical_specification.rb
130
+ - lib/pubid/jis/parser.rb
131
+ - lib/pubid/jis/renderer/amendment.rb
132
+ - lib/pubid/jis/renderer/base.rb
133
+ - lib/pubid/jis/renderer/technical_report.rb
134
+ - lib/pubid/jis/renderer/technical_specification.rb
135
+ - lib/pubid/jis/version.rb
136
+ homepage: https://github.com/metanorma/pubid-jis
137
+ licenses:
138
+ - BSD-2-Clause
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: 2.5.0
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubygems_version: 3.0.3.1
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Library to generate, parse and manipulate JIS PubID.
159
+ test_files: []