pubid-jis 0.1.1 → 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: aaeab5258bdddf833c4ab9918d0973abfb23993ac3e6433b9fd73e4c9c6b2f6d
4
- data.tar.gz: ef707e6ec8b8d989b2376a46266388c4a9fdb1f577b25b991accf56dcc772877
3
+ metadata.gz: 07eef4940f4a38e169eebcd786cb2d4456814c9bb0ab6eafba78eaf619dee42b
4
+ data.tar.gz: 6e42254073b7bcb5d8a00fc5c1d8c74d0a0ac116340f8b25ba6a77bbbc8b4de8
5
5
  SHA512:
6
- metadata.gz: 450467f6397bad16e962d7b15628d1cb8b91d169cf5d6d76b551593b63a99df3a1910bfd415b97ac805964c6b31eb3ca76649f3c0c3d9caeb599fc1e55d4c1dc
7
- data.tar.gz: 1a1ba91e716740b9d1e9b135a9c72e3dca0f351ce0682d9fc92bf763e3438df6d706be880f15f6e5f2821c14032c273ebe45de0c36d89ce02a681aadca7797d7
6
+ metadata.gz: e94361974bb9a05aa7613270dbe940afeb45909274d279c505fa4612cb292854cea31b46c28d280348867cda5c9a620fb3fa4218dd833be84f8061d02ba4e254
7
+ data.tar.gz: b29aa12e363a0536f5a31bf8bc336ccaedc7e83d6e9f3a7c9ceb6d99f5f621245bd514150828c91fdbaea0039ffadec96ea40e353598e8c9fd668a44dba7ba70
@@ -25,18 +25,26 @@ module Pubid::Jis
25
25
 
26
26
  def ==(other)
27
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) }
28
+ return get_params.reject { |k, _| [:year, :part, :all_parts].include?(k) } ==
29
+ other.get_params.reject { |k, _| [:year, :part, :all_parts].include?(k) }
30
30
  end
31
31
 
32
32
  super
33
33
  end
34
34
 
35
+ # @param with_publisher [Boolean] add publisher to output
36
+ def to_s(with_publisher: true)
37
+ options = {}
38
+ options[:with_publisher] = with_publisher
39
+
40
+ self.class.get_renderer_class.new(get_params).render(**options)
41
+ end
42
+
35
43
  class << self
36
44
  def transform_supplements(supplements_params, base_params)
37
45
  supplements = supplements_params.map do |supplement|
38
46
  Identifier.create(number: supplement[:number], year: supplement[:year],
39
- type: supplement[:type], base: Identifier.create(**base_params))
47
+ type: :amd, base: Identifier.create(**base_params))
40
48
  end
41
49
 
42
50
  return supplements.first if supplements.count == 1
@@ -44,6 +52,10 @@ module Pubid::Jis
44
52
  raise Errors::SupplementParsingError, "more than one or none supplements provided"
45
53
  end
46
54
 
55
+ def transform_explanation(params, base_params)
56
+ Identifier.create(type: :explanation, base: Identifier.create(**base_params), **params)
57
+ end
58
+
47
59
  # Use Identifier#create to resolve identifier's type class
48
60
  def transform(params)
49
61
  identifier_params = params.map do |k, v|
@@ -57,6 +69,13 @@ module Pubid::Jis
57
69
  )
58
70
  end
59
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
+
60
79
  Identifier.create(**identifier_params)
61
80
  end
62
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,12 +2,20 @@ 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
8
12
 
9
- def render_series(series, _opts, _params)
10
- " #{series}"
13
+ def render_publisher(publisher, opts, params)
14
+ super if opts[:with_publisher]
15
+ end
16
+
17
+ def render_series(series, opts, _params)
18
+ opts[:with_publisher] ? " #{series}" : series
11
19
  end
12
20
 
13
21
  def render_part(part, opts, _params)
@@ -19,5 +27,9 @@ module Pubid::Jis::Renderer
19
27
  def render_all_parts(all_parts, _opts, _params)
20
28
  "(規格群)" if all_parts
21
29
  end
30
+
31
+ def render_year(year, _opts, _params)
32
+ ":#{year}"
33
+ end
22
34
  end
23
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.1.1".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.1.1
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-01 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