pubid-iso 0.1.12 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e97d39eae4c4c0962361910084b0ba9ed9613a01761214d2f4a0750e0c71fe39
4
- data.tar.gz: 0b41fc99349db1c5c5672e690305561e01dac3503d7c226b049bada4fcf857b7
3
+ metadata.gz: d60d5581ae205f08b23f80682735696086c753587386ab0b7bfcf7ce306e6156
4
+ data.tar.gz: '08d626a7cbb67820faac3fb9503dce84f21d13fcd8387671d110878de84adc4a'
5
5
  SHA512:
6
- metadata.gz: 7859c8ac83fc94369f1fab9fc6d4c7529cc49d35a5a09c2fa34dda3b95b2d21d1cd5917e277e6c63bbf96ec174496494ca328f8fff0d995e59ae160423d0ba01
7
- data.tar.gz: 7a104ec181c49142996ef2133648a9145a2c0a0d01a05348abddf362285327d915e59d0b283913113b03bd343ee44f5f5de5265ba111ad21ed2da25bffee2ef8
6
+ metadata.gz: b690e1a4d95efe0ed794ce74c1fef9e320cbb394c473650af6e7fded623ec4f986cb1d4ca463bdeab988be14d82fd14c0f7ec48f51febd8cd98d0ae2cd17a5eb
7
+ data.tar.gz: 33ca94206cb4b8812956fd3d1c146c77a5a5d8e24cd55e002405e6acc28b54b5433f4caf23e59bab5320b4189a4fb78c469696218995538d36600a1124abe341
data/README.adoc CHANGED
@@ -12,8 +12,7 @@ identifiers.
12
12
  . generate language specific PubID
13
13
  . generate dated vs undated PubIDs
14
14
 
15
- === Usage
16
-
15
+ === Usage samples
17
16
 
18
17
  [source,ruby]
19
18
  ----
@@ -25,12 +24,96 @@ pubid.to_s
25
24
  => "ISO 1234"
26
25
  ----
27
26
 
28
- Available attributes:
27
+ ==== With coopublisher
28
+
29
+ [source,ruby]
30
+ ----
31
+ pubid = Pubid::Iso::Identifier.new(publisher: "ISO", copublisher: "IEC", number: 123)
32
+ pubid.to_s
33
+
34
+ => "ISO/IEC 1234"
35
+ ----
36
+
37
+ ==== With document type
38
+
39
+ [source,ruby]
40
+ ----
41
+ pubid = Pubid::Iso::Identifier.new(publisher: "ISO", type: "TR", number: 123)
42
+ pubid.to_s
43
+
44
+ => "ISO/TR 1234"
45
+ ----
46
+
47
+ ==== With stage
48
+
49
+ [source,ruby]
50
+ ----
51
+ pubid = Pubid::Iso::Identifier.new(publisher: "ISO", stage: :WD, number: 123)
52
+ pubid.to_s
53
+
54
+ => "ISO/WD 1234"
55
+ ----
56
+
57
+ ==== With part number
58
+
59
+ [source,ruby]
60
+ ----
61
+ pubid = Pubid::Iso::Identifier.new(publisher: "ISO", number: 123, part: 1)
62
+ pubid.to_s
63
+
64
+ => "ISO 1234-1"
65
+ ----
66
+
67
+ ==== Using format options
68
+ [source,ruby]
69
+ ----
70
+ > pubid = Pubid::Iso::Identifier.new(
71
+ number: "8601",
72
+ part: "1",
73
+ year: 2019,
74
+ edition: 1,
75
+ amendment: {number: "1", year: "2021", stage: "DIS"}
76
+ )
77
+ > pubid.to_s(:ref_num_short)
78
+ => "ISO 8601-1:2019/DAM 1:2021(E)"
79
+ > pubid.to_s(:ref_num_long)
80
+ => "ISO 8601-1:2019/DAmd 1:2021(en)"
81
+ > pubid.to_s(:ref_dated)
82
+ => "ISO 8601-1:2019/DAM 1:2021"
83
+ > pubid.to_s(:ref_dated_long)
84
+ => "ISO 8601-1:2019/DAmd 1:2021"
85
+ > pubid.to_s(:ref_undated)
86
+ => "ISO 8601-1:2019/DAM 1"
87
+ > pubid.to_s(:ref_undated_long)
88
+ => "ISO 8601-1:2019/DAmd 1"
89
+ ----
90
+
91
+ ==== Using language specific rendering
92
+ [source,ruby]
93
+ ----
94
+ > pubid = Pubid::Iso::Identifier.parse("ISO/FDIS 26000:2010(ru)")
95
+ > pubid.to_s(format: :ref_num_long, lang: :russian)
96
+ => "ИСО/ОПМС 26000:2010(ru)"
97
+ > pubid = Pubid::Iso::Identifier.parse("ISO/IEC Guide 71:2001(fr)")
98
+ > pubid.to_s(format: :ref_num_long, lang: :french)
99
+ => "Guide ISO/CEI 71:2001(fr)"
100
+ ----
101
+
102
+ ==== Rendering URN identifier
103
+ [source,ruby]
104
+ ----
105
+ > pubid = Pubid::Iso::Identifier.new(
106
+ number: "8601",
107
+ part: "1",
108
+ year: 2019,
109
+ edition: 1,
110
+ amendment: {number: "1", year: "2021", stage: "DIS"}
111
+ )
112
+ > pubid.urn
113
+ => "urn:iso:std:iso:8601:-1:ed-1:amd:2021:v1"
114
+ ----
29
115
 
30
- `number`, `publisher`, `copublisher`, `part`, `type`, `year`, `edition`, `language`, `amendments`,
31
- `corrigendums`, `stage`, `substage`, `iteration`, `supplements`, `amendment_stage`, `corrigendum_stage`,
32
- `joint_document`, `tctype`, `sctype`, `wgtype`, `tcnumber`, `scnumber`, `wgnumber`, `urn_stage`,
33
- `dir`, `dirtype`, `supplement`
116
+ See documentation (https://www.rubydoc.info/gems/pubid-iso/Pubid/Iso/Identifier#initialize-instance_method[Pubid::Iso::Identifier] and https://www.rubydoc.info/gems/pubid-core/Pubid/Core/Identifier#initialize-instance_method[Pubid::Core::Identifier]) for all available attributes and options.
34
117
 
35
118
  == Elements of the PubID
36
119
 
@@ -3,9 +3,11 @@ module Pubid::Iso
3
3
  class ParseError < StandardError; end
4
4
  class PublishedIterationError < StandardError; end
5
5
  class HarmonizedStageCodeInvalidError < StandardError; end
6
- class CodeInvalidError < StandardError; end
6
+ class StageInvalidError < StandardError; end
7
7
  class IsStageIterationError < StandardError; end
8
8
  class WrongFormat < StandardError; end
9
- class SupplementWithoutYearError < StandardError; end
9
+ # Error raised when supplement applied to base document without publication year or stage
10
+ class SupplementWithoutYearOrStageError < StandardError; end
11
+ class NoEditionError < StandardError; end
10
12
  end
11
13
  end
@@ -53,22 +53,36 @@ module Pubid::Iso
53
53
  }
54
54
 
55
55
  STAGES_NAMES = {
56
- approval: "50"
57
- }
56
+ preliminary: "00",
57
+ proposal: "10",
58
+ preparatory: "20",
59
+ committee: "30",
60
+ enquiry: "40",
61
+ approval: "50",
62
+ publication: "60",
63
+ review: "90",
64
+ withdrawal: "95",
65
+ }.freeze
58
66
 
59
67
  SUBSTAGES_NAMES = {
60
- registration: "00"
61
- }
68
+ registration: "00",
69
+ start_of_main_action: "20",
70
+ completion_of_main_action: "60",
71
+ repeat_an_earlier_phase: "92",
72
+ repeat_current_phase: "93",
73
+ abandon: "98",
74
+ proceed: "99",
75
+ }.freeze
62
76
 
63
- def initialize(stage, substage = nil)
77
+ def initialize(stage, substage = "00")
64
78
  # when stage is stage name
65
79
  if STAGES_NAMES.key?(stage)
66
80
  @stage = STAGES_NAMES[stage]
67
81
  @substage = SUBSTAGES_NAMES[substage]
68
82
  else
69
83
  # stage is number
70
- validate_stage(stage, substage)
71
84
  @stage, @substage = stage, substage
85
+ validate_stage(stage, substage)
72
86
  end
73
87
  end
74
88
 
@@ -77,8 +91,7 @@ module Pubid::Iso
77
91
  raise Errors::HarmonizedStageCodeInvalidError if Integer(stage).nil?
78
92
 
79
93
  # raise an error when substage wrong
80
- raise Errors::HarmonizedStageCodeInvalidError if stage == "90" && substage == "00"
81
- # raise Errors::HarmonizedStageCodeNotValidError if stage.to_i
94
+ raise Errors::HarmonizedStageCodeInvalidError unless DESCRIPTIONS.key?(to_s)
82
95
  end
83
96
 
84
97
  def to_s
@@ -10,7 +10,7 @@ module Pubid::Iso
10
10
  # Creates new identifier from options provided, includes options from
11
11
  # Pubid::Core::Identifier#initialize
12
12
  #
13
- # @param stage [Stage] stage
13
+ # @param stage [Stage, Symbol, String] stage, e.g. "PWI", "NP", "50.00", Stage.new(abbr: :WD)
14
14
  # @param urn_stage [Float] numeric stage for URN rendering
15
15
  # @param iteration [Integer] document iteration, eg. "1", "2", "3"
16
16
  # @param joint_document [Identifier] joint document
@@ -22,6 +22,10 @@ module Pubid::Iso
22
22
  # @param scnumber [Integer] Subsommittee number, eg. "1", "2"
23
23
  # @param wgnumber [Integer] Working group number, eg. "1", "2"
24
24
  # @param dirtype [String] Directives document type, eg. "JTC"
25
+ # @raise [Errors::SupplementWithoutYearOrStageError] when trying to apply
26
+ # supplement to the document without edition year or stage
27
+ # @raise [Errors::IsStageIterationError] when trying to apply iteration
28
+ # to document with IS stage
25
29
  # @see Supplement
26
30
  # @see Identifier
27
31
  # @see Pubid::Core::Identifier
@@ -32,18 +36,23 @@ module Pubid::Iso
32
36
  tctype: nil, sctype: nil, wgtype: nil, tcnumber: nil,
33
37
  scnumber: nil, wgnumber:nil,
34
38
  dir: nil, dirtype: nil, year: nil, amendments: nil,
35
- corrigendums: nil, **opts)
39
+ corrigendums: nil, type: nil, **opts)
36
40
  super(**opts.merge(number: number, publisher: publisher, year: year,
37
- amendments: amendments, corrigendums: corrigendums))
41
+ amendments: amendments, corrigendums: corrigendums, type: type))
38
42
 
39
- if (amendments || corrigendums) && year.nil?
40
- raise Errors::SupplementWithoutYearError, "Cannot apply supplement to document without edition year"
43
+ if (amendments || corrigendums) && (year.nil? && stage.nil?)
44
+ raise Errors::SupplementWithoutYearOrStageError, "Cannot apply supplement to document without edition year or stage"
41
45
  end
42
46
  if stage
43
- @stage = (stage.is_a?(Symbol) || stage.is_a?(String)) ? Stage.new(abbr: stage) : stage
47
+ @stage = stage.is_a?(Stage) ? stage : Stage.parse(stage)
48
+
44
49
  if @stage.abbr == "IS" && iteration
45
50
  raise Errors::IsStageIterationError, "IS stage document cannot have iteration"
46
51
  end
52
+
53
+ if @stage.abbr == "FDIS" && type == "PAS"
54
+ raise Errors::StageInvalidError, "PAS type cannot have FDIS stage"
55
+ end
47
56
  end
48
57
  @iteration = iteration.to_i if iteration
49
58
  @supplement = supplement if supplement
@@ -90,39 +99,61 @@ module Pubid::Iso
90
99
  end
91
100
  end
92
101
 
102
+ # Render URN identifier
103
+ # @return [String] URN identifier
93
104
  def urn
94
- (@tctype && Renderer::UrnTc || @type == "DIR" && Renderer::UrnDir || Pubid::Iso::Renderer::Urn).new(get_params).render
95
- end
96
-
97
- def formatted(format)
98
- case format
99
- when :ref_num_short
100
- to_s(with_language_code: :single, stage_format_long: false)
101
- when :ref_num_long
102
- to_s(with_language_code: :iso, stage_format_long: true)
103
- when :ref_dated
104
- to_s(with_language_code: :none, stage_format_long: false)
105
- when :ref_dated_long
106
- to_s(with_language_code: :none, stage_format_long: true)
107
- when :ref_undated
108
- to_s(with_language_code: :none, stage_format_long: false, with_date: false)
109
- when :ref_undated_long
110
- to_s(with_language_code: :none, stage_format_long: true, with_date: false)
111
- else
112
- raise Errors::WrongFormat, "#{format} is not available"
105
+ if (@amendments || @corrigendums) && !@edition
106
+ raise Errors::NoEditionError, "Base document must have edition"
113
107
  end
108
+ (@tctype && Renderer::UrnTc || @type == "DIR" && Renderer::UrnDir || Pubid::Iso::Renderer::Urn).new(get_params).render
114
109
  end
115
110
 
116
111
  # Renders pubid identifier
117
112
  #
118
113
  # @param lang [:french,:russian] use language specific renderer
119
114
  # @param with_date [Boolean] render identifier with date
120
- # @param with_language_code [:iso,:single] use iso format or single language code for rendering
121
115
  # @param with_edition [Boolean] render identifier with edition
122
116
  # @param stage_format_long [Boolean] render with long or short stage format
117
+ # @param format [:ref_num_short,:ref_num_long,:ref_dated,:ref_dated_long,:ref_undated,:ref_undated_long] create reference with specified format
118
+ # Format options are:
119
+ # :ref_num_short -- instance reference number: 1 letter language code + short form (DAM) + dated
120
+ # :ref_num_long -- instance reference number long: 2 letter language code + long form (DAmd) + dated
121
+ # :ref_dated -- reference dated: no language code + short form (DAM) + dated
122
+ # :ref_dated_long -- reference dated long: no language code + short form (DAM) + dated
123
+ # :ref_undated -- reference undated: no language code + short form (DAM) + undated
124
+ # :ref_undated_long -- reference undated long: 1 letter language code + long form (DAmd) + undated
123
125
  # @return [String] pubid identifier
124
- def to_s(lang: nil, with_date: true, with_language_code: :iso,
125
- with_edition: true, stage_format_long: true)
126
+ def to_s(lang: nil, with_date: true,
127
+ with_edition: false, with_prf: false,
128
+ format: :ref_dated_long)
129
+ with_language_code = nil
130
+ stage_format_long = nil
131
+ if format
132
+ case format
133
+ when :ref_num_short
134
+ with_language_code = :single
135
+ stage_format_long = false
136
+ when :ref_num_long
137
+ with_language_code = :iso
138
+ stage_format_long = true
139
+ when :ref_dated
140
+ with_language_code = :none
141
+ stage_format_long = false
142
+ when :ref_dated_long
143
+ with_language_code = :none
144
+ stage_format_long = true
145
+ when :ref_undated
146
+ with_language_code = :none
147
+ stage_format_long = false
148
+ with_date = false
149
+ when :ref_undated_long
150
+ with_language_code = :none
151
+ stage_format_long = true
152
+ with_date = false
153
+ else
154
+ raise Errors::WrongFormat, "#{format} is not available"
155
+ end
156
+ end
126
157
  case lang
127
158
  when :french
128
159
  Renderer::French.new(get_params)
@@ -137,7 +168,7 @@ module Pubid::Iso
137
168
  self.class.get_renderer_class.new(get_params)
138
169
  end
139
170
  end.render(with_date: with_date, with_language_code: with_language_code, with_edition: with_edition,
140
- stage_format_long: stage_format_long) +
171
+ stage_format_long: stage_format_long, with_prf: with_prf) +
141
172
  if @joint_document && @type != "DIR"
142
173
  "|#{@joint_document}"
143
174
  end.to_s
@@ -13,25 +13,34 @@ module Pubid::Iso::Renderer
13
13
  end
14
14
 
15
15
  def render_identifier(params)
16
- if @params[:type] && @params[:stage] && %w(DIS FDIS).include?(@params[:stage].abbr)
17
- render_base(params, " #{render_short_stage(@params[:stage].abbr)}#{@params[:type]}")
16
+ if @params[:type] && @params[:stage]
17
+ if %w(DIS FDIS).include?(@params[:stage].abbr)
18
+ render_base(params, "#{render_short_stage(@params[:stage].abbr)}#{@params[:type]}")
19
+ else
20
+ if params[:copublisher] && !params[:copublisher].empty?
21
+ render_base(params, "%{type}%{stage}" % params)
22
+ else
23
+ render_base(params, "%{stage}%{type}" % params)
24
+ end
25
+ end
18
26
  else
19
27
  render_base(params, "%{type}%{stage}" % params)
20
28
  end +
21
- "%{part}%{iteration}%{year}%{edition}%{amendments}%{corrigendums}%{language}" % params
29
+ "%{part}%{iteration}%{year}%{amendments}%{corrigendums}%{edition}%{language}" % params
22
30
  end
23
31
 
24
32
  def render_short_stage(stage)
25
- case stage
26
- when "DIS"
27
- "D"
28
- when "FDIS"
29
- "FD"
30
- end
33
+ (params[:copublisher] ? " " : "/") +
34
+ case stage
35
+ when "DIS"
36
+ "D"
37
+ when "FDIS"
38
+ "FD"
39
+ end
31
40
  end
32
41
 
33
42
  def render_type(type, opts, params)
34
- if params[:copublisher]
43
+ if params[:copublisher] || (params[:stage] && params[:stage].abbr != "IS")
35
44
  " #{type}"
36
45
  else
37
46
  "/#{type}"
@@ -39,6 +48,8 @@ module Pubid::Iso::Renderer
39
48
  end
40
49
 
41
50
  def render_stage(stage, opts, params)
51
+ return if (stage.abbr == "PRF" and !opts[:with_prf]) || stage.abbr == "IS"
52
+
42
53
  if params[:copublisher]
43
54
  " #{stage.abbr}"
44
55
  else
@@ -2,7 +2,7 @@ module Pubid::Iso::Renderer
2
2
  class Dir < Base
3
3
 
4
4
  def render_identifier(params)
5
- res = ("%{publisher}%{copublisher} DIR%{dirtype}%{number}%{year}%{supplement}" % params)
5
+ res = ("%{publisher}%{copublisher} DIR%{dirtype}%{number}%{year}%{supplement}%{language}" % params)
6
6
 
7
7
  if params.key?(:joint_document)
8
8
  joint_params = prerender_params(params[:joint_document].get_params, {})
@@ -4,30 +4,71 @@ module Pubid::Iso
4
4
 
5
5
  STAGES = { PWI: "00.00",
6
6
  NP: "10.00",
7
- AWI: "20.00",
8
- WD: "20.20",
7
+ AWI: %w[20.00 10.99],
8
+ WD: %w[20.20 20.60 20.98 20.99],
9
9
  CD: "30.00",
10
10
  DIS: "40.00",
11
11
  FDIS: "50.00",
12
- PRF: "50.00",
13
- IS: "60.00" }.freeze
12
+ PRF: "60.00",
13
+ IS: "60.60" }.freeze
14
+
14
15
 
15
16
  # @param abbr [String, Symbol] abbreviation eg. :PWI, :WD
16
- # @param harmonized_code [HarmonizedStageCode]
17
+ # @param harmonized_code [String, Float, HarmonizedStageCode]
17
18
  def initialize(abbr: nil, harmonized_code: nil)
18
- @abbr = abbr
19
- @harmonized_code = harmonized_code
19
+ @abbr = abbr&.to_s
20
20
 
21
21
  if harmonized_code
22
- # @abbr = STAGES.select { |k,v| v == @harmonized_code.to_s }.first&.first
23
- @abbr ||= STAGES.key(@harmonized_code.to_s)
22
+ @harmonized_code = if harmonized_code.is_a?(HarmonizedStageCode)
23
+ harmonized_code
24
+ else
25
+ HarmonizedStageCode.new(*harmonized_code.to_s.split("."))
26
+ end
27
+ @abbr ||= lookup_abbr(@harmonized_code.to_s) || lookup_abbr("#{@harmonized_code.stage}.00")
24
28
  end
25
29
 
26
30
  if abbr
27
- raise Errors::CodeInvalidError, "#{abbr} is not valid stage" unless STAGES.key?(abbr.to_sym)
31
+ raise Errors::StageInvalidError, "#{abbr} is not valid stage" unless STAGES.key?(abbr.to_sym)
32
+
33
+ @harmonized_code ||= HarmonizedStageCode.new(*lookup_code(abbr).split("."))
34
+ end
35
+ end
28
36
 
29
- @harmonized_code ||= HarmonizedStageCode.new(*STAGES[abbr.to_sym].split("."))
37
+ # Lookup for abbreviated code by numeric stage code
38
+ # @param lookup_code [String] stage code, e.g. "00.00", "20.20"
39
+ def lookup_abbr(lookup_code)
40
+ STAGES.each do |abbr, codes|
41
+ case codes
42
+ when Array
43
+ codes.each do |code|
44
+ return abbr if code == lookup_code
45
+ end
46
+ when lookup_code
47
+ return abbr
48
+ end
30
49
  end
50
+
51
+ nil
52
+ end
53
+
54
+ def lookup_code(lookup_abbr)
55
+ code = STAGES[lookup_abbr.to_sym]
56
+ code.is_a?(Array) ? code.first : code
57
+ end
58
+
59
+ def self.parse(stage)
60
+ if /\A[\d.]+\z/.match?(stage)
61
+ Stage.new(harmonized_code: stage)
62
+ else
63
+ raise Errors::StageInvalidError unless stage.is_a?(Symbol) || stage.is_a?(String)
64
+
65
+ Stage.new(abbr: stage)
66
+ end
67
+ end
68
+
69
+ # Compares one stage with another
70
+ def ==(other)
71
+ other&.harmonized_code == harmonized_code
31
72
  end
32
73
  end
33
74
  end
@@ -2,14 +2,14 @@ module Pubid::Iso
2
2
  class Supplement < Pubid::Core::Supplement
3
3
  attr_accessor :stage, :publisher, :edition, :iteration
4
4
 
5
- # @param stage [Stage] stage, e.g. "PWI", "NP"
5
+ # @param stage [Stage, Symbol, String] stage, e.g. "PWI", "NP", "50.00", Stage.new(abbr: :WD)
6
6
  # @param publisher [String] publisher, e.g. "ISO", "IEC"
7
7
  # @param edition [Integer] edition, e.g. 1, 2, 3
8
8
  # @param iteration [Integer] iteration, e.g. 1, 2, 3
9
9
  # @see Pubid::Core::Supplement for other options
10
10
  def initialize(stage: nil, publisher: nil, edition: nil, iteration: nil, **args)
11
11
  super(**args)
12
- @stage = (stage.is_a?(Symbol) || stage.is_a?(String)) ? Stage.new(abbr: stage) : stage
12
+ @stage = stage.is_a?(Stage) ? stage : Stage.parse(stage) if stage
13
13
  @publisher = publisher.to_s
14
14
  @edition = edition&.to_i
15
15
  @iteration = iteration&.to_i
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Iso
3
- VERSION = "0.1.12".freeze
3
+ VERSION = "0.2.1".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubid-iso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-19 00:00:00.000000000 Z
11
+ date: 2022-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake