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



200
201
202
# File 'lib/pubid/ieee/renderer/base.rb', line 200

def render_adoption(adoption, _opts, _params)
  adoption
end

#render_adoption_year(adoption_year, _opts, _params) ⇒ Object



194
195
196
197
198
# File 'lib/pubid/ieee/renderer/base.rb', line 194

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



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

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



147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/pubid/ieee/renderer/base.rb', line 147

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



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/pubid/ieee/renderer/base.rb', line 160

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



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

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

#render_day(day, _opts, params) ⇒ Object



47
48
49
50
51
# File 'lib/pubid/ieee/renderer/base.rb', line 47

def render_day(day, _opts, params)
  # month = Date.parse(params[:month]).month
  # " %s-%s-%02d" % [params[:year], month, day]
  " #{day}"
end

#render_draft(draft, _opts, params) ⇒ Object



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

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

  result = if draft[:version].is_a?(Array)
             "/D#{draft[:version].join('D')}"
           else
             "/#{draft[:version].to_s.match?(/^\d/) ? 'D' : ''}#{draft[:version]}"
           end
  result += "#{params[:iteration]}" if params[:iteration]
  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



134
135
136
# File 'lib/pubid/ieee/renderer/base.rb', line 134

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

#render_edition(edition, _opts, _params) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/pubid/ieee/renderer/base.rb', line 86

def render_edition(edition, _opts, _params)
  edition == "First" ? " Edition 1.0" : " Edition #{edition}"
  # result = ""
  # if edition[:version]
  #   result +=
  # 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
14
15
16
17
18
19
20
21
# 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}%{edition}%{includes}%{redline}%{adoption}" % params
  else
    if params[:day].empty? && params[:month].empty?
      # if only year - edition and draft after year
      "%{publisher}%{draft_status}%{type}%{number}%{part}%{subpart}%{stage}"\
      "%{year}%{edition}%{corrigendum_comment}%{corrigendum}%{draft}%{alternative}%{supersedes}%{reaffirmed}%{incorporates}%{supplement}"\
      "%{revision}%{iso_amendment}%{amendment}%{includes}%{redline}%{adoption}" % params
    else
      # if year and month - edition and draft before
      "%{publisher}%{draft_status}%{type}%{number}%{part}%{subpart}%{edition}%{stage}"\
      "%{corrigendum_comment}%{corrigendum}%{draft}%{month}%{day}%{year}%{alternative}%{supersedes}%{reaffirmed}%{incorporates}%{supplement}"\
      "%{revision}%{iso_amendment}%{amendment}%{includes}%{redline}%{adoption}" % params
    end
  end
end

#render_includes(includes, _opts, _params) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/pubid/ieee/renderer/base.rb', line 78

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



186
187
188
# File 'lib/pubid/ieee/renderer/base.rb', line 186

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

#render_iso_amendment(iso_amendment, _opts, _params) ⇒ Object



204
205
206
207
# File 'lib/pubid/ieee/renderer/base.rb', line 204

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



53
54
55
56
57
# File 'lib/pubid/ieee/renderer/base.rb', line 53

def render_month(month, _opts, params)
  # return if params[:day]

  ", #{Date::MONTHNAMES[month]}"
end

#render_number(number, _opts, _params) ⇒ Object



23
24
25
# File 'lib/pubid/ieee/renderer/base.rb', line 23

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

#render_part(part, _opts, _params) ⇒ Object



43
44
45
# File 'lib/pubid/ieee/renderer/base.rb', line 43

def render_part(part, _opts, _params)
  (part =~ /^[-.]/ ? "" : "-") + part
end

#render_publisher(publisher, opts, params) ⇒ Object



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

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



180
181
182
183
184
# File 'lib/pubid/ieee/renderer/base.rb', line 180

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



142
143
144
# File 'lib/pubid/ieee/renderer/base.rb', line 142

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

#render_revision(revision, _opts, _params) ⇒ Object



138
139
140
# File 'lib/pubid/ieee/renderer/base.rb', line 138

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

#render_stage(stage, _opts, _params) ⇒ Object



213
214
215
# File 'lib/pubid/ieee/renderer/base.rb', line 213

def render_stage(stage, _opts, _params)
  "/#{stage}"
end

#render_supersedes(supersedes, _opts, _params) ⇒ Object



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

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



190
191
192
# File 'lib/pubid/ieee/renderer/base.rb', line 190

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

#render_type(type, opts, params) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/pubid/ieee/renderer/base.rb', line 32

def render_type(type, opts, params)
  result = if params[:publisher] == "IEEE" ||
             (params[:copublisher].is_a?(Array) && params[:copublisher].include?("IEEE") || params[:copublisher] == "IEEE")
             type.to_s(opts[:format])
           else
             type.to_s(:alternative)
           end

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

#render_year(year, _opts, params) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/pubid/ieee/renderer/base.rb', line 63

def render_year(year, _opts, params)
  # return if params[:day]

  # add comma when day appears before year
  return (params[:day] ? "," : "") + " #{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