pubid-jis 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c0c791095c83e4b8722ee5231a32aaa67ef83bc79c7819010bc7b3b39896b86
4
- data.tar.gz: 73e325a24c1e57418037c4d14b793029c6203122325a0af3baf9de358e59d86c
3
+ metadata.gz: 07eef4940f4a38e169eebcd786cb2d4456814c9bb0ab6eafba78eaf619dee42b
4
+ data.tar.gz: 6e42254073b7bcb5d8a00fc5c1d8c74d0a0ac116340f8b25ba6a77bbbc8b4de8
5
5
  SHA512:
6
- metadata.gz: 072776bc60700e55cf0ba6c34f8be8aabb368d93f388e78ca676a7483cc093c051178336370eb301a26797a8d74d9f8f2f026e3c92bc543abf34e2cd9b175b80
7
- data.tar.gz: bbcf78001e99c6043dbcf41efc7c0df69612c6f449e75864a2da9de1d7fd7d1d459717c1b79c4917cd9812bfd6e68496f5fbb5bed54f13fb52b3a925b75e1a6c
6
+ metadata.gz: e94361974bb9a05aa7613270dbe940afeb45909274d279c505fa4612cb292854cea31b46c28d280348867cda5c9a620fb3fa4218dd833be84f8061d02ba4e254
7
+ data.tar.gz: b29aa12e363a0536f5a31bf8bc336ccaedc7e83d6e9f3a7c9ceb6d99f5f621245bd514150828c91fdbaea0039ffadec96ea40e353598e8c9fd668a44dba7ba70
@@ -44,7 +44,7 @@ module Pubid::Jis
44
44
  def transform_supplements(supplements_params, base_params)
45
45
  supplements = supplements_params.map do |supplement|
46
46
  Identifier.create(number: supplement[:number], year: supplement[:year],
47
- type: supplement[:type], base: Identifier.create(**base_params))
47
+ type: :amd, base: Identifier.create(**base_params))
48
48
  end
49
49
 
50
50
  return supplements.first if supplements.count == 1
@@ -52,6 +52,10 @@ module Pubid::Jis
52
52
  raise Errors::SupplementParsingError, "more than one or none supplements provided"
53
53
  end
54
54
 
55
+ def transform_explanation(params, base_params)
56
+ Identifier.create(type: :explanation, base: Identifier.create(**base_params), **params)
57
+ end
58
+
55
59
  # Use Identifier#create to resolve identifier's type class
56
60
  def transform(params)
57
61
  identifier_params = params.map do |k, v|
@@ -65,6 +69,13 @@ module Pubid::Jis
65
69
  )
66
70
  end
67
71
 
72
+ if identifier_params[:explanation]
73
+ return transform_explanation(
74
+ identifier_params[:explanation].is_a?(Hash) ? identifier_params[:explanation] : {},
75
+ identifier_params.dup.tap { |h| h.delete(:explanation) }
76
+ )
77
+ end
78
+
68
79
  Identifier.create(**identifier_params)
69
80
  end
70
81
 
@@ -0,0 +1,24 @@
1
+ require_relative "../renderer/amendment"
2
+
3
+ module Pubid::Jis
4
+ module Identifier
5
+ class Explanation < Base
6
+ attr_accessor :base
7
+
8
+ def_delegators 'Pubid::Jis::Identifier::Explanation', :type
9
+
10
+ def initialize(base: nil, number: nil, **opts)
11
+ super(**opts.merge(number: number))
12
+ @base = base
13
+ end
14
+
15
+ def self.type
16
+ { key: :explanation, title: "Explanation", short: "EXPL" }
17
+ end
18
+
19
+ def self.get_renderer_class
20
+ Renderer::Explanation
21
+ end
22
+ end
23
+ end
24
+ end
@@ -35,12 +35,16 @@ module Pubid::Jis
35
35
  end
36
36
 
37
37
  rule(:amendment) do
38
- (str("/") >> str("AMD").as(:type) >> space >> digits.as(:number) >> colon >> year).repeat(1).as(:supplements)
38
+ (str("/") >> (str("AMD") | str("AMENDMENT")).as(:type) >> space >> digits.as(:number) >> colon >> year).repeat(1).as(:supplements)
39
+ end
40
+
41
+ rule(:explanation) do
42
+ (str("/") >> (str("EXPLANATION") | str("EXPL")) >> (space >> digits.as(:number)).maybe).as(:explanation)
39
43
  end
40
44
 
41
45
  rule(:identifier) do
42
46
  str("JIS").maybe >> space? >> type.maybe >> space? >> series >> space? >> digits.as(:number) >> part >>
43
- (colon >> year).maybe >> language.maybe >> all_parts.maybe >> amendment.maybe
47
+ (colon >> year).maybe >> language.maybe >> all_parts.maybe >> amendment.maybe >> explanation.maybe
44
48
  end
45
49
 
46
50
  rule(:root) { identifier }
@@ -5,5 +5,9 @@ module Pubid::Jis::Renderer
5
5
  def render_identifier(params)
6
6
  "%{base}/AMD %{number}%{year}" % params
7
7
  end
8
+
9
+ def render_base(base, opts, _params)
10
+ base.to_s(**opts)
11
+ end
8
12
  end
9
13
  end
@@ -2,6 +2,10 @@ module Pubid::Jis::Renderer
2
2
  class Base < Pubid::Core::Renderer::Base
3
3
  TYPE = "".freeze
4
4
 
5
+ def render(**args)
6
+ render_base_identifier(**args) + @prerendered_params[:language].to_s
7
+ end
8
+
5
9
  def render_identifier(params)
6
10
  "%{publisher}%{series} %{number}%{part}%{year}%{all_parts}" % params
7
11
  end
@@ -23,5 +27,9 @@ module Pubid::Jis::Renderer
23
27
  def render_all_parts(all_parts, _opts, _params)
24
28
  "(規格群)" if all_parts
25
29
  end
30
+
31
+ def render_year(year, _opts, _params)
32
+ ":#{year}"
33
+ end
26
34
  end
27
35
  end
@@ -0,0 +1,13 @@
1
+ require_relative "base"
2
+
3
+ module Pubid::Jis::Renderer
4
+ class Explanation < Base
5
+ def render_identifier(params)
6
+ if params[:number].to_s.empty?
7
+ "%{base}/EXPL" % params
8
+ else
9
+ "%{base}/EXPL %{number}" % params
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Jis
3
- VERSION = "0.2.0".freeze
3
+ VERSION = "0.3.0".freeze
4
4
  end
5
5
  end
data/lib/pubid/jis.rb CHANGED
@@ -12,16 +12,21 @@ require_relative "jis/identifier/base"
12
12
  require_relative "jis/identifier/technical_report"
13
13
  require_relative "jis/identifier/technical_specification"
14
14
  require_relative "jis/identifier/amendment"
15
+ require_relative "jis/identifier/explanation"
15
16
  require_relative "jis/renderer/base"
16
17
  require_relative "jis/renderer/technical_report"
17
18
  require_relative "jis/renderer/technical_specification"
18
19
  require_relative "jis/renderer/amendment"
20
+ require_relative "jis/renderer/explanation"
19
21
  require_relative "jis/parser"
20
22
  require_relative "jis/identifier"
21
23
 
22
24
  config = Pubid::Core::Configuration.new
23
25
  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.types = [Pubid::Jis::Identifier::Base,
27
+ Pubid::Jis::Identifier::TechnicalReport,
28
+ Pubid::Jis::Identifier::TechnicalSpecification,
29
+ Pubid::Jis::Identifier::Amendment,
30
+ Pubid::Jis::Identifier::Explanation]
26
31
  config.type_names = {}.freeze
27
32
  Pubid::Jis::Identifier.set_config(config)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubid-jis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-06 00:00:00.000000000 Z
11
+ date: 2023-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -125,11 +125,13 @@ files:
125
125
  - lib/pubid/jis/identifier.rb
126
126
  - lib/pubid/jis/identifier/amendment.rb
127
127
  - lib/pubid/jis/identifier/base.rb
128
+ - lib/pubid/jis/identifier/explanation.rb
128
129
  - lib/pubid/jis/identifier/technical_report.rb
129
130
  - lib/pubid/jis/identifier/technical_specification.rb
130
131
  - lib/pubid/jis/parser.rb
131
132
  - lib/pubid/jis/renderer/amendment.rb
132
133
  - lib/pubid/jis/renderer/base.rb
134
+ - lib/pubid/jis/renderer/explanation.rb
133
135
  - lib/pubid/jis/renderer/technical_report.rb
134
136
  - lib/pubid/jis/renderer/technical_specification.rb
135
137
  - lib/pubid/jis/version.rb