diff --git a/lib/pubid/itu/identifier/base.rb b/lib/pubid/itu/identifier/base.rb index 74ac0a5..dfe31a9 100644 --- a/lib/pubid/itu/identifier/base.rb +++ b/lib/pubid/itu/identifier/base.rb @@ -3,7 +3,8 @@ module Pubid::Itu module Identifier class Base < Pubid::Core::Identifier::Base - attr_accessor :series, :sector, :date, :amendment, :subseries, :second_number, :annex + attr_accessor :series, :sector, :date, :amendment, :subseries, + :second_number, :annex, :range extend Forwardable @@ -15,7 +16,7 @@ def self.type # @param edition [String] document's edition version, e.g. "3.0", "1.0" def initialize(publisher: "ITU", series: nil, sector: nil, part: nil, date: nil, amendment: nil, subseries: nil, number: nil, - second_number: nil, annex: nil, **opts) + second_number: nil, annex: nil, range: nil, **opts) super(**opts.merge(publisher: publisher, number: number)) @series = series @@ -26,6 +27,7 @@ def initialize(publisher: "ITU", series: nil, sector: nil, part: nil, @subseries = subseries @second_number = second_number @annex = annex + @range = range end def to_s(**opts) diff --git a/lib/pubid/itu/parser.rb b/lib/pubid/itu/parser.rb index 22e455b..8f8ee43 100644 --- a/lib/pubid/itu/parser.rb +++ b/lib/pubid/itu/parser.rb @@ -34,11 +34,15 @@ class Parser < Pubid::Core::Parser str("OB") | str("Operational Bulletin") | # Recommendation series array_to_str(Identifier.config.series["T"].keys.sort_by(&:length).reverse) - ).as(:series) >> + ).capture(:series).as(:series) >> # "No. " for Operational Bulletin (dot | str(" No. ")).maybe end + rule(:series_range) do + (dash >> dynamic { |s, c| str(c.captures[:series]) } >> dot >> full_number).as(:range) + end + rule(:sector_series_number) do ( # ITU-R @@ -47,7 +51,8 @@ class Parser < Pubid::Core::Parser # ITU-T (str("T").as(:sector) >> type.maybe >> (space | dash) >> t_sector_series.maybe >> full_number >> - (str("/") >> t_sector_series.maybe >> full_number).as(:second_number).maybe) | + (str("/") >> t_sector_series.maybe >> full_number).as(:second_number).maybe >> + series_range.maybe) | # ITU-D (str("D") >> space >> full_number) ) diff --git a/lib/pubid/itu/renderer/base.rb b/lib/pubid/itu/renderer/base.rb index 397f5f1..efaa601 100644 --- a/lib/pubid/itu/renderer/base.rb +++ b/lib/pubid/itu/renderer/base.rb @@ -12,7 +12,7 @@ def render_type_series(params) def render_identifier(params) "%{publisher}-%{sector} #{render_type_series(params)}%{number}%{subseries}"\ - "%{part}%{second_number}%{annex}%{amendment}%{corrigendum}%{supplement}%{date}" % params + "%{part}%{second_number}%{range}%{annex}%{amendment}%{corrigendum}%{supplement}%{date}" % params end def render_number(number, _opts, params) @@ -72,5 +72,9 @@ def render_annex(annex, _opts, _params) def render_corrigendum(corrigendum, opts, params) "#{render_date(corrigendum[:date], opts, params)} Cor. #{corrigendum[:number]}" end + + def render_range(range, _opts, params) + "-#{params[:series]}.#{range[:number]}" + end end end diff --git a/spec/pubid_itu/identifier_spec.rb b/spec/pubid_itu/identifier_spec.rb index ad2af8d..bc1a13e 100644 --- a/spec/pubid_itu/identifier_spec.rb +++ b/spec/pubid_itu/identifier_spec.rb @@ -272,6 +272,12 @@ module Pubid::Itu it { expect(subject.base).to be_a(Identifier::Annex) } end + context "ITU-T Q.400-Q.490" do + let(:pubid) { "ITU-T Q.400-Q.490" } + + it_behaves_like "converts pubid to pubid" + end + describe "parse identifiers from examples files" do context "parses IEC identifiers from itu-r.txt" do let(:examples_file) { "itu-r.txt" }