Class: Pubid::Ieee::Identifier::Base
- Inherits:
-
Core::Identifier::Base
- Object
- Core::Identifier::Base
- Pubid::Ieee::Identifier::Base
- Defined in:
- lib/pubid/ieee/identifier/base.rb
Constant Summary collapse
- REGISTERED_SERIES =
IEEE series carrying a registered trademark ("\u00AE"); everything else takes the unregistered mark ("\u2122"). 8802 is the ISO/IEC co-published form of the 802 series, and a project number keeps its series identity, so a leading "P" is stripped before the lookup.
%w[802 8802 2030].freeze
- ISO_ADOPTED_SERIES =
The ISO/IEC adoption of IEEE 802: the number alone identifies the series, whatever publishers are printed.
"8802".freeze
Instance Attribute Summary collapse
-
#adoption ⇒ Object
Returns the value of attribute adoption.
-
#adoption_year ⇒ Object
Returns the value of attribute adoption_year.
-
#alternative ⇒ Object
Returns the value of attribute alternative.
-
#amendment ⇒ Object
Returns the value of attribute amendment.
-
#corrigendum ⇒ Object
Returns the value of attribute corrigendum.
-
#corrigendum_comment ⇒ Object
Returns the value of attribute corrigendum_comment.
-
#day ⇒ Object
Returns the value of attribute day.
-
#draft ⇒ Object
Returns the value of attribute draft.
-
#draft_status ⇒ Object
Returns the value of attribute draft_status.
-
#edition ⇒ Object
Returns the value of attribute edition.
-
#includes ⇒ Object
Returns the value of attribute includes.
-
#incorporates ⇒ Object
Returns the value of attribute incorporates.
-
#iso_amendment ⇒ Object
Returns the value of attribute iso_amendment.
-
#iso_identifier ⇒ Object
Returns the value of attribute iso_identifier.
-
#iteration ⇒ Object
Returns the value of attribute iteration.
-
#month ⇒ Object
Returns the value of attribute month.
-
#proposal ⇒ Object
Returns the value of attribute proposal.
-
#reaffirmed ⇒ Object
Returns the value of attribute reaffirmed.
-
#redline ⇒ Object
Returns the value of attribute redline.
-
#revision ⇒ Object
Returns the value of attribute revision.
-
#subpart ⇒ Object
Returns the value of attribute subpart.
-
#supersedes ⇒ Object
Returns the value of attribute supersedes.
-
#supplement ⇒ Object
Returns the value of attribute supplement.
Class Method Summary collapse
- .add_missing_bracket(code) ⇒ Object
- .get_parser_class ⇒ Object
- .get_renderer_class ⇒ Object
- .get_transformer_class ⇒ Object
- .transform(params) ⇒ Object
- .transform_parameters(params) ⇒ Object
- .type ⇒ Object
- .update_old_code(code) ⇒ Object
Instance Method Summary collapse
-
#fallback_number ⇒ Object
Document number to pick the symbol from when the mark falls back to the end of the string.
-
#initialize(publisher: "IEEE", number: nil, stage: nil, subpart: nil, edition: nil, draft: nil, redline: nil, month: nil, revision: nil, iso_identifier: nil, type: :std, alternative: nil, draft_status: nil, adoption_year: nil, amendment: nil, supersedes: nil, corrigendum: nil, corrigendum_comment: nil, reaffirmed: nil, incorporates: nil, supplement: nil, proposal: nil, iso_amendment: nil, iteration: nil, includes: nil, adoption: nil, year: nil, day: nil, **opts) ⇒ Base
constructor
A new instance of Base.
-
#marks_a_number? ⇒ Boolean
True when the rendered string carries the mark on a number of its own: either this identifier's number, or the IEEE designation it renders as a parenthesised alternative.
-
#set_values(hash) ⇒ Object
convert parameters comes from parser to.
- #to_s(format = :short, with_trademark: false, annotated: false) ⇒ Object
-
#trademark(number) ⇒ Object
The registered mark belongs to IEEE, so it is claimed only when IEEE is among the printed publishers -- another body may simply have numbered a document 802 or 2030 ("AIEE Std No. 802" predates the IEEE 802 series by two decades).
Constructor Details
#initialize(publisher: "IEEE", number: nil, stage: nil, subpart: nil, edition: nil, draft: nil, redline: nil, month: nil, revision: nil, iso_identifier: nil, type: :std, alternative: nil, draft_status: nil, adoption_year: nil, amendment: nil, supersedes: nil, corrigendum: nil, corrigendum_comment: nil, reaffirmed: nil, incorporates: nil, supplement: nil, proposal: nil, iso_amendment: nil, iteration: nil, includes: nil, adoption: nil, year: nil, day: nil, **opts) ⇒ 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/pubid/ieee/identifier/base.rb', line 15 def initialize(publisher: "IEEE", number: nil, stage: nil, subpart: nil, edition: nil, draft: nil, redline: nil, month: nil, revision: nil, iso_identifier: nil, type: :std, alternative: nil, draft_status: nil, adoption_year: nil, amendment: nil, supersedes: nil, corrigendum: nil, corrigendum_comment: nil, reaffirmed: nil, incorporates: nil, supplement: nil, proposal: nil, iso_amendment: nil, iteration: nil, includes: nil, adoption: nil, year: nil, day: nil, **opts) super(**opts.merge(number: number, publisher: publisher))#.merge(amendments: amendments, corrigendums: corrigendums)) @edition = edition if edition @proposal = @number.to_s[0] == "P" @revision = revision if iso_identifier @iso_identifier = Pubid::Iso::Identifier.parse(iso_identifier) elsif draft# && type != :p @type = Type.new(:draft) elsif type if type.is_a?(Symbol) @type = Type.new(type) else @type = Type.parse(type) end else @type = Type.new end @stage = stage @subpart = subpart @draft = draft @redline = redline @month = month @revision = revision @amendment = amendment @corrigendum = corrigendum @corrigendum_comment = corrigendum_comment @alternative = alternative @draft_status = draft_status @adoption_year = adoption_year @supersedes = supersedes @reaffirmed = reaffirmed @incorporates = incorporates @supplement = supplement @proposal = proposal @iso_amendment = iso_amendment @iteration = iteration @includes = includes @adoption = adoption @year = year.is_a?(Array) ? year.first.to_i : year.to_i if year @day = day.to_i if day end |
Instance Attribute Details
#adoption ⇒ Object
Returns the value of attribute adoption.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def adoption @adoption end |
#adoption_year ⇒ Object
Returns the value of attribute adoption_year.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def adoption_year @adoption_year end |
#alternative ⇒ Object
Returns the value of attribute alternative.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def alternative @alternative end |
#amendment ⇒ Object
Returns the value of attribute amendment.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def amendment @amendment end |
#corrigendum ⇒ Object
Returns the value of attribute corrigendum.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def corrigendum @corrigendum end |
#corrigendum_comment ⇒ Object
Returns the value of attribute corrigendum_comment.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def corrigendum_comment @corrigendum_comment end |
#day ⇒ Object
Returns the value of attribute day.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def day @day end |
#draft ⇒ Object
Returns the value of attribute draft.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def draft @draft end |
#draft_status ⇒ Object
Returns the value of attribute draft_status.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def draft_status @draft_status end |
#edition ⇒ Object
Returns the value of attribute edition.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def edition @edition end |
#includes ⇒ Object
Returns the value of attribute includes.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def includes @includes end |
#incorporates ⇒ Object
Returns the value of attribute incorporates.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def incorporates @incorporates end |
#iso_amendment ⇒ Object
Returns the value of attribute iso_amendment.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def iso_amendment @iso_amendment end |
#iso_identifier ⇒ Object
Returns the value of attribute iso_identifier.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def iso_identifier @iso_identifier end |
#iteration ⇒ Object
Returns the value of attribute iteration.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def iteration @iteration end |
#month ⇒ Object
Returns the value of attribute month.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def month @month end |
#proposal ⇒ Object
Returns the value of attribute proposal.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def proposal @proposal end |
#reaffirmed ⇒ Object
Returns the value of attribute reaffirmed.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def reaffirmed @reaffirmed end |
#redline ⇒ Object
Returns the value of attribute redline.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def redline @redline end |
#revision ⇒ Object
Returns the value of attribute revision.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def revision @revision end |
#subpart ⇒ Object
Returns the value of attribute subpart.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def subpart @subpart end |
#supersedes ⇒ Object
Returns the value of attribute supersedes.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def supersedes @supersedes end |
#supplement ⇒ Object
Returns the value of attribute supplement.
9 10 11 |
# File 'lib/pubid/ieee/identifier/base.rb', line 9 def supplement @supplement end |
Class Method Details
.add_missing_bracket(code) ⇒ Object
79 80 81 |
# File 'lib/pubid/ieee/identifier/base.rb', line 79 def self.add_missing_bracket(code) code.count("(") > code.count(")") ? "#{code})" : code end |
.get_parser_class ⇒ Object
219 220 221 |
# File 'lib/pubid/ieee/identifier/base.rb', line 219 def get_parser_class Parser end |
.get_renderer_class ⇒ Object
211 212 213 |
# File 'lib/pubid/ieee/identifier/base.rb', line 211 def get_renderer_class Renderer::Base end |
.get_transformer_class ⇒ Object
215 216 217 |
# File 'lib/pubid/ieee/identifier/base.rb', line 215 def get_transformer_class Transformer end |
.transform(params) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/pubid/ieee/identifier/base.rb', line 128 def self.transform(params) # transform inside parameters identifier_params = transform_parameters( Identifier.convert_parser_parameters(**params), ) if identifier_params.key?(:draft) && identifier_params[:draft].key?(:year) identifier_params[:year] = identifier_params[:draft][:year] identifier_params[:month] = identifier_params[:draft][:month] identifier_params[:day] = identifier_params[:draft][:day] identifier_params[:draft].delete(:year) identifier_params[:draft].delete(:month) end Identifier.create(**identifier_params) end |
.transform_parameters(params) ⇒ 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 125 126 |
# File 'lib/pubid/ieee/identifier/base.rb', line 91 def self.transform_parameters(params) return params if params == "" if params[:iso_identifier] if params[:iso_identifier].is_a?(Array) params[:iso_identifier] = array_to_hash(params[:iso_identifier]) end if params[:iso_identifier][:month] params[:month] = params[:iso_identifier][:month] params[:year] = params[:iso_identifier][:year] params[:iso_identifier].delete(:year) params[:iso_identifier].delete(:month) end end params.map do |k, v| case k when :parameters, :draft, :alternative v = Identifier.merge_parameters(v) if k == :draft # apply transformer for each separate item when array provided if v.is_a?(Array) get_transformer_class.new.apply(k => v.map { |vv| transform_parameters(vv) }) else get_transformer_class.new.apply(k => transform_parameters(v)) end when :iso_identifier v = Identifier.merge_parameters(v) result = get_transformer_class.new.apply(k => v) # apply transformation when output was transformed to IEEE result.key?(:iso_identifier) ? result : transform_parameters(result) else get_transformer_class.new.apply(k => v) end end.inject({}, :merge) end |
.type ⇒ Object
70 71 72 |
# File 'lib/pubid/ieee/identifier/base.rb', line 70 def self.type { key: :std, title: "Standard" } end |
.update_old_code(code) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/pubid/ieee/identifier/base.rb', line 83 def self.update_old_code(code) UPDATE_CODES.each do |from, to| code = code.gsub(from.match?(/^\/.*\/$/) ? Regexp.new(from[1..-2]) : /^#{Regexp.escape(from)}$/, to) end code end |
Instance Method Details
#fallback_number ⇒ Object
Document number to pick the symbol from when the mark falls back to the
end of the string. The ISO identifier holds the only number there is,
and for a supplement it is the base document that carries the series
(an amendment's own number is its ordinal, "1").
186 187 188 189 190 191 192 |
# File 'lib/pubid/ieee/identifier/base.rb', line 186 def fallback_number return @number if @number iso = @iso_identifier iso = iso.base while iso.respond_to?(:base) && iso.base iso&.number end |
#marks_a_number? ⇒ Boolean
True when the rendered string carries the mark on a number of its own: either this identifier's number, or the IEEE designation it renders as a parenthesised alternative. A form that renders neither -- an ISO-led document with no IEEE designation of its own, such as "ISO/IEC/IEEE 8802-11:2012/Amd.1:2013(E)" or "IEC 61588:2009(E)" -- keeps the trailing mark rather than losing it altogether.
178 179 180 |
# File 'lib/pubid/ieee/identifier/base.rb', line 178 def marks_a_number? !@number.nil? || !@alternative.nil? end |
#set_values(hash) ⇒ Object
convert parameters comes from parser to
75 76 77 |
# File 'lib/pubid/ieee/identifier/base.rb', line 75 def set_values(hash) hash.each { |key, value| send("#{key}=", value.is_a?(Parslet::Slice) && value.to_s || value) } end |
#to_s(format = :short, with_trademark: false, annotated: false) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/pubid/ieee/identifier/base.rb', line 157 def to_s(format = :short, with_trademark: false, annotated: false) opts = { format: format, with_trademark: with_trademark, annotated: annotated } params = to_h(deep: false) # IEEE attaches the mark to the standard number, before the year and # every suffix ("IEEE Std 1619\u2122-2007"), so it is rendered from a # dedicated slot in the format templates rather than appended to the # finished string. An identifier without a number of its own (an # ISO-led co-publication) carries its IEEE designation in the # parenthesised alternative, which is marked by the renderer instead. params[:trademark] = trademark(@number) if with_trademark && @number (@iso_identifier ? @iso_identifier.to_s(format: :ref_num_short, with_edition: true, annotated: annotated) : "") + self.class.get_renderer_class.new(params).render(**opts) + (with_trademark && !marks_a_number? ? trademark(fallback_number) : "") end |
#trademark(number) ⇒ Object
The registered mark belongs to IEEE, so it is claimed only when IEEE is among the printed publishers -- another body may simply have numbered a document 802 or 2030 ("AIEE Std No. 802" predates the IEEE 802 series by two decades). The ISO/IEC adoption 8802 is identified by its number alone, whatever publishers are printed.
199 200 201 202 203 204 205 206 207 208 |
# File 'lib/pubid/ieee/identifier/base.rb', line 199 def trademark(number) = number.to_s.sub(/\AP/, "") return "\u2122" unless REGISTERED_SERIES.include?() return "\u00AE" if == ISO_ADOPTED_SERIES ieee = [@publisher, *@copublisher].compact.any? do |publisher| publisher.to_s.split("/").include?("IEEE") end ieee ? "\u00AE" : "\u2122" end |