Class: Pubid::Iso::Identifier::Base
- Inherits:
-
Core::Identifier::Base
- Object
- Core::Identifier::Base
- Pubid::Iso::Identifier::Base
- Extended by:
- Forwardable
- Defined in:
- lib/pubid/iso/identifier/base.rb
Direct Known Subclasses
Data, Directives, Extract, Guide, InternationalStandard, InternationalStandardizedProfile, InternationalWorkshopAgreement, PubliclyAvailableSpecification, Recommendation, Supplement, TechnicalCommittee, TechnicalReport, TechnicalSpecification, TechnologyTrendsAssessments
Instance Attribute Summary collapse
-
#addendum ⇒ Object
Returns the value of attribute addendum.
-
#base ⇒ Object
Returns the value of attribute base.
-
#dirtype ⇒ Object
Returns the value of attribute dirtype.
-
#iteration ⇒ Object
Returns the value of attribute iteration.
-
#joint_document ⇒ Object
Returns the value of attribute joint_document.
-
#jtc_dir ⇒ Object
Returns the value of attribute jtc_dir.
-
#month ⇒ Object
Returns the value of attribute month.
-
#scnumber ⇒ Object
Returns the value of attribute scnumber.
-
#sctype ⇒ Object
Returns the value of attribute sctype.
-
#stage ⇒ Object
Returns the value of attribute stage.
-
#supplements ⇒ Object
Returns the value of attribute supplements.
-
#tcnumber ⇒ Object
Returns the value of attribute tcnumber.
-
#tctype ⇒ Object
Returns the value of attribute tctype.
-
#wgnumber ⇒ Object
Returns the value of attribute wgnumber.
-
#wgtype ⇒ Object
Returns the value of attribute wgtype.
Class Method Summary collapse
- .create_supplements(params, base_params) ⇒ Object
- .get_amendment_class ⇒ Object
- .get_corrigendum_class ⇒ Object
- .get_identifier ⇒ Object
- .get_parser_class ⇒ Object
- .get_renderer_class ⇒ Object
- .get_transformer_class ⇒ Object
- .get_update_codes ⇒ Object
- .supplement_by_type(supplements, type) ⇒ Object
- .supplements_has_type?(supplements, type) ⇒ Boolean
-
.transform(params) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength.
-
.transform_supplements(supplements_params, base_params) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity.
- .type_match?(parameters) ⇒ Boolean
Instance Method Summary collapse
-
#initialize(publisher: "ISO", number: nil, stage: nil, iteration: nil, joint_document: nil, tctype: nil, sctype: nil, wgtype: nil, tcnumber: nil, scnumber: nil, wgnumber: nil, dir: nil, dirtype: nil, year: nil, amendments: nil, corrigendums: nil, type: nil, base: nil, supplements: nil, part: nil, addendum: nil, edition: nil, jtc_dir: nil, month: nil, **opts) ⇒ Base
constructor
Creates new identifier from options provided, includes options from Pubid::Core::Identifier#initialize.
- #render_all_parts ⇒ Object
- #render_joint_document(joint_document) ⇒ Object
-
#resolve_format(format = :ref_dated_long) ⇒ Object
Format options are: :ref_num_short – instance reference number: 1 letter language code + short form (DAM) + dated :ref_num_long – instance reference number long: 2 letter language code + long form (DAmd) + dated :ref_dated – reference dated: no language code + short form (DAM) + dated :ref_dated_long – reference dated long: no language code + short form (DAM) + dated :ref_undated – reference undated: no language code + short form (DAM) + undated :ref_undated_long – reference undated long: 1 letter language code + long form (DAmd) + undated.
-
#root ⇒ Object
Return typed stage abbreviation, eg.
-
#to_s(lang: nil, with_edition: false, with_prf: false, format: :ref_dated_long, annotated: false) ⇒ String
Renders pubid identifier.
-
#urn ⇒ String
Render URN identifier.
Constructor Details
#initialize(publisher: "ISO", number: nil, stage: nil, iteration: nil, joint_document: nil, tctype: nil, sctype: nil, wgtype: nil, tcnumber: nil, scnumber: nil, wgnumber: nil, dir: nil, dirtype: nil, year: nil, amendments: nil, corrigendums: nil, type: nil, base: nil, supplements: nil, part: nil, addendum: nil, edition: nil, jtc_dir: nil, month: nil, **opts) ⇒ Base
Creates new identifier from options provided, includes options from Pubid::Core::Identifier#initialize
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/pubid/iso/identifier/base.rb', line 47 def initialize(publisher: "ISO", number: nil, stage: nil, iteration: nil, joint_document: nil, tctype: nil, sctype: nil, wgtype: nil, tcnumber: nil, scnumber: nil, wgnumber:nil, dir: nil, dirtype: nil, year: nil, amendments: nil, corrigendums: nil, type: nil, base: nil, supplements: nil, part: nil, addendum: nil, edition: nil, jtc_dir: nil, month: nil, **opts) super(**opts.merge(number: number, publisher: publisher, year: year, amendments: amendments, corrigendums: corrigendums)) if supplements @supplements = supplements.map do |supplement| if supplement.is_a?(Hash) self.class.get_transformer_class.new.apply(:supplements => [supplement])[:supplements].first else supplement end end end if stage @stage = resolve_stage(stage) elsif iteration && !is_a?(Supplement) raise Errors::IterationWithoutStageError, "Document without stage cannot have iteration" end @iteration = iteration.to_i if iteration if joint_document if joint_document.is_a?(Hash) @joint_document = Identifier.create(**joint_document) else @joint_document = joint_document end end if tctype @tctype = tctype.is_a?(Array) ? tctype.map(&:to_s) : tctype.to_s end @sctype = sctype.to_s if sctype @wgtype = wgtype.to_s if wgtype @tcnumber = tcnumber.to_s if tcnumber @scnumber = scnumber.to_s if scnumber @wgnumber = wgnumber.to_s if wgnumber @dir = dir.to_s if dir @dirtype = dirtype.to_s if dirtype if jtc_dir @jtc_dir = jtc_dir.to_s end if base if base.is_a?(Hash) @base = Identifier.create(**base) else @base = base end end @part = part.to_s if part @addendum = addendum if addendum @edition = edition @month = month.to_s if month end |
Instance Attribute Details
#addendum ⇒ Object
Returns the value of attribute addendum.
10 11 12 |
# File 'lib/pubid/iso/identifier/base.rb', line 10 def addendum @addendum end |
#base ⇒ Object
Returns the value of attribute base.
10 11 12 |
# File 'lib/pubid/iso/identifier/base.rb', line 10 def base @base end |
#dirtype ⇒ Object
Returns the value of attribute dirtype.
10 11 12 |
# File 'lib/pubid/iso/identifier/base.rb', line 10 def dirtype @dirtype end |
#iteration ⇒ Object
Returns the value of attribute iteration.
10 11 12 |
# File 'lib/pubid/iso/identifier/base.rb', line 10 def iteration @iteration end |
#joint_document ⇒ Object
Returns the value of attribute joint_document.
10 11 12 |
# File 'lib/pubid/iso/identifier/base.rb', line 10 def joint_document @joint_document end |
#jtc_dir ⇒ Object
Returns the value of attribute jtc_dir.
10 11 12 |
# File 'lib/pubid/iso/identifier/base.rb', line 10 def jtc_dir @jtc_dir end |
#month ⇒ Object
Returns the value of attribute month.
10 11 12 |
# File 'lib/pubid/iso/identifier/base.rb', line 10 def month @month end |
#scnumber ⇒ Object
Returns the value of attribute scnumber.
10 11 12 |
# File 'lib/pubid/iso/identifier/base.rb', line 10 def scnumber @scnumber end |
#sctype ⇒ Object
Returns the value of attribute sctype.
10 11 12 |
# File 'lib/pubid/iso/identifier/base.rb', line 10 def sctype @sctype end |
#stage ⇒ Object
Returns the value of attribute stage.
10 11 12 |
# File 'lib/pubid/iso/identifier/base.rb', line 10 def stage @stage end |
#supplements ⇒ Object
Returns the value of attribute supplements.
10 11 12 |
# File 'lib/pubid/iso/identifier/base.rb', line 10 def supplements @supplements end |
#tcnumber ⇒ Object
Returns the value of attribute tcnumber.
10 11 12 |
# File 'lib/pubid/iso/identifier/base.rb', line 10 def tcnumber @tcnumber end |
#tctype ⇒ Object
Returns the value of attribute tctype.
10 11 12 |
# File 'lib/pubid/iso/identifier/base.rb', line 10 def tctype @tctype end |
#wgnumber ⇒ Object
Returns the value of attribute wgnumber.
10 11 12 |
# File 'lib/pubid/iso/identifier/base.rb', line 10 def wgnumber @wgnumber end |
#wgtype ⇒ Object
Returns the value of attribute wgtype.
10 11 12 |
# File 'lib/pubid/iso/identifier/base.rb', line 10 def wgtype @wgtype end |
Class Method Details
.create_supplements(params, base_params) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/pubid/iso/identifier/base.rb', line 139 def create_supplements(params, base_params) params.map do |supplement| Identifier.create( number: supplement[:number], year: supplement[:year], month: supplement[:month], stage: supplement[:typed_stage], edition: supplement[:edition], iteration: supplement[:iteration], type: supplement[:type] || !supplement[:typed_stage] && :sup, publisher: supplement[:publisher]&.to_s, base: Identifier.create(**base_params), separator: ([" + ", ", "].include?(supplement[:separator]&.to_s) ? supplement[:separator].to_s : nil) ) end end |
.get_amendment_class ⇒ Object
175 176 177 |
# File 'lib/pubid/iso/identifier/base.rb', line 175 def get_amendment_class Pubid::Iso::Amendment end |
.get_corrigendum_class ⇒ Object
179 180 181 |
# File 'lib/pubid/iso/identifier/base.rb', line 179 def get_corrigendum_class Pubid::Iso::Corrigendum end |
.get_identifier ⇒ Object
199 200 201 |
# File 'lib/pubid/iso/identifier/base.rb', line 199 def get_identifier Identifier end |
.get_parser_class ⇒ Object
183 184 185 |
# File 'lib/pubid/iso/identifier/base.rb', line 183 def get_parser_class Parser end |
.get_renderer_class ⇒ Object
191 192 193 |
# File 'lib/pubid/iso/identifier/base.rb', line 191 def get_renderer_class Renderer::Base end |
.get_transformer_class ⇒ Object
187 188 189 |
# File 'lib/pubid/iso/identifier/base.rb', line 187 def get_transformer_class Transformer end |
.get_update_codes ⇒ Object
195 196 197 |
# File 'lib/pubid/iso/identifier/base.rb', line 195 def get_update_codes UPDATE_CODES end |
.supplement_by_type(supplements, type) ⇒ Object
113 114 115 |
# File 'lib/pubid/iso/identifier/base.rb', line 113 def supplement_by_type(supplements, type) supplements.select { |supplement| supplement.type[:key] == type }.first end |
.supplements_has_type?(supplements, type) ⇒ Boolean
107 108 109 110 111 |
# File 'lib/pubid/iso/identifier/base.rb', line 107 def supplements_has_type?(supplements, type) supplements.any? do |supplement| supplement.type[:key] == type end end |
.transform(params) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/pubid/iso/identifier/base.rb', line 152 def transform(params) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength transformer = get_transformer_class.new params = transformer.apply(root: params) identifier_params = params.map { |k, v| transformer.apply(k => v) }.inject({}, :merge) # return supplement if supplements applied if identifier_params[:supplements].is_a?(Array) return transform_supplements( identifier_params[:supplements], identifier_params.dup.tap { |h| h.delete(:supplements) }, ) end if identifier_params[:extract] base_parameters = identifier_params.reject { |k, _| k == :extract } return Identifier.create(base: Identifier.create(**base_parameters), type: :ext, **identifier_params[:extract]) end Identifier.create(**identifier_params) end |
.transform_supplements(supplements_params, base_params) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/pubid/iso/identifier/base.rb', line 117 def transform_supplements(supplements_params, base_params) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity all_parts = base_params.delete(:all_parts) supplements = create_supplements supplements_params, base_params if supplements.count == 1 supplement = supplements.first # update corrigendum base to amendment elsif supplements_has_type?(supplements, :cor) && (supplements_has_type?(supplements, :amd) || supplements_has_type?(supplements, :sup)) && supplements.count == 2 supplement = supplement_by_type(supplements, :cor) supplement.base = supplement_by_type(supplements, :amd) || supplement_by_type(supplements, :sup) else raise Errors::SupplementRenderingError, "don't know how to render provided supplements" end supplement.all_parts = all_parts if all_parts supplement end |
.type_match?(parameters) ⇒ Boolean
203 204 205 |
# File 'lib/pubid/iso/identifier/base.rb', line 203 def type_match?(parameters) parameters[:type] ? has_type?(parameters[:type]) : has_typed_stage?(parameters[:stage]) end |
Instance Method Details
#render_all_parts ⇒ Object
286 287 288 |
# File 'lib/pubid/iso/identifier/base.rb', line 286 def render_all_parts all_parts ? " (all parts)" : "" end |
#render_joint_document(joint_document) ⇒ Object
280 281 282 283 284 |
# File 'lib/pubid/iso/identifier/base.rb', line 280 def render_joint_document(joint_document) return "" if joint_document.nil? || joint_document.to_s.empty? "|#{@joint_document}" end |
#resolve_format(format = :ref_dated_long) ⇒ Object
Format options are:
:ref_num_short -- instance reference number: 1 letter language code + short form (DAM) + dated
:ref_num_long -- instance reference number long: 2 letter language code + long form (DAmd) + dated
:ref_dated -- reference dated: no language code + short form (DAM) + dated
:ref_dated_long -- reference dated long: no language code + short form (DAM) + dated
:ref_undated -- reference undated: no language code + short form (DAM) + undated
:ref_undated_long -- reference undated long: 1 letter language code + long form (DAmd) + undated
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/pubid/iso/identifier/base.rb', line 224 def resolve_format(format = :ref_dated_long) = { with_date: true } case format when :ref_num_short [:with_language_code] = :single [:stage_format_long] = false when :ref_num_long [:with_language_code] = :iso [:stage_format_long] = true when :ref_dated [:with_language_code] = :none [:stage_format_long] = false when :ref_dated_long [:with_language_code] = :none [:stage_format_long] = true when :ref_undated [:with_language_code] = :none [:stage_format_long] = false [:with_date] = false when :ref_undated_long [:with_language_code] = :none [:stage_format_long] = true [:with_date] = false else raise Errors::WrongFormat, "#{format} is not available" end end |
#root ⇒ Object
Return typed stage abbreviation, eg. “FDTR”, “DIS”, “TR” returns root identifier
292 293 294 295 296 |
# File 'lib/pubid/iso/identifier/base.rb', line 292 def root return base.base if base&.base base || self end |
#to_s(lang: nil, with_edition: false, with_prf: false, format: :ref_dated_long, annotated: false) ⇒ String
Renders pubid identifier
Format options are:
:ref_num_short -- instance reference number: 1 letter language code + short form (DAM) + dated
:ref_num_long -- instance reference number long: 2 letter language code + long form (DAmd) + dated
:ref_dated -- reference dated: no language code + short form (DAM) + dated
:ref_dated_long -- reference dated long: no language code + short form (DAM) + dated
:ref_undated -- reference undated: no language code + short form (DAM) + undated
:ref_undated_long -- reference undated long: 1 letter language code + long form (DAmd) + undated
269 270 271 272 273 274 275 276 277 278 |
# File 'lib/pubid/iso/identifier/base.rb', line 269 def to_s(lang: nil, with_edition: false, with_prf: false, format: :ref_dated_long, annotated: false) = resolve_format(format) [:with_edition] = with_edition [:with_prf] = with_prf [:language] = lang [:annotated] = annotated self.class.get_renderer_class.new(to_h(deep: false)).render(**) + render_joint_document(@joint_document) + render_all_parts end |