Class: Pubid::Ieee::Renderer::Base

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

Instance Method Summary collapse

Instance Method Details

#render_adoption(adoption, opts, _params) ⇒ Object



171
172
173
# File 'lib/pubid/ieee/renderer/base.rb', line 171

def render_adoption(adoption, _opts, _params)
  adoption
end

#render_adoption_year(adoption_year, _opts, _params) ⇒ Object



165
166
167
168
169
# File 'lib/pubid/ieee/renderer/base.rb', line 165

def render_adoption_year(adoption_year, _opts, _params)
  adoption_id = dup
  adoption_id.year = adoption_year
  " (Adoption of #{adoption_id.identifier})"
end

#render_alternative(alternative, _opts, _params) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/pubid/ieee/renderer/base.rb', line 86

def render_alternative(alternative, _opts, _params)
  if alternative.is_a?(Array)
    " (#{alternative.map { |a| Pubid::Ieee::Identifier::Base.new(**Pubid::Ieee::Identifier.convert_parser_parameters(**a)) }.join(', ')})"
  else
    " (#{Pubid::Ieee::Identifier::Base.new(**Pubid::Ieee::Identifier.convert_parser_parameters(**alternative))})"
  end
end

#render_amendment(amendment, _opts, _params) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/pubid/ieee/renderer/base.rb', line 118

def render_amendment(amendment, _opts, _params)
  return " (Amendment to #{amendment})" unless amendment.is_a?(Array)

  result = " (Amendment to #{amendment.first} as amended by "
  result += if amendment.length > 2
              "#{amendment[1..-2].map(&:to_s).join(', ')}, and #{amendment[-1]}"
            else
              amendment.last.to_s
            end

  "#{result})"
end

#render_corrigendum(corrigendum, _opts, params) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/pubid/ieee/renderer/base.rb', line 131

def render_corrigendum(corrigendum, _opts, params)
  # if corrigendum.nil?
  #   (params[:year] && corrigendum_comment && "/Cor 1-#{params[:year]}") || ""
  # else
  if corrigendum[:year]
    "/Cor #{corrigendum[:version]}-#{corrigendum[:year]}"
  else
    "/Cor #{corrigendum[:version]}"
  end
  # end
end

#render_corrigendum_comment(corrigendum_comment, _opts, params) ⇒ Object



39
40
41
# File 'lib/pubid/ieee/renderer/base.rb', line 39

def render_corrigendum_comment(corrigendum_comment, _opts, params)
  "/Cor 1-#{params[:year]}" if params[:year]
end

#render_draft(draft, _opts, _params) ⇒ Object



94
95
96
97
98
99
100
101
102
103
# File 'lib/pubid/ieee/renderer/base.rb', line 94

def render_draft(draft, _opts, _params)
  draft = Pubid::Ieee::Identifier.merge_parameters(draft) if draft.is_a?(Array)

  result = "/D#{draft[:version].is_a?(Array) ? draft[:version].join('D') : draft[:version]}"
  result += ".#{draft[:revision]}" if draft[:revision]
  result += ", #{draft[:month]}" if draft[:month]
  result += " #{draft[:day]}," if draft[:day]
  result += " #{draft[:year]}" if draft[:year]
  result
end

#render_draft_status(draft_status, opts, _params) ⇒ Object



105
106
107
# File 'lib/pubid/ieee/renderer/base.rb', line 105

def render_draft_status(draft_status, opts, _params)
  " #{draft_status}" if opts[:format] == :full
end

#render_edition(edition, _opts, _params) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/pubid/ieee/renderer/base.rb', line 63

def render_edition(edition, _opts, _params)
  result = ""
  if edition[:version]
    result += edition[:version] == "First" ? " Edition 1.0 " : " Edition #{edition[:version]} "
  end

  if edition[:year]
    result += if edition[:version]
                "#{edition[:year]}"
              else
                " #{edition[:year]} Edition"
              end
  end

  if edition[:month]
    month = edition[:month]
    month = Date.parse(edition[:month]).month if month.to_i.zero?
    result += "-#{sprintf('%02d', month)}"
  end
  result += "-#{edition[:day]}" if edition[:day]
  result
end

#render_identifier(params) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/pubid/ieee/renderer/base.rb', line 3

def render_identifier(params)
  if params[:iso_identifier].to_s != "" && params[:number] != ""
    " (%{publisher}%{stage}%{draft_status}%{type}%{number}%{iteration}%{part}%{subpart}%{month}%{year}%{corrigendum_comment}"\
    "%{corrigendum}%{draft}%{edition})%{alternative}%{supersedes}%{reaffirmed}%{incorporates}%{supplement}"\
    "%{revision}%{iso_amendment}%{amendment}%{includes}%{redline}%{adoption}" % params
  else
    "%{publisher}%{stage}%{draft_status}%{type}%{number}%{iteration}%{part}%{subpart}%{month}%{year}%{corrigendum_comment}"\
    "%{corrigendum}%{draft}%{edition}%{alternative}%{supersedes}%{reaffirmed}%{incorporates}%{supplement}"\
    "%{revision}%{iso_amendment}%{amendment}%{includes}%{redline}%{adoption}" % params
  end
end

#render_includes(includes, _opts, _params) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/pubid/ieee/renderer/base.rb', line 55

def render_includes(includes, _opts, _params)
  if includes.is_a?(Hash) && includes[:supplement]
    return " (Includes Supplement #{includes[:supplement]})"
  end

  " (Includes #{includes})"
end

#render_incorporates(incorporates, _opts, _params) ⇒ Object



157
158
159
# File 'lib/pubid/ieee/renderer/base.rb', line 157

def render_incorporates(incorporates, _opts, _params)
  " (Incorporates #{incorporates.join(', and ')})"
end

#render_iso_amendment(iso_amendment, _opts, _params) ⇒ Object



175
176
177
178
# File 'lib/pubid/ieee/renderer/base.rb', line 175

def render_iso_amendment(iso_amendment, _opts, _params)
  "/Amd#{iso_amendment[:version]}" +
    (iso_amendment[:year] ? "-#{iso_amendment[:year]}" : "")
end

#render_month(month, _opts, _params) ⇒ Object



35
36
37
# File 'lib/pubid/ieee/renderer/base.rb', line 35

def render_month(month, _opts, _params)
  ", #{month}"
end

#render_number(number, _opts, _params) ⇒ Object



15
16
17
# File 'lib/pubid/ieee/renderer/base.rb', line 15

def render_number(number, _opts, _params)
  " #{number}"
end

#render_part(part, _opts, _params) ⇒ Object



31
32
33
# File 'lib/pubid/ieee/renderer/base.rb', line 31

def render_part(part, _opts, _params)
  "#{part}"
end

#render_publisher(publisher, opts, params) ⇒ Object



19
20
21
22
# File 'lib/pubid/ieee/renderer/base.rb', line 19

def render_publisher(publisher, opts, params)
  # don't render publisher if no number assigned
  super if params[:number]
end

#render_reaffirmed(reaffirmed, _opts, params) ⇒ Object



151
152
153
154
155
# File 'lib/pubid/ieee/renderer/base.rb', line 151

def render_reaffirmed(reaffirmed, _opts, params)
  return " (Reaffirmed #{params[:year]})" if reaffirmed.key?(:reaffirmation_of)

  " (Reaffirmed #{reaffirmed[:year]})" if reaffirmed[:year]
end

#render_redline(_redline, _opts, _params) ⇒ Object



113
114
115
# File 'lib/pubid/ieee/renderer/base.rb', line 113

def render_redline(_redline, _opts, _params)
  " - Redline"
end

#render_revision(revision, _opts, _params) ⇒ Object



109
110
111
# File 'lib/pubid/ieee/renderer/base.rb', line 109

def render_revision(revision, _opts, _params)
  " (Revision of #{revision.join(' and ')})" if revision
end

#render_supersedes(supersedes, _opts, _params) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/pubid/ieee/renderer/base.rb', line 143

def render_supersedes(supersedes, _opts, _params)
  if supersedes.length > 2
    " (Supersedes #{supersedes.join(', ')})"
  else
    " (Supersedes #{supersedes.join(' and ')})"
  end
end

#render_supplement(supplement, _opts, _params) ⇒ Object



161
162
163
# File 'lib/pubid/ieee/renderer/base.rb', line 161

def render_supplement(supplement, _opts, _params)
  " (Supplement to #{supplement})" if supplement
end

#render_type(type, opts, params) ⇒ Object



24
25
26
27
28
29
# File 'lib/pubid/ieee/renderer/base.rb', line 24

def render_type(type, opts, params)
  result = type.to_s(params[:publisher] == "IEEE" ? opts[:format] : :alternative)

  " #{result}" unless result.empty?
  #" #{type}"
end

#render_year(year, _opts, params) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pubid/ieee/renderer/base.rb', line 43

def render_year(year, _opts, params)
  return " #{year}" if params[:month]

  if params[:corrigendum_comment]
    "-#{params[:corrigendum_comment].year}"
  elsif params[:reaffirmed] && params[:reaffirmed].key?(:reaffirmation_of)
    "-#{params[:reaffirmed][:reaffirmation_of].year}"
  else
    "-#{year}"
  end
end