pubid-iso 0.1.10 → 0.1.11

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: eb49fb09056ae2a808d1fef9f8c1bd107285095fdf3496fad1a2bc9b929d3555
4
- data.tar.gz: dfe7c869035871233c2d318bc2eb3b9baa98208cc29ac7e59ac538402850a91a
3
+ metadata.gz: 5970af41e67f70e22e928d11ac1eabd71d42ca1855f5d3d6254dea8f98844aab
4
+ data.tar.gz: fface01211f338c08b5ab853be7a48573400e4ca8c290bca9f52e9f6d9361c89
5
5
  SHA512:
6
- metadata.gz: af2a0127f4cebfa368c26b6e55b651c70dce70d25af68d9d6af8e0e1f56487ec7a73dbadc0abb423d6bb4da26d013754ae7b65e38d897ab8cd79a4c0250fa3f4
7
- data.tar.gz: 0afe6817acab2cf6f32164669038e1ab96cbd34763921191f43d8e96606bac0355f000c825b01799ff70aeca8bb1f8539d4a7a5f5b057c4259dec23bc25f07b2
6
+ metadata.gz: 7b4431cc30c76062a19fc1531ad3e2b57ec2b31b0fc9604672ad9a6a3a5908fc756c256f5552d94b0165b36f5032df084250b68fe7c884435339e6628ec365ba
7
+ data.tar.gz: b0d2a810b02ceff7044fe35a88a81e3ef2c5feb0a39a8592655136d4b9f0bd6d3ab01e3fb325a743843e057cc816930bfeb09f6cb0d0b45c586b6a8f127bee9d
data/README.adoc CHANGED
@@ -12,6 +12,25 @@ identifiers.
12
12
  . generate language specific PubID
13
13
  . generate dated vs undated PubIDs
14
14
 
15
+ === Usage
16
+
17
+
18
+ [source,ruby]
19
+ ----
20
+ require "pubid-iso"
21
+
22
+ pubid = Pubid::Iso::Identifier.new(publisher: "ISO", number: 123)
23
+ pubid.to_s
24
+
25
+ => "ISO 1234"
26
+ ----
27
+
28
+ Available attributes:
29
+
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`
15
34
 
16
35
  == Elements of the PubID
17
36
 
@@ -1,9 +1,34 @@
1
1
  module Pubid::Iso
2
2
  class Amendment < Supplement
3
- def render_pubid
3
+ # @param stage_format_long [Boolean] long or short format for stage rendering
4
+ # @param with_date [Boolean] include date
5
+ def render_pubid(stage_format_long = true, with_date = true)
4
6
  stage = render_pubid_stage
5
- stage += " " unless stage.size == 0
6
- "/#{stage}Amd #{render_pubid_number}"
7
+ pubid_number = render_pubid_number(with_date: with_date)
8
+ case stage.to_s
9
+ when "DIS"
10
+ if stage_format_long
11
+ "/DAmd #{pubid_number}"
12
+ else
13
+ "/DAM #{pubid_number}"
14
+ end
15
+ when "FDIS"
16
+ if stage_format_long
17
+ "/FDAmd #{pubid_number}"
18
+ else
19
+ "/FDAM #{pubid_number}"
20
+ end
21
+ when "CD"
22
+ if stage_format_long
23
+ "/CD Amd #{pubid_number}"
24
+ else
25
+ "/CDAM #{pubid_number}"
26
+ end
27
+ when ""
28
+ "/Amd #{pubid_number}"
29
+ else
30
+ "/#{stage} Amd #{pubid_number}"
31
+ end
7
32
  end
8
33
 
9
34
  def render_urn
@@ -1,9 +1,26 @@
1
1
  module Pubid::Iso
2
2
  class Corrigendum < Supplement
3
- def render_pubid
3
+ def render_pubid(stage_format_long = true, with_date = true)
4
4
  stage = render_pubid_stage
5
- stage += " " unless stage.size == 0
6
- "/#{stage}Cor #{render_pubid_number}"
5
+ pubid_number = render_pubid_number(with_date: with_date)
6
+ case stage.to_s
7
+ when "DIS"
8
+ if stage_format_long
9
+ "/DCor #{pubid_number}"
10
+ else
11
+ "/DCOR #{pubid_number}"
12
+ end
13
+ when "FDIS"
14
+ if stage_format_long
15
+ "/FDCor #{pubid_number}"
16
+ else
17
+ "/FDCOR #{pubid_number}"
18
+ end
19
+ when ""
20
+ "/Cor #{pubid_number}"
21
+ else
22
+ "/#{stage} Cor #{pubid_number}"
23
+ end
7
24
  end
8
25
 
9
26
  def render_urn
@@ -1,5 +1,11 @@
1
1
  module Pubid::Iso
2
2
  module Errors
3
3
  class ParseError < StandardError; end
4
+ class PublishedIterationError < StandardError; end
5
+ class HarmonizedStageCodeInvalidError < StandardError; end
6
+ class CodeInvalidError < StandardError; end
7
+ class IsStageIterationError < StandardError; end
8
+ class WrongFormat < StandardError; end
9
+ class SupplementWithoutYearError < StandardError; end
4
10
  end
5
11
  end
@@ -0,0 +1,96 @@
1
+ module Pubid::Iso
2
+ class HarmonizedStageCode
3
+ include Comparable
4
+ attr_accessor :stage, :substage
5
+
6
+ DESCRIPTIONS = {
7
+ "00.00" => "Proposal for new project received",
8
+ "00.20" => "Proposal for new project under review",
9
+ "00.60" => "Close of review",
10
+ "00.98" => "Proposal for new project abandoned",
11
+ "00.99" => "Approval to ballot proposal for new project",
12
+ "10.00" => "Proposal for new project registered",
13
+ "10.20" => "New project ballot initiated",
14
+ "10.60" => "Close of voting",
15
+ "10.92" => "Proposal returned to submitter for further definition",
16
+ "10.98" => "New project rejected",
17
+ "10.99" => "New project approved",
18
+ "20.00" => "New project registered in TC/SC work programme",
19
+ "20.20" => "Working draft (WD) study initiated",
20
+ "20.60" => "Close of comment period",
21
+ "20.98" => "Project deleted",
22
+ "20.99" => "WD approved for registration as CD",
23
+ "30.00" => "Committee draft (CD) registered",
24
+ "30.20" => "CD study/ballot initiated",
25
+ "30.60" => "Close of voting/ comment period",
26
+ "30.92" => "CD referred back to Working Group",
27
+ "30.98" => "Project deleted",
28
+ "30.99" => "CD approved for registration as DIS",
29
+ "40.00" => "DIS registered",
30
+ "40.20" => "DIS ballot initiated: 12 weeks",
31
+ "40.60" => "Close of voting",
32
+ "40.92" => "Full report circulated: DIS referred back to TC or SC",
33
+ "40.93" => "Full report circulated: decision for new DIS ballot",
34
+ "40.98" => "Project deleted",
35
+ "40.99" => "Full report circulated: DIS approved for registration as FDIS",
36
+ "50.00" => "Final text received or FDIS registered for formal approval",
37
+ "50.20" => "Proof sent to secretariat or FDIS ballot initiated: 8 weeks",
38
+ "50.60" => "Close of voting. Proof returned by secretariat",
39
+ "50.92" => "FDIS or proof referred back to TC or SC",
40
+ "50.98" => "Project deleted",
41
+ "50.99" => "FDIS or proof approved for publication",
42
+ "60.00" => "International Standard under publication",
43
+ "60.60" => "International Standard published",
44
+ "90.20" => "International Standard under systematic review",
45
+ "90.60" => "Close of review",
46
+ "90.92" => "International Standard to be revised",
47
+ "90.93" => "International Standard confirmed",
48
+ "90.99" => "Withdrawal of International Standard proposed by TC or SC",
49
+ "95.20" => "Withdrawal ballot initiated",
50
+ "95.60" => "Close of voting",
51
+ "95.92" => "Decision not to withdraw International Standard",
52
+ "95.99" => "Withdrawal of International Standard"
53
+ }
54
+
55
+ STAGES_NAMES = {
56
+ approval: "50"
57
+ }
58
+
59
+ SUBSTAGES_NAMES = {
60
+ registration: "00"
61
+ }
62
+
63
+ def initialize(stage, substage = nil)
64
+ # when stage is stage name
65
+ if STAGES_NAMES.key?(stage)
66
+ @stage = STAGES_NAMES[stage]
67
+ @substage = SUBSTAGES_NAMES[substage]
68
+ else
69
+ # stage is number
70
+ validate_stage(stage, substage)
71
+ @stage, @substage = stage, substage
72
+ end
73
+ end
74
+
75
+ def validate_stage(stage, substage)
76
+ # raise an error if stage is not number
77
+ raise Errors::HarmonizedStageCodeInvalidError if Integer(stage).nil?
78
+
79
+ # raise an error when substage wrong
80
+ raise Errors::HarmonizedStageCodeInvalidError if stage == "90" && substage == "00"
81
+ # raise Errors::HarmonizedStageCodeNotValidError if stage.to_i
82
+ end
83
+
84
+ def to_s
85
+ "#{stage}.#{substage}"
86
+ end
87
+
88
+ def ==(other)
89
+ stage == other.stage && substage == other.substage
90
+ end
91
+
92
+ def description
93
+ DESCRIPTIONS[to_s]
94
+ end
95
+ end
96
+ end
@@ -1,18 +1,62 @@
1
1
  module Pubid::Iso
2
2
  class Identifier < Pubid::Core::Identifier
3
- attr_accessor :stage, :substage,
4
- :iteration, :supplements,
5
- :amendment_stage, :corrigendum_stage, :joint_document,
3
+ attr_accessor :stage,
4
+ :iteration, :joint_document,
6
5
  :tctype, :sctype, :wgtype, :tcnumber, :scnumber, :wgnumber,
7
- :urn_stage, :dir, :dirtype, :supplement
6
+ :urn_stage, :dirtype,
7
+ # supplement for DIR type identifiers
8
+ :supplement
8
9
 
9
- def initialize(**opts)
10
- super
11
- # if supplement
12
- # @supplement = Supplement.new(number: supplement[:year],
13
- # publisher: supplement[:publisher],
14
- # edition: supplement[:edition])
15
- # end
10
+ # Creates new identifier from options provided, includes options from
11
+ # Pubid::Core::Identifier#initialize
12
+ #
13
+ # @param stage [Stage] stage
14
+ # @param urn_stage [Float] numeric stage for URN rendering
15
+ # @param iteration [Integer] document iteration, eg. "1", "2", "3"
16
+ # @param joint_document [Identifier] joint document
17
+ # @param supplement [Supplement] supplement
18
+ # @param tctype [String] Technical Committee type, eg. "TC", "JTC"
19
+ # @param sctype [String] TC subsommittee, eg. "SC"
20
+ # @param wgtype [String] TC working group type, eg. "AG", "AHG"
21
+ # @param tcnumber [Integer] Technical Committee number, eg. "1", "2"
22
+ # @param scnumber [Integer] Subsommittee number, eg. "1", "2"
23
+ # @param wgnumber [Integer] Working group number, eg. "1", "2"
24
+ # @param dirtype [String] Directives document type, eg. "JTC"
25
+ # @see Supplement
26
+ # @see Identifier
27
+ # @see Pubid::Core::Identifier
28
+ # @see Parser
29
+ #
30
+ def initialize(publisher: "ISO", number: nil, stage: nil, iteration: nil, supplement: nil,
31
+ joint_document: nil, urn_stage: nil,
32
+ tctype: nil, sctype: nil, wgtype: nil, tcnumber: nil,
33
+ scnumber: nil, wgnumber:nil,
34
+ dir: nil, dirtype: nil, year: nil, amendments: nil,
35
+ corrigendums: nil, **opts)
36
+ super(**opts.merge(number: number, publisher: publisher, year: year,
37
+ amendments: amendments, corrigendums: corrigendums))
38
+
39
+ if (amendments || corrigendums) && year.nil?
40
+ raise Errors::SupplementWithoutYearError, "Cannot apply supplement to document without edition year"
41
+ end
42
+ if stage
43
+ if stage.abbr == "IS" && iteration
44
+ raise Errors::IsStageIterationError, "IS stage document cannot have iteration"
45
+ end
46
+ @stage = stage
47
+ end
48
+ @iteration = iteration.to_i if iteration
49
+ @supplement = supplement if supplement
50
+ @joint_document = joint_document if joint_document
51
+ @urn_stage = urn_stage if urn_stage
52
+ @tctype = tctype if tctype
53
+ @sctype = sctype.to_s if sctype
54
+ @wgtype = wgtype.to_s if wgtype
55
+ @tcnumber = tcnumber.to_s if tcnumber
56
+ @scnumber = scnumber.to_s if scnumber
57
+ @wgnumber = wgnumber.to_s if wgnumber
58
+ @dir = dir.to_s if dir
59
+ @dirtype = dirtype.to_s if dirtype
16
60
  end
17
61
 
18
62
  def self.parse_from_title(title)
@@ -40,14 +84,45 @@ module Pubid::Iso
40
84
  def get_transformer_class
41
85
  Transformer
42
86
  end
87
+
88
+ def get_renderer_class
89
+ Renderer::Base
90
+ end
43
91
  end
44
92
 
45
93
  def urn
46
- (@tctype && Renderer::UrnTc || @dir && Renderer::UrnDir || Pubid::Core::Renderer::Urn).new(get_params).render
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"
113
+ end
47
114
  end
48
115
 
49
- def to_s(lang: nil, with_date: true, with_language_code: :iso)
50
- # @pubid_language = lang
116
+ # Renders pubid identifier
117
+ #
118
+ # @param lang [:french,:russian] use language specific renderer
119
+ # @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
+ # @param with_edition [Boolean] render identifier with edition
122
+ # @param stage_format_long [Boolean] render with long or short stage format
123
+ # @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)
51
126
  case lang
52
127
  when :french
53
128
  Renderer::French.new(get_params)
@@ -56,13 +131,14 @@ module Pubid::Iso
56
131
  else
57
132
  if @tctype
58
133
  Renderer::Tc.new(get_params)
59
- elsif @dir
134
+ elsif @type == "DIR"
60
135
  Renderer::Dir.new(get_params)
61
136
  else
62
137
  self.class.get_renderer_class.new(get_params)
63
138
  end
64
- end.render(with_date: with_date, with_language_code: with_language_code) +
65
- if @joint_document && !@dir
139
+ end.render(with_date: with_date, with_language_code: with_language_code, with_edition: with_edition,
140
+ stage_format_long: stage_format_long) +
141
+ if @joint_document && @type != "DIR"
66
142
  "|#{@joint_document}"
67
143
  end.to_s
68
144
  end
@@ -1,36 +1,33 @@
1
1
  module Pubid::Iso
2
2
  class Parser < Pubid::Core::Parser
3
+ STAGES = %w[NP NWIP WD CD DIS FDIS PRF IS AWI PWI FPD pD PD FD D F].freeze
4
+ TYPES = %w[DATA ISP IWA R TTA TS TR PAS Guide GUIDE DIR].freeze
5
+
6
+ TCTYPES = ["TC", "JTC", "PC", "IT", "CAB", "CASCO", "COPOLCO",
7
+ "COUNCIL", "CPSG", "CS", "DEVCO", "GA", "GAAB", "INFCO",
8
+ "ISOlutions", "ITN", "REMCO", "TMB", "TMBG", "WMO",
9
+ "DMT", "JCG", "SGPM", "ATMG", "CCCC", "CCCC-TG", "JDMT",
10
+ "JSAG", "JSCTF-TF", "JTCG", "JTCG-TF", "SAG_Acc", "SAG_CRMI",
11
+ "SAG_CRMI_CG", "SAG_ESG", "SAG_ESG_CG", "SAG_MRS", "SAG SF", "SAG SF_CG",
12
+ "SMCC", "STMG", "MENA STAR"].freeze
13
+
14
+ WGTYPES = ["AG", "AHG", "AhG", "WG", "JWG", "QC", "TF",
15
+ "PPC", "CAG", "WG SGDG", "WG SR", "STAR", "STTF", "TIG",
16
+ "CPAG", "CSC", "ITSAG", "CSC/FIN", "CSC/NOM", "CSC/OVE",
17
+ "CSC/SP", "CSC/FIN", "JAG"].freeze
18
+
19
+ ORGANIZATIONS = %w[IEC IEEE CIW SAE CIE ASME ASTM OECD ISO IWA HL7 CEI].freeze
3
20
  rule(:stage) do
4
- Renderer::Russian::STAGE.values.reduce(
5
- # other stages
6
- str("NP") | str("NWIP") |
7
- str("WD") | str("CD") | str("DIS") | str("FDIS") | str("PRF") |
8
- str("IS") | str("AWI") | str("PWI") |
9
- # AMD and COR stages
10
- str("FPD") | str("pD") | str("PD") | str("FD") | str("D")) do |acc, stage|
11
- acc | str(stage)
12
- end
21
+ array_to_str(Renderer::Russian::STAGE.values) | array_to_str(STAGES)
13
22
  end
14
23
 
15
24
  rule(:type) do
16
- (
17
- Renderer::Russian::TYPE.values.reduce(
18
- str("DATA") | str("ISP") | str("IWA") | str("R") | str("TTA") |
19
- str("TS") | str("TR") | str("PAS") | str("Guide") | str("GUIDE")) do |acc, type|
20
- acc | str(type)
21
- end
22
- ).as(:type)
25
+ (array_to_str(Renderer::Russian::TYPE.values) | array_to_str(TYPES)).as(:type)
23
26
  end
24
27
 
25
28
  rule(:tctype) do
26
29
  # tc-types
27
- str("TC") | str("JTC") | str("PC") | str("IT") | str("CAB") | str("CASCO") | str("COPOLCO") |
28
- str("COUNCIL") | str("CPSG") | str("CS") | str("DEVCO") | str("GA") | str("GAAB") | str("INFCO") |
29
- str("ISOlutions") | str("ITN") | str("REMCO") | str("TMB") | str("TMBG") | str("WMO") |
30
- str("DMT") | str("JCG") | str("SGPM") | str("ATMG") | str("CCCC") | str("CCCC-TG") | str("JDMT") |
31
- str("JSAG") | str("JSCTF-TF") | str("JTCG") | str("JTCG-TF") | str("SAG_Acc") | str("SAG_CRMI") |
32
- str("SAG_CRMI_CG") | str("SAG_ESG") | str("SAG_ESG_CG") | str("SAG_MRS") | str("SAG SF") | str("SAG SF_CG") |
33
- str("SMCC") | str("STMG") | str("MENA STAR")
30
+ array_to_str(TCTYPES)
34
31
  end
35
32
 
36
33
  rule(:sctype) do
@@ -38,10 +35,7 @@ module Pubid::Iso
38
35
  end
39
36
 
40
37
  rule(:wgtype) do
41
- str("AG") | str("AHG") | str("AhG") | str("WG") | str("JWG") | str("QC") | str("TF") |
42
- str("PPC") | str("CAG") | str("WG SGDG") | str("WG SR") | str("STAR") | str("STTF") | str("TIG") |
43
- str("CPAG") | str("CSC") | str("ITSAG") | str("CSC/FIN") | str("CSC/NOM") | str("CSC/OVE") |
44
- str("CSC/SP") | str("CSC/FIN") | str("JAG")
38
+ array_to_str(WGTYPES)
45
39
  end
46
40
 
47
41
  rule(:part) do
@@ -50,12 +44,7 @@ module Pubid::Iso
50
44
  end
51
45
 
52
46
  rule(:organization) do
53
- Renderer::Russian::PUBLISHER.values.reduce(
54
- str("IEC") | str("IEEE") | str("CIW") | str("SAE") |
55
- str("CIE") | str("ASME") | str("ASTM") | str("OECD") | str("ISO") |
56
- str("IWA") | str("HL7") | str("CEI")) do |acc, publisher|
57
- acc | str(publisher)
58
- end
47
+ array_to_str(Renderer::Russian::PUBLISHER.values) | array_to_str(ORGANIZATIONS)
59
48
  end
60
49
 
61
50
  rule(:edition) do
@@ -72,8 +61,9 @@ module Pubid::Iso
72
61
  (str("/") | space).maybe >>
73
62
  (str("Amd") | str("AMD") | str("AM")) >>
74
63
  (space | str(".")).repeat(1).maybe >>
75
- digits.as(:version) >>
76
- ((str(":") | str("-")) >> digits.as(:number)).maybe).as(:amendments)
64
+ digits.as(:number) >>
65
+ (str(".") >> digits.as(:iteration)).maybe >>
66
+ ((str(":") | str("-")) >> digits.as(:year)).maybe).as(:amendments)
77
67
  end
78
68
 
79
69
  rule(:corrigendum) do
@@ -81,8 +71,9 @@ module Pubid::Iso
81
71
  (str("/") | space).maybe >>
82
72
  (str("Cor") | str("COR")) >>
83
73
  (space | str(".")).repeat(1).maybe >>
84
- digits.as(:version) >>
85
- ((str(":") | str("-")) >> digits.as(:number)).maybe).as(:corrigendums)
74
+ digits.as(:number) >>
75
+ (str(".") >> digits.as(:iteration)).maybe >>
76
+ ((str(":") | str("-")) >> digits.as(:year)).maybe).as(:corrigendums)
86
77
  end
87
78
 
88
79
  rule(:language) do
@@ -115,7 +106,7 @@ module Pubid::Iso
115
106
  end
116
107
 
117
108
  rule(:dir_document_body) do
118
- ((str("DIR") | str("Directives Part") | str("Directives, Part") | str("Directives,")).as(:dir) >> space).maybe >>
109
+ ((str("DIR") | str("Directives Part") | str("Directives, Part") | str("Directives,")).as(:type) >> space).maybe >>
119
110
  (str("JTC").as(:dirtype) >> space).maybe >>
120
111
  (digits.as(:number) >> (str(":") >> year).maybe).maybe >>
121
112
  (str(" -- Consolidated").maybe >> (space? >> (organization.as(:publisher) >> space).maybe >>
@@ -129,7 +120,7 @@ module Pubid::Iso
129
120
  space? >> ((stage.as(:stage) | type) >> space).maybe >>
130
121
  digits.as(:number) >>
131
122
  # for identifiers like ISO 5537/IDF 26
132
- (str("|") >> (str("IDF") >> space >> digits).as(:joint_document)).maybe >>
123
+ (str("|") >> (str("IDF").as(:publisher) >> space >> digits.as(:number)).as(:joint_document)).maybe >>
133
124
  part.maybe >> iteration.maybe >>
134
125
  (space? >> (str(":") | str("-")) >> year).maybe >>
135
126
  # stage before amendment
@@ -0,0 +1,75 @@
1
+ module Pubid::Iso::Renderer
2
+ class Base < Pubid::Core::Renderer::Base
3
+ # Render identifier
4
+ # @param with_edition [Boolean] include edition in output
5
+ # @see Pubid::Core::Renderer::Base for another options
6
+ def render(with_edition: true, **args)
7
+ params = prerender_params(@params,
8
+ { with_edition: with_edition }.merge(args))
9
+ # render empty string when the key is not exist
10
+ params.default = ""
11
+
12
+ render_identifier(params)
13
+ end
14
+
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]}")
18
+ else
19
+ render_base(params, "%{type}%{stage}" % params)
20
+ end +
21
+ "%{part}%{iteration}%{year}%{edition}%{amendments}%{corrigendums}%{language}" % params
22
+ end
23
+
24
+ def render_short_stage(stage)
25
+ case stage
26
+ when "DIS"
27
+ "D"
28
+ when "FDIS"
29
+ "FD"
30
+ end
31
+ end
32
+
33
+ def render_type(type, opts, params)
34
+ if params[:copublisher]
35
+ " #{type}"
36
+ else
37
+ "/#{type}"
38
+ end
39
+ end
40
+
41
+ def render_stage(stage, opts, params)
42
+ if params[:copublisher]
43
+ " #{stage.abbr}"
44
+ else
45
+ "/#{stage.abbr}"
46
+ end
47
+ end
48
+
49
+ def render_edition(edition, opts, _params)
50
+ " ED#{edition}" if opts[:with_edition]
51
+ end
52
+
53
+ def render_iteration(iteration, _opts, _params)
54
+ ".#{iteration}"
55
+ end
56
+
57
+ def render_amendments(amendments, opts, _params)
58
+ amendments.sort.map { |amendment| amendment.render_pubid(opts[:stage_format_long], opts[:with_date]) }.join("+")
59
+ end
60
+
61
+ def render_corrigendums(corrigendums, opts, _params)
62
+ corrigendums.sort.map { |corrigendum| corrigendum.render_pubid(opts[:stage_format_long], opts[:with_date]) }.join("+")
63
+ end
64
+
65
+ def render_language(language, opts, _params)
66
+ return if opts[:with_language_code] == :none
67
+ super
68
+ end
69
+
70
+ def render_year(year, opts, params)
71
+ return ":#{year}" if params[:amendments] || params[:corrigendums]
72
+ opts[:with_date] && ":#{year}" || ""
73
+ end
74
+ end
75
+ end
@@ -1,11 +1,11 @@
1
1
  module Pubid::Iso::Renderer
2
- class Dir < Pubid::Core::Renderer::Base
2
+ class Dir < Base
3
3
 
4
4
  def render_identifier(params)
5
5
  res = ("%{publisher}%{copublisher} DIR%{dirtype}%{number}%{year}%{supplement}" % params)
6
6
 
7
7
  if params.key?(:joint_document)
8
- joint_params = prerender_params(params[:joint_document], {})
8
+ joint_params = prerender_params(params[:joint_document].get_params, {})
9
9
  joint_params.default = ""
10
10
  res += (" + %{publisher}%{copublisher}%{dirtype}%{number}%{year}%{supplement}" % joint_params)
11
11
  end
@@ -26,7 +26,7 @@ module Pubid::Iso::Renderer
26
26
  " #{supplement.publisher} SUP"
27
27
  else
28
28
  " SUP"
29
- end + (supplement.number && ":#{supplement.number}" || "") +
29
+ end + (supplement.year && ":#{supplement.year}" || "") +
30
30
  (supplement.edition && " Edition #{supplement.edition}" || "")
31
31
  end
32
32
  end
@@ -1,5 +1,5 @@
1
1
  module Pubid::Iso::Renderer
2
- class French < Pubid::Core::Renderer::Base
2
+ class French < Base
3
3
  def render_identifier(params)
4
4
  if params[:type] == " Guide"
5
5
  params[:type] = ""
@@ -10,7 +10,7 @@ module Pubid::Iso::Renderer
10
10
  end
11
11
 
12
12
  def render_copublisher(copublisher, opts, params)
13
- "/#{copublisher.sub("IEC", "CEI")}"
13
+ "/#{copublisher.to_s.sub("IEC", "CEI")}"
14
14
  end
15
15
 
16
16
  def render_corrigendums(corrigendums, _opts, _params)
@@ -1,5 +1,5 @@
1
1
  module Pubid::Iso::Renderer
2
- class Russian < Pubid::Core::Renderer::Base
2
+ class Russian < Base
3
3
  PUBLISHER = { "ISO" => "ИСО", "IEC" => "МЭК" }.freeze
4
4
  STAGE = { "FDIS" => "ОПМС",
5
5
  "DIS" => "ПМС",
@@ -44,9 +44,9 @@ module Pubid::Iso::Renderer
44
44
 
45
45
  def render_stage(stage, _opts, params)
46
46
  if params[:copublisher]
47
- " #{STAGE[stage]}"
47
+ " #{STAGE[stage.abbr]}"
48
48
  else
49
- "/#{STAGE[stage]}"
49
+ "/#{STAGE[stage.abbr]}"
50
50
  end
51
51
  end
52
52
 
@@ -1,12 +1,12 @@
1
1
  module Pubid::Iso::Renderer
2
- class Tc < Pubid::Core::Renderer::Base
2
+ class Tc < Base
3
3
 
4
4
  def render_identifier(params)
5
5
  "%{publisher}%{copublisher} %{tctype} %{tcnumber}%{sctype}%{wgtype} N%{number}" % params
6
6
  end
7
7
 
8
8
  def render_tctype(tctype, _opts, _params)
9
- tctype.is_a?(Array) && tctype.join("/") || tctype
9
+ tctype.is_a?(Array) && tctype.join("/") || tctype.to_s
10
10
  end
11
11
 
12
12
  # TC 184/SC/WG 4 - no wg number
@@ -1,13 +1,11 @@
1
1
  module Pubid::Iso::Renderer
2
- class UrnDir < Pubid::Core::Renderer::Urn
2
+ class UrnDir < Urn
3
3
 
4
4
  def render_identifier(params)
5
5
  res = ("urn:iso:doc:%{publisher}%{copublisher}:dir%{dirtype}%{number}%{year}%{supplement}" % params)
6
6
 
7
7
  if params.key?(:joint_document)
8
- joint_params = prerender_params(
9
- params[:joint_document].transform_values { |value| value.is_a?(Parslet::Slice) && value.to_s || value }, {}
10
- )
8
+ joint_params = prerender_params(params[:joint_document].get_params, {})
11
9
  joint_params.default = ""
12
10
  res += (":%{publisher}%{copublisher}%{dirtype}%{number}%{supplement}" % joint_params)
13
11
  end
@@ -28,7 +26,7 @@ module Pubid::Iso::Renderer
28
26
  ":sup:#{supplement.publisher.downcase}"
29
27
  else
30
28
  ":sup"
31
- end + (supplement.number && ":#{supplement.number}" || "") +
29
+ end + (supplement.year && ":#{supplement.year}" || "") +
32
30
  (supplement.edition && ":ed-#{supplement.edition}" || "")
33
31
  end
34
32
  end
@@ -1,12 +1,12 @@
1
1
  module Pubid::Iso::Renderer
2
- class UrnTc < Pubid::Core::Renderer::Urn
2
+ class UrnTc < Urn
3
3
 
4
4
  def render_identifier(params)
5
5
  "urn:iso:doc:%{publisher}%{copublisher}:%{tctype}:%{tcnumber}%{sctype}%{wgtype}:%{number}" % params
6
6
  end
7
7
 
8
8
  def render_tctype(tctype, _opts, _params)
9
- (tctype.is_a?(Array) && tctype.join(":") || tctype).downcase
9
+ (tctype.is_a?(Array) && tctype.join(":") || tctype.to_s).downcase
10
10
  end
11
11
 
12
12
  def render_sctype(sctype, _opts, params)
@@ -0,0 +1,22 @@
1
+ module Pubid::Iso::Renderer
2
+ class Urn < Pubid::Core::Renderer::Urn
3
+ STAGES = { PWI: 0,
4
+ NP: 10,
5
+ AWI: 20,
6
+ WD: 20.20,
7
+ CD: 30,
8
+ DIS: 40,
9
+ FDIS: 50,
10
+ PRF: 50,
11
+ IS: 60 }.freeze
12
+
13
+ def render_identifier(params)
14
+ render_base(params) + "%{stage}"\
15
+ "%{corrigendum_stage}%{iteration}%{edition}%{amendments}%{corrigendums}%{language}" % params
16
+ end
17
+
18
+ def render_stage(stage, _opts, params)
19
+ ":stage-#{stage.harmonized_code}"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,33 @@
1
+ module Pubid::Iso
2
+ class Stage
3
+ attr_accessor :abbr, :harmonized_code
4
+
5
+ STAGES = { PWI: "00.00",
6
+ NP: "10.00",
7
+ AWI: "20.00",
8
+ WD: "20.20",
9
+ CD: "30.00",
10
+ DIS: "40.00",
11
+ FDIS: "50.00",
12
+ PRF: "50.00",
13
+ IS: "60.00" }.freeze
14
+
15
+ # @param abbr [String, Symbol] abbreviation eg. :PWI, :WD
16
+ # @param harmonized_code [HarmonizedStageCode]
17
+ def initialize(abbr: nil, harmonized_code: nil)
18
+ @abbr = abbr
19
+ @harmonized_code = harmonized_code
20
+
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)
24
+ end
25
+
26
+ if abbr
27
+ raise Errors::CodeInvalidError, "#{abbr} is not valid stage" unless STAGES.key?(abbr.to_sym)
28
+
29
+ @harmonized_code ||= HarmonizedStageCode.new(*STAGES[abbr.to_sym].split("."))
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,24 +1,54 @@
1
1
  module Pubid::Iso
2
2
  class Supplement < Pubid::Core::Supplement
3
- attr_accessor :stage, :publisher, :edition
3
+ attr_accessor :stage, :publisher, :edition, :iteration
4
4
 
5
- def initialize(stage: nil, version: nil, publisher: nil, edition: nil, **args)
6
- super(version: version, **args)
5
+ # @param stage [Stage] stage, e.g. "PWI", "NP"
6
+ # @param publisher [String] publisher, e.g. "ISO", "IEC"
7
+ # @param edition [Integer] edition, e.g. 1, 2, 3
8
+ # @param iteration [Integer] iteration, e.g. 1, 2, 3
9
+ # @see Pubid::Core::Supplement for other options
10
+ def initialize(stage: nil, publisher: nil, edition: nil, iteration: nil, **args)
11
+ super(**args)
7
12
  @stage = stage
8
13
  @publisher = publisher.to_s
9
- @edition = edition
14
+ @edition = edition&.to_i
15
+ @iteration = iteration&.to_i
16
+
17
+ if @iteration && @stage.nil?
18
+ raise Errors::PublishedIterationError.new("cannot assign iteration to published supplement")
19
+ end
10
20
  end
11
21
 
12
22
  def render_pubid_stage
13
- ((@stage && @stage) || "")
23
+ ((@stage && @stage.abbr != "IS" && @stage.abbr) || "")
14
24
  end
15
25
 
16
26
  def render_urn_stage
17
- ((@stage && ":stage-#{sprintf('%05.2f', Pubid::Core::Renderer::Urn::STAGES[@stage.to_sym])}") || "")
27
+ ((@stage && ":stage-#{@stage.harmonized_code}") || "")
18
28
  end
19
29
 
20
30
  def <=>(other)
21
31
  (super == 0) && ((stage.nil? || stage == other.stage) && 0 || -1) || super
22
32
  end
33
+
34
+ def render_iteration
35
+ @iteration && ".#{@iteration}"
36
+ end
37
+
38
+ def render_pubid_number(with_date: true)
39
+ if @year && with_date
40
+ "#{@number}#{render_iteration}:#{@year}"
41
+ else
42
+ "#{@number}#{render_iteration}"
43
+ end
44
+ end
45
+
46
+ def render_urn_number
47
+ if @year
48
+ ":#{@year}:v#{@number}#{render_iteration}"
49
+ else
50
+ ":#{@number}#{render_iteration}:v1"
51
+ end
52
+ end
23
53
  end
24
54
  end
@@ -9,16 +9,24 @@ module Pubid::Iso
9
9
  end
10
10
 
11
11
  rule(amendments: subtree(:amendments)) do |context|
12
- if context[:amendments].key?(:stage)
13
- context[:amendments][:stage] = convert_stage(context[:amendments][:stage])
14
- end
12
+ context[:amendments] =
13
+ [Amendment.new(
14
+ number: context[:amendments][:number],
15
+ year: context[:amendments][:year],
16
+ stage: context[:amendments][:stage] && convert_stage(context[:amendments][:stage]),
17
+ iteration: context[:amendments][:iteration])]
18
+
15
19
  context
16
20
  end
17
- #
21
+
18
22
  rule(corrigendums: subtree(:corrigendums)) do |context|
19
- if context[:corrigendums].key?(:stage)
20
- context[:corrigendums][:stage] = convert_stage(context[:corrigendums][:stage])
21
- end
23
+ context[:corrigendums] =
24
+ [Corrigendum.new(
25
+ number: context[:corrigendums][:number],
26
+ year: context[:corrigendums][:year],
27
+ stage: context[:corrigendums][:stage] && convert_stage(context[:corrigendums][:stage]),
28
+ iteration: context[:corrigendums][:iteration])]
29
+
22
30
  context
23
31
  end
24
32
 
@@ -43,6 +51,8 @@ module Pubid::Iso
43
51
  "TS"
44
52
  when "ТО"
45
53
  "TR"
54
+ when "Directives Part", "Directives, Part", "Directives,"
55
+ "DIR"
46
56
  else
47
57
  type
48
58
  end
@@ -72,7 +82,8 @@ module Pubid::Iso
72
82
  #
73
83
  rule(publisher: simple(:publisher), supplement: subtree(:supplement)) do |context|
74
84
  context[:supplement] =
75
- Supplement.new(number: context[:supplement][:year],
85
+ Supplement.new(number: context[:supplement][:number],
86
+ year: context[:supplement][:year],
76
87
  publisher: context[:supplement][:publisher],
77
88
  edition: context[:supplement][:edition])
78
89
  context
@@ -80,31 +91,38 @@ module Pubid::Iso
80
91
 
81
92
  rule(supplement: subtree(:supplement)) do |context|
82
93
  context[:supplement] =
83
- Supplement.new(number: context[:supplement][:year],
94
+ Supplement.new(number: context[:supplement][:number],
95
+ year: context[:supplement][:year],
84
96
  publisher: context[:supplement][:publisher],
85
97
  edition: context[:supplement][:edition])
86
98
  context
87
99
  end
88
100
 
101
+ rule(joint_document: subtree(:joint_document)) do |context|
102
+ context[:joint_document] =
103
+ Identifier.new(**context[:joint_document])
104
+ context
105
+ end
89
106
 
90
107
  def self.convert_stage(code)
91
108
  russian_code = Renderer::Russian::STAGE.key(code.to_s)
92
- return russian_code.to_s if russian_code
109
+ # return russian_code.to_s if russian_code
93
110
 
94
- case code
95
- when "NWIP"
96
- "NP"
97
- when "D"
98
- "DIS"
99
- when "FD"
100
- "FDIS"
101
- when "Fpr"
102
- "PRF"
103
- when "pD", "PD"
104
- "CD"
105
- else
106
- code
107
- end
111
+ code = case code
112
+ when "NWIP"
113
+ "NP"
114
+ when "D", "FPD"
115
+ "DIS"
116
+ when "FD", "F"
117
+ "FDIS"
118
+ when "Fpr"
119
+ "PRF"
120
+ when "pD", "PD"
121
+ "CD"
122
+ else
123
+ code
124
+ end
125
+ Stage.new(abbr: (russian_code || code))
108
126
  end
109
127
 
110
128
  def self.convert_language(code)
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Iso
3
- VERSION = "0.1.10".freeze
3
+ VERSION = "0.1.11".freeze
4
4
  end
5
5
  end
data/lib/pubid/iso.rb CHANGED
@@ -10,12 +10,16 @@ end
10
10
 
11
11
  require "pubid-core"
12
12
  require_relative "iso/errors"
13
+ require_relative "iso/stage"
14
+ require_relative "iso/harmonized_stage_code"
13
15
  require_relative "iso/parser"
14
16
  require_relative "iso/transformer"
15
17
  require_relative "iso/supplement"
16
18
  require_relative "iso/amendment"
17
19
  require_relative "iso/corrigendum"
18
20
  require_relative "iso/identifier"
21
+ require_relative "iso/renderer/base"
22
+ require_relative "iso/renderer/urn"
19
23
  require_relative "iso/renderer/french"
20
24
  require_relative "iso/renderer/russian"
21
25
  require_relative "iso/renderer/tc"
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.10
4
+ version: 0.1.11
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-08-05 00:00:00.000000000 Z
11
+ date: 2022-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.2'
103
+ version: 1.1.2
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0.2'
110
+ version: 1.1.2
111
111
  description: Library to generate, parse and manipulate ISO PubID.
112
112
  email:
113
113
  - open.source@ribose.com
@@ -124,14 +124,18 @@ files:
124
124
  - lib/pubid/iso/amendment.rb
125
125
  - lib/pubid/iso/corrigendum.rb
126
126
  - lib/pubid/iso/errors.rb
127
+ - lib/pubid/iso/harmonized_stage_code.rb
127
128
  - lib/pubid/iso/identifier.rb
128
129
  - lib/pubid/iso/parser.rb
130
+ - lib/pubid/iso/renderer/base.rb
129
131
  - lib/pubid/iso/renderer/dir.rb
130
132
  - lib/pubid/iso/renderer/french.rb
131
133
  - lib/pubid/iso/renderer/russian.rb
132
134
  - lib/pubid/iso/renderer/tc.rb
133
135
  - lib/pubid/iso/renderer/urn-dir.rb
134
136
  - lib/pubid/iso/renderer/urn-tc.rb
137
+ - lib/pubid/iso/renderer/urn.rb
138
+ - lib/pubid/iso/stage.rb
135
139
  - lib/pubid/iso/supplement.rb
136
140
  - lib/pubid/iso/transformer.rb
137
141
  - lib/pubid/iso/version.rb