Class: Pubid::Ieee::Identifier::Base

Inherits:
Core::Identifier::Base
  • Object
show all
Defined in:
lib/pubid/ieee/identifier/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#adoptionObject

Returns the value of attribute adoption.



9
10
11
# File 'lib/pubid/ieee/identifier/base.rb', line 9

def adoption
  @adoption
end

#adoption_yearObject

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

#alternativeObject

Returns the value of attribute alternative.



9
10
11
# File 'lib/pubid/ieee/identifier/base.rb', line 9

def alternative
  @alternative
end

#amendmentObject

Returns the value of attribute amendment.



9
10
11
# File 'lib/pubid/ieee/identifier/base.rb', line 9

def amendment
  @amendment
end

#corrigendumObject

Returns the value of attribute corrigendum.



9
10
11
# File 'lib/pubid/ieee/identifier/base.rb', line 9

def corrigendum
  @corrigendum
end

#corrigendum_commentObject

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

#draftObject

Returns the value of attribute draft.



9
10
11
# File 'lib/pubid/ieee/identifier/base.rb', line 9

def draft
  @draft
end

#draft_statusObject

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

#editionObject

Returns the value of attribute edition.



9
10
11
# File 'lib/pubid/ieee/identifier/base.rb', line 9

def edition
  @edition
end

#includesObject

Returns the value of attribute includes.



9
10
11
# File 'lib/pubid/ieee/identifier/base.rb', line 9

def includes
  @includes
end

#incorporatesObject

Returns the value of attribute incorporates.



9
10
11
# File 'lib/pubid/ieee/identifier/base.rb', line 9

def incorporates
  @incorporates
end

#iso_amendmentObject

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_identifierObject

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

#iterationObject

Returns the value of attribute iteration.



9
10
11
# File 'lib/pubid/ieee/identifier/base.rb', line 9

def iteration
  @iteration
end

#monthObject

Returns the value of attribute month.



9
10
11
# File 'lib/pubid/ieee/identifier/base.rb', line 9

def month
  @month
end

#proposalObject

Returns the value of attribute proposal.



9
10
11
# File 'lib/pubid/ieee/identifier/base.rb', line 9

def proposal
  @proposal
end

#reaffirmedObject

Returns the value of attribute reaffirmed.



9
10
11
# File 'lib/pubid/ieee/identifier/base.rb', line 9

def reaffirmed
  @reaffirmed
end

#redlineObject

Returns the value of attribute redline.



9
10
11
# File 'lib/pubid/ieee/identifier/base.rb', line 9

def redline
  @redline
end

#revisionObject

Returns the value of attribute revision.



9
10
11
# File 'lib/pubid/ieee/identifier/base.rb', line 9

def revision
  @revision
end

#subpartObject

Returns the value of attribute subpart.



9
10
11
# File 'lib/pubid/ieee/identifier/base.rb', line 9

def subpart
  @subpart
end

#supersedesObject

Returns the value of attribute supersedes.



9
10
11
# File 'lib/pubid/ieee/identifier/base.rb', line 9

def supersedes
  @supersedes
end

#supplementObject

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_classObject



126
127
128
# File 'lib/pubid/ieee/identifier/base.rb', line 126

def get_renderer_class
  Renderer::Base
end

.get_transformer_classObject



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.message}\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

.typeObject



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

Parameters:

  • format (:short, :full) (defaults to: :short)


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