Class: Pubid::Itu::Builder
- Inherits:
-
Object
- Object
- Pubid::Itu::Builder
- Defined in:
- lib/pubid/itu/builder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build(data) ⇒ Object
-
#build_annex(inner_data) ⇒ Object
Build “Annex to …” identifier.
-
#build_special_publication(data) ⇒ Object
Build Special Publication (OB).
- #build_supplement(data) ⇒ Object
Class Method Details
.build(parsed_data) ⇒ Object
6 7 8 |
# File 'lib/pubid/itu/builder.rb', line 6 def self.build(parsed_data) new.build(parsed_data) end |
Instance Method Details
#build(data) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pubid/itu/builder.rb', line 10 def build(data) # "Annex to ..." identifier — wraps a Special Publication base if data[:annex_to] return build_annex(data[:annex_to]) end # Operational Bulletin (Special Publication) — series == "OB" or # legacy long form ("Operational Bulletin No. ..."). if data[:series].to_s == "OB" || data[:_op_bull] return build_special_publication(data) end # Check if this is a supplement identifier if data[:supplement_type] return build_supplement(data) end # Build basic recommendation or combined identifier sector = Components::Sector.new(sector: data[:sector].to_s) series = Components::Series.new(series: data[:series].to_s) if data[:series] code = build_code(data) if data[:number] date = build_date(data) if data[:year] # Check if this is a combined identifier (has combined_series and combined_number) if data[:combined_series] || data[:combined_number] if data[:combined_series] combined_series = Components::Series.new( series: data[:combined_series][:series].to_s, ) end if data[:combined_number] combined_code = Components::Code.new( number: data[:combined_number].to_s, subseries: data[:combined_subseries]&.to_s, parts: extract_parts(data[:combined_parts]), ) end return Identifiers::CombinedIdentifier.new( sector: sector, series: series, code: code, combined_series: combined_series, combined_code: combined_code, date: date, language: data[:language]&.to_s, ) end Identifiers::Recommendation.new( sector: sector, series: series, code: code, date: date, language: data[:language]&.to_s, ) end |
#build_annex(inner_data) ⇒ Object
Build “Annex to …” identifier. The inner data is the Special Publication; the annex inherits its language.
83 84 85 86 87 88 89 |
# File 'lib/pubid/itu/builder.rb', line 83 def build_annex(inner_data) base = build_special_publication(inner_data) Identifiers::Annex.new( base: base, language: inner_data[:language]&.to_s, ) end |
#build_special_publication(data) ⇒ Object
Build Special Publication (OB). Sector is silently dropped — OB is a cross-bureau publication and ‘Identifiers::Base` rejects sector+OB in its constructor.
72 73 74 75 76 77 78 79 |
# File 'lib/pubid/itu/builder.rb', line 72 def build_special_publication(data) Identifiers::SpecialPublication.new( series: Components::Series.new(series: "OB"), code: data[:number] ? build_code(data) : nil, date: data[:year] ? build_date(data) : nil, language: data[:language]&.to_s, ) end |
#build_supplement(data) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/pubid/itu/builder.rb', line 91 def build_supplement(data) # Build the base identifier first base = build(data[:base]) if data[:base] # Determine supplement type supplement_type = data[:supplement_type].to_s.gsub(".", "") klass = case supplement_type when "Amd" Identifiers::Amendment when "Cor" Identifiers::Corrigendum when "Suppl" Identifiers::Supplement end # Build supplement date (separate from base date) supplement_date = if data[:supplement_year] Pubid::Components::Date.new( year: data[:supplement_year].to_s, month: data[:supplement_month]&.to_s, ) end # Build supplement with extracted components klass.new( sector: base&.sector || Components::Sector.new(sector: data[:sector].to_s), series: base&.series || (data[:series] ? Components::Series.new(series: data[:series].to_s) : nil), code: base&.code, base: base, number: data[:supplement_number].to_s, date: supplement_date, language: data[:language]&.to_s, ) end |