Class: RelatonIeee::PubId

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_ieee/pub_id.rb

Defined Under Namespace

Classes: Id

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pubid) ⇒ PubId

IEEE publication id

Parameters:

  • pubid (Array<Hash>, Hash)


110
111
112
# File 'lib/relaton_ieee/pub_id.rb', line 110

def initialize(pubid)
  @pubid = array(pubid).map { |id| Id.new(**id) }
end

Instance Attribute Details

#pubidArray<RelatonIeee::PubId::Id> (readonly)

Returns:



103
104
105
# File 'lib/relaton_ieee/pub_id.rb', line 103

def pubid
  @pubid
end

Instance Method Details

#array(pid) ⇒ Array<Hash>

Convert to array

Parameters:

  • pid (Array<Hash>, Hash)

Returns:

  • (Array<Hash>)


121
122
123
# File 'lib/relaton_ieee/pub_id.rb', line 121

def array(pid)
  pid.is_a?(Array) ? pid : [pid]
end

#to_idString

Generate ID without publisher and second number

Returns:

  • (String)


141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/relaton_ieee/pub_id.rb', line 141

def to_id # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
  out = pubid[0].to_s
  if pubid.size > 1
    out += pubid[1].edition_to_s if pubid[0].edition.nil?
    out += pubid[1].draft_to_s if pubid[0].draft.nil?
    out += pubid[1].rev_to_s if pubid[0].rev.nil?
    out += pubid[1].corr_to_s if pubid[0].corr.nil?
    out += pubid[1].amd_to_s if pubid[0].amd.nil?
    out += pubid[1].year_to_s if pubid[0].year.nil?
    out += pubid[1].month_to_s if pubid[0].month.nil?
    out += pubid[1].redline_to_s unless pubid[0].redline
  end
  out
end

#to_s(trademark: false) ⇒ String

PubId string representation

Parameters:

  • trademark (Boolean) (defaults to: false)

    if true, add trademark symbol

Returns:

  • (String)


132
133
134
# File 'lib/relaton_ieee/pub_id.rb', line 132

def to_s(trademark: false)
  pubid.map { |id| id.to_s(trademark: trademark) }.join("/")
end