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
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.
-
#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_renderer_class ⇒ Object
- .get_transformer_class ⇒ Object
- .parse(code) ⇒ Object
- .transform(params) ⇒ Object
- .type ⇒ Object
- .update_old_code(code) ⇒ Object
Instance Method Summary collapse
-
#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, **opts) ⇒ Base
constructor
A new instance of Base.
-
#set_values(hash) ⇒ Object
convert parameters comes from parser to.
- #to_s(format = :short, with_trademark: false) ⇒ Object
- #trademark(number) ⇒ Object
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, **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 69 70 71 72 73 74 |
# 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, **opts) super(**opts.merge(number: number, publisher: publisher))#.merge(amendments: amendments, corrigendums: corrigendums)) if edition @edition = edition.update(edition) do |key, value| case key when :year, :month value.to_i else value end end end @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 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 |
#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
85 86 87 |
# File 'lib/pubid/ieee/identifier/base.rb', line 85 def self.add_missing_bracket(code) code.count("(") > code.count(")") ? "#{code})" : code end |
.get_renderer_class ⇒ Object
126 127 128 |
# File 'lib/pubid/ieee/identifier/base.rb', line 126 def get_renderer_class Renderer::Base end |
.get_transformer_class ⇒ Object
130 131 132 |
# File 'lib/pubid/ieee/identifier/base.rb', line 130 def get_transformer_class Transformer end |
.parse(code) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/pubid/ieee/identifier/base.rb', line 97 def self.parse(code) parsed = Parser.new.parse(update_old_code(code)) transform(parsed) rescue Parslet::ParseFailed => failure raise Pubid::Ieee::Errors::ParseError, "#{failure.}\ncause: #{failure.parse_failure_cause.ascii_tree}" end |
.transform(params) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/pubid/ieee/identifier/base.rb', line 105 def self.transform(params) identifier_params = params.map do |k, v| get_transformer_class.new.apply(k => v) end.inject({}, :merge) Identifier.create(**Identifier.convert_parser_parameters(**identifier_params)) end |
.type ⇒ Object
76 77 78 |
# File 'lib/pubid/ieee/identifier/base.rb', line 76 def self.type { key: :std, title: "Standard" } end |
.update_old_code(code) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/pubid/ieee/identifier/base.rb', line 89 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
#set_values(hash) ⇒ Object
convert parameters comes from parser to
81 82 83 |
# File 'lib/pubid/ieee/identifier/base.rb', line 81 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) ⇒ Object
114 115 116 117 118 119 |
# File 'lib/pubid/ieee/identifier/base.rb', line 114 def to_s(format = :short, with_trademark: false) opts = { format: format, with_trademark: with_trademark } (@iso_identifier ? @iso_identifier.to_s(format: :ref_num_short) : "") + self.class.get_renderer_class.new(to_h(deep: false)).render(**opts) + (with_trademark ? trademark(@number) : "") end |
#trademark(number) ⇒ Object
121 122 123 |
# File 'lib/pubid/ieee/identifier/base.rb', line 121 def trademark(number) %w(802 2030).include?(number.to_s) ? "\u00AE" : "\u2122" end |