Class: Pubid::Iec::Base
- Inherits:
-
Core::Identifier::Base
- Object
- Core::Identifier::Base
- Pubid::Iec::Base
- Extended by:
- Forwardable
- Defined in:
- lib/pubid/iec/identifier/base.rb
Direct Known Subclasses
Identifier::ComponentSpecification, Identifier::ConformityAssessment, Identifier::Guide, Identifier::InternationalStandard, Identifier::InterpretationSheet, Identifier::OperationalDocument, Identifier::PubliclyAvailableSpecification, Identifier::SocietalTechnologyTrendReport, Identifier::Supplement, Identifier::SystemsReferenceDocument, Identifier::TechnicalReport, Identifier::TechnicalSpecification, Identifier::TechnologyAndMarketOutlookPaper, Identifier::TechnologyReport, Identifier::TestReportForm, Identifier::WritePaper, TrfIdentifier
Constant Summary collapse
- PROJECT_STAGES =
{}.freeze
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#conjuction_part ⇒ Object
Returns the value of attribute conjuction_part.
-
#database ⇒ Object
Returns the value of attribute database.
-
#day ⇒ Object
Returns the value of attribute day.
-
#decision_sheet ⇒ Object
Returns the value of attribute decision_sheet.
-
#fragment ⇒ Object
Returns the value of attribute fragment.
-
#month ⇒ Object
Returns the value of attribute month.
-
#part_version ⇒ Object
Returns the value of attribute part_version.
-
#sheet ⇒ Object
Returns the value of attribute sheet.
-
#test_type ⇒ Object
Returns the value of attribute test_type.
-
#trf_publisher ⇒ Object
Returns the value of attribute trf_publisher.
-
#trf_series ⇒ Object
Returns the value of attribute trf_series.
-
#trf_version ⇒ Object
Returns the value of attribute trf_version.
-
#vap ⇒ Object
Returns the value of attribute vap.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
- .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
- .has_project_stage?(project_stage) ⇒ Boolean
- .has_type?(type) ⇒ Boolean
- .normalize_urn_params!(params) ⇒ Object
- .resolve_project_stage(project_stage) ⇒ Object
- .transform(params) ⇒ Object
- .transform_hash(params) ⇒ Object
Instance Method Summary collapse
-
#initialize(publisher: "IEC", vap: nil, database: nil, fragment: nil, version: nil, decision_sheet: nil, conjuction_part: nil, part_version: nil, trf_publisher: nil, trf_series: nil, trf_version: nil, test_type: nil, edition: nil, type: nil, month: nil, day: nil, language: nil, stage: nil, sheet: nil, **args) ⇒ Base
constructor
A new instance of Base.
- #lookup_typed_stage(lookup_code) ⇒ Object
- #renderer_data ⇒ Object
- #root ⇒ Object
- #to_s(with_edition_month_date: false, annotated: false) ⇒ Object
- #to_yaml ⇒ Object
- #urn ⇒ Object
Constructor Details
#initialize(publisher: "IEC", vap: nil, database: nil, fragment: nil, version: nil, decision_sheet: nil, conjuction_part: nil, part_version: nil, trf_publisher: nil, trf_series: nil, trf_version: nil, test_type: nil, edition: nil, type: nil, month: nil, day: nil, language: nil, stage: nil, sheet: nil, **args) ⇒ Base
Returns a new instance of Base.
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 |
# File 'lib/pubid/iec/identifier/base.rb', line 15 def initialize(publisher: "IEC", vap: nil, database: nil, fragment: nil, version: nil, decision_sheet: nil, conjuction_part: nil, part_version: nil, trf_publisher: nil, trf_series: nil, trf_version: nil, test_type: nil, edition: nil, type: nil, month: nil, day: nil, language: nil, stage: nil, sheet: nil, **args) @vap = Array(vap).map(&:to_s) if vap @database = database if database @fragment = fragment.to_s if fragment @version = version if version @decision_sheet = decision_sheet if decision_sheet @conjuction_part = Array(conjuction_part).map(&:to_s) if conjuction_part @part_version = part_version if part_version @trf_publisher = trf_publisher.to_s if trf_publisher @trf_series = trf_series if trf_series @trf_version = trf_version.to_s if trf_version @test_type = test_type if test_type @edition = edition.to_s if edition @month = month.to_s if month @day = day.to_s if day @language = Array(language).map(&:to_s) if language @sheet = sheet.transform_values(&:to_s) if sheet if stage @stage = self.class.has_project_stage?(stage) ? self.class.resolve_project_stage(stage) : resolve_stage(stage) end super(**args.merge(publisher: publisher)) end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
6 7 8 |
# File 'lib/pubid/iec/identifier/base.rb', line 6 def base @base end |
#conjuction_part ⇒ Object
Returns the value of attribute conjuction_part.
6 7 8 |
# File 'lib/pubid/iec/identifier/base.rb', line 6 def conjuction_part @conjuction_part end |
#database ⇒ Object
Returns the value of attribute database.
6 7 8 |
# File 'lib/pubid/iec/identifier/base.rb', line 6 def database @database end |
#day ⇒ Object
Returns the value of attribute day.
6 7 8 |
# File 'lib/pubid/iec/identifier/base.rb', line 6 def day @day end |
#decision_sheet ⇒ Object
Returns the value of attribute decision_sheet.
6 7 8 |
# File 'lib/pubid/iec/identifier/base.rb', line 6 def decision_sheet @decision_sheet end |
#fragment ⇒ Object
Returns the value of attribute fragment.
6 7 8 |
# File 'lib/pubid/iec/identifier/base.rb', line 6 def fragment @fragment end |
#month ⇒ Object
Returns the value of attribute month.
6 7 8 |
# File 'lib/pubid/iec/identifier/base.rb', line 6 def month @month end |
#part_version ⇒ Object
Returns the value of attribute part_version.
6 7 8 |
# File 'lib/pubid/iec/identifier/base.rb', line 6 def part_version @part_version end |
#sheet ⇒ Object
Returns the value of attribute sheet.
6 7 8 |
# File 'lib/pubid/iec/identifier/base.rb', line 6 def sheet @sheet end |
#test_type ⇒ Object
Returns the value of attribute test_type.
6 7 8 |
# File 'lib/pubid/iec/identifier/base.rb', line 6 def test_type @test_type end |
#trf_publisher ⇒ Object
Returns the value of attribute trf_publisher.
6 7 8 |
# File 'lib/pubid/iec/identifier/base.rb', line 6 def trf_publisher @trf_publisher end |
#trf_series ⇒ Object
Returns the value of attribute trf_series.
6 7 8 |
# File 'lib/pubid/iec/identifier/base.rb', line 6 def trf_series @trf_series end |
#trf_version ⇒ Object
Returns the value of attribute trf_version.
6 7 8 |
# File 'lib/pubid/iec/identifier/base.rb', line 6 def trf_version @trf_version end |
#vap ⇒ Object
Returns the value of attribute vap.
6 7 8 |
# File 'lib/pubid/iec/identifier/base.rb', line 6 def vap @vap end |
#version ⇒ Object
Returns the value of attribute version.
6 7 8 |
# File 'lib/pubid/iec/identifier/base.rb', line 6 def version @version end |
Class Method Details
.get_amendment_class ⇒ Object
151 152 153 |
# File 'lib/pubid/iec/identifier/base.rb', line 151 def get_amendment_class Amendment end |
.get_corrigendum_class ⇒ Object
155 156 157 |
# File 'lib/pubid/iec/identifier/base.rb', line 155 def get_corrigendum_class Corrigendum end |
.get_identifier ⇒ Object
175 176 177 |
# File 'lib/pubid/iec/identifier/base.rb', line 175 def get_identifier Identifier end |
.get_parser_class ⇒ Object
159 160 161 |
# File 'lib/pubid/iec/identifier/base.rb', line 159 def get_parser_class Parser end |
.get_renderer_class ⇒ Object
163 164 165 |
# File 'lib/pubid/iec/identifier/base.rb', line 163 def get_renderer_class Renderer::Pubid end |
.get_transformer_class ⇒ Object
167 168 169 |
# File 'lib/pubid/iec/identifier/base.rb', line 167 def get_transformer_class Transformer end |
.get_update_codes ⇒ Object
171 172 173 |
# File 'lib/pubid/iec/identifier/base.rb', line 171 def get_update_codes UPDATE_CODES end |
.has_project_stage?(project_stage) ⇒ Boolean
86 87 88 |
# File 'lib/pubid/iec/identifier/base.rb', line 86 def has_project_stage?(project_stage) self::PROJECT_STAGES.any? { |k, v| v[:abbr] == project_stage } end |
.has_type?(type) ⇒ Boolean
90 91 92 93 94 95 96 97 98 |
# File 'lib/pubid/iec/identifier/base.rb', line 90 def has_type?(type) return type == self.type[:key] if type.is_a?(Symbol) if self.type.key?(:short) self.type[:short].is_a?(Array) ? self.type[:short].include?(type) : self.type[:short] == type else type.to_s.downcase.to_sym == self.type[:key] end end |
.normalize_urn_params!(params) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/pubid/iec/identifier/base.rb', line 130 def normalize_urn_params!(params) params[:publisher] = params[:publisher].to_s.upcase params[:copublisher] = params[:copublisher].to_s.upcase if params[:copublisher] params[:type] = params[:type].to_s.upcase if params[:type] params[:number] = params[:number].to_s.upcase # Map fuzzy URN stages to abbreviations that resolve correctly if params[:stage] stage_str = params[:stage].to_s case stage_str when "draft" then params[:stage] = "CD" when "published" then params[:stage] = "60.60" end end # Remove amendments/corrigendums parsed as bare strings from URN # (full supplement round-trip support to be added later) params.delete(:amendments) if params[:amendments].is_a?(String) params.delete(:corrigendums) if params[:corrigendums].is_a?(String) end |
.resolve_project_stage(project_stage) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/pubid/iec/identifier/base.rb', line 100 def resolve_project_stage(project_stage) stage = self::PROJECT_STAGES.find do |k, v| v[:abbr] == project_stage end Identifier.build_project_stage(abbr: stage[1][:abbr], harmonized_code: stage[1][:harmonized_stages]) end |
.transform(params) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/pubid/iec/identifier/base.rb', line 114 def transform(params) identifier_params = transform_hash(params) normalize_urn_params!(identifier_params) if identifier_params[:publisher].to_s.match?(/\A[a-z]+\z/) if identifier_params[:interpretation_sheet] return Identifier.create( type: :ish, base: Identifier.create( **identifier_params.dup.tap { |h| h.delete(:interpretation_sheet) }), number: identifier_params[:interpretation_sheet][:number], year: identifier_params[:interpretation_sheet][:year] ) end Identifier.create(**identifier_params) end |
.transform_hash(params) ⇒ Object
108 109 110 111 112 |
# File 'lib/pubid/iec/identifier/base.rb', line 108 def transform_hash(params) params.map do |k, v| get_transformer_class.new.apply(k => v.is_a?(Hash) ? transform_hash(v) : v) end.inject({}, :merge) end |
Instance Method Details
#lookup_typed_stage(lookup_code) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/pubid/iec/identifier/base.rb', line 50 def lookup_typed_stage(lookup_code) self.class::TYPED_STAGES.each do |abbr, stage| if stage[:harmonized_stages] & lookup_code == lookup_code return Identifier.build_typed_stage(abbr: abbr, harmonized_code: lookup_code) end end nil end |
#renderer_data ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/pubid/iec/identifier/base.rb', line 60 def renderer_data values = to_h(deep: false) # convert project stage to typed stage if values.key?(:stage) && values[:stage].is_a?(TypedProjectStage) values[:stage] = lookup_typed_stage(values[:stage].harmonized_code.stages) || resolve_stage(values[:stage].harmonized_code.stages.first) end values end |
#root ⇒ Object
81 82 83 |
# File 'lib/pubid/iec/identifier/base.rb', line 81 def root base || self end |
#to_s(with_edition_month_date: false, annotated: false) ⇒ Object
71 72 73 74 75 |
# File 'lib/pubid/iec/identifier/base.rb', line 71 def to_s(with_edition_month_date: false, annotated: false) result = self.class.get_renderer_class.new(renderer_data).render(with_edition_month_date: with_edition_month_date, annotated: annotated) result += " (all parts)" if all_parts result end |
#to_yaml ⇒ Object
77 78 79 |
# File 'lib/pubid/iec/identifier/base.rb', line 77 def to_yaml to_h(deep: true).to_yaml end |