Skip to content

Commit

Permalink
Merge pull request #45 from metanorma/contribution-identifiers
Browse files Browse the repository at this point in the history
Add contribution identifiers creation
  • Loading branch information
opoudjis authored Sep 11, 2024
2 parents 963e18c + 8df2ff1 commit 200a2a4
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 14 deletions.
5 changes: 4 additions & 1 deletion lib/pubid/itu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ module Itu
require_relative "itu/identifier/corrigendum"
require_relative "itu/identifier/addendum"
require_relative "itu/identifier/appendix"
require_relative "itu/identifier/contribution"
require_relative "itu/transformer"
require_relative "itu/renderer/base"
require_relative "itu/renderer/implementers_guide"
require_relative "itu/renderer/contribution"
require_relative "itu/parser"
require_relative "itu/identifier"
require_relative "itu/configuration"
Expand All @@ -53,7 +55,8 @@ module Itu
Pubid::Itu::Identifier::Supplement,
Pubid::Itu::Identifier::Annex,
Pubid::Itu::Identifier::Addendum,
Pubid::Itu::Identifier::Appendix]
Pubid::Itu::Identifier::Appendix,
Pubid::Itu::Identifier::Contribution]
config.type_names = {}.freeze
config.series = YAML.load_file(File.join(File.dirname(__FILE__), "../../series.yaml"))
Pubid::Itu::Identifier.set_config(config)
2 changes: 1 addition & 1 deletion lib/pubid/itu/identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def parse(*args)
end

def resolve_identifier(parameters = {})
return Question.new(**parameters) if parameters[:series].to_s.match?(/^SG/)
return Question.new(**parameters) if parameters[:series].to_s.match?(/^SG/) && !parameters[:type]

return Resolution.new(**parameters) if parameters[:series].to_s == "R"

Expand Down
15 changes: 15 additions & 0 deletions lib/pubid/itu/identifier/contribution.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Pubid::Itu
module Identifier
class Contribution < Base
def_delegators 'Pubid::Itu::Identifier::Contribution', :type

def self.type
{ key: :contribution, title: "Contribution" }
end

def self.get_renderer_class
Renderer::Contribution
end
end
end
end
11 changes: 11 additions & 0 deletions lib/pubid/itu/renderer/contribution.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Pubid::Itu::Renderer
class Contribution < Base
def render_identifier(params)
("%{series}-C%{number}" % params)
end

def render_number(number, _opts, params)
number
end
end
end
49 changes: 37 additions & 12 deletions spec/pubid_itu/create_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module Pubid::Itu
RSpec.describe Identifier do
describe "creating new identifier" do
subject { described_class.create(**{ number: number, sector: sector, series: series }.merge(params)) }
subject do
described_class.create(**{ number: number, sector: sector,
series: series }.merge(params))
end
let(:number) { 123 }
let(:sector) { "R" }
let(:series) { "V" }
Expand Down Expand Up @@ -29,7 +32,10 @@ module Pubid::Itu

context "dual-numbered identifier" do
let(:sector) { "T" }
let(:params) { { series: "G", number: 780, second_number: { series: "Y", number: 1351 } } }
let(:params) do
{ series: "G", number: 780,
second_number: { series: "Y", number: 1351 } }
end

it "renders dual-numbered identifier" do
expect(subject.to_s).to eq("ITU-T G.780/Y.1351")
Expand All @@ -39,7 +45,10 @@ module Pubid::Itu
context "supplement" do
context "series supplement" do
let(:sector) { "T" }
let(:params) { { number: 1, type: :supplement, base: Identifier.create(sector: "T", series: "H") } }
let(:params) do
{ number: 1, type: :supplement,
base: Identifier.create(sector: "T", series: "H") }
end

it "renders series supplement" do
expect(subject.to_s).to eq("ITU-T H Suppl. 1")
Expand All @@ -48,7 +57,10 @@ module Pubid::Itu

context "document's supplement" do
let(:sector) { "T" }
let(:params) { { number: 1, type: :supplement, base: Identifier.create(sector: "T", series: "H", number: 1) } }
let(:params) do
{ number: 1, type: :supplement,
base: Identifier.create(sector: "T", series: "H", number: 1) }
end

it "renders series supplement" do
expect(subject.to_s).to eq("ITU-T H.1 Suppl. 1")
Expand All @@ -64,25 +76,38 @@ module Pubid::Itu
end
end

context "Contributions" do
let(:series) { "SG07" }
let(:number) { 1000 }
let(:params) { { type: :contribution } }

it "renders contribution identifier" do
expect(subject.to_s).to eq("SG07-C1000")
end
end

context "Special Publication" do
let(:sector) { "T" }
let(:series) { "OB" }
let(:params) { { date: { month: 01, year: 2024 } } }
let(:params) { { date: { month: 0o1, year: 2024 } } }
# let(:params) { { number: 1, type: :supplement, base: Identifier.create(sector: "T", series: "H", number: 1) } }

# Annex to ITU-T OB.1283 (01/2024)
it "renders identifier" do
expect(subject.to_s).to eq("ITU-T OB.#{number} (01/2024)")
end
end

context "Annex to Special Publication" do
let(:series) { nil }
let(:number) { nil }
let(:params) { { type: :annex, base: Identifier.create(sector: "T", series: "OB", number: 1) } }
context "Annex to Special Publication" do
let(:series) { nil }
let(:number) { nil }
let(:params) do
{ type: :annex,
base: Identifier.create(sector: "T", series: "OB", number: 1) }
end

it "renders annex to identifier" do
expect(subject.to_s).to eq("Annex to ITU-T OB.1")
end
it "renders annex to identifier" do
expect(subject.to_s).to eq("Annex to ITU-T OB.1")
end
end
end
Expand Down

0 comments on commit 200a2a4

Please sign in to comment.