Class: Pubid::Iso::Renderer::Base

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

Direct Known Subclasses

Dir, French, Russian, Tc

Instance Method Summary collapse

Instance Method Details

#render(with_edition: true, **args) ⇒ Object

Render identifier

See Also:

  • for another options


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

def render(with_edition: true, **args)
  params = prerender_params(@params,
                            { with_edition: with_edition }.merge(args))
  # render empty string when the key is not exist
  params.default = ""

  render_identifier(params)
end

#render_amendments(amendments, opts, _params) ⇒ Object



68
69
70
# File 'lib/pubid/iso/renderer/base.rb', line 68

def render_amendments(amendments, opts, _params)
  amendments.sort.map { |amendment| amendment.render_pubid(opts[:stage_format_long], opts[:with_date]) }.join("+")
end

#render_corrigendums(corrigendums, opts, _params) ⇒ Object



72
73
74
# File 'lib/pubid/iso/renderer/base.rb', line 72

def render_corrigendums(corrigendums, opts, _params)
  corrigendums.sort.map { |corrigendum| corrigendum.render_pubid(opts[:stage_format_long], opts[:with_date]) }.join("+")
end

#render_edition(edition, opts, _params) ⇒ Object



60
61
62
# File 'lib/pubid/iso/renderer/base.rb', line 60

def render_edition(edition, opts, _params)
  " ED#{edition}" if opts[:with_edition]
end

#render_identifier(params) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pubid/iso/renderer/base.rb', line 15

def render_identifier(params)
  if @params[:type] && @params[:stage]
    if %w(DIS FDIS).include?(@params[:stage].abbr)
      render_base(params, "#{render_short_stage(@params[:stage].abbr)}#{@params[:type]}")
    else
      if params[:copublisher] && !params[:copublisher].empty?
        render_base(params, "%{type}%{stage}" % params)
      else
        render_base(params, "%{stage}%{type}" % params)
      end
    end
  else
    render_base(params, "%{type}%{stage}" % params)
  end +
    "%{part}%{iteration}%{year}%{amendments}%{corrigendums}%{edition}%{language}" % params
end

#render_iteration(iteration, _opts, _params) ⇒ Object



64
65
66
# File 'lib/pubid/iso/renderer/base.rb', line 64

def render_iteration(iteration, _opts, _params)
  ".#{iteration}"
end

#render_language(language, opts, _params) ⇒ Object



76
77
78
79
# File 'lib/pubid/iso/renderer/base.rb', line 76

def render_language(language, opts, _params)
  return if opts[:with_language_code] == :none
  super
end

#render_short_stage(stage) ⇒ Object



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

def render_short_stage(stage)
  (params[:copublisher] ? " " : "/") +
    case stage
    when "DIS"
      "D"
    when "FDIS"
      "FD"
    end
end

#render_stage(stage, opts, params) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/pubid/iso/renderer/base.rb', line 50

def render_stage(stage, opts, params)
  return if (stage.abbr == "PRF" and !opts[:with_prf]) || stage.abbr == "IS"

  if params[:copublisher]
    " #{stage.abbr}"
  else
    "/#{stage.abbr}"
  end
end

#render_type(type, opts, params) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/pubid/iso/renderer/base.rb', line 42

def render_type(type, opts, params)
  if params[:copublisher] || (params[:stage] && params[:stage].abbr != "IS")
    " #{type}"
  else
    "/#{type}"
  end
end

#render_year(year, opts, params) ⇒ Object



81
82
83
84
# File 'lib/pubid/iso/renderer/base.rb', line 81

def render_year(year, opts, params)
  return ":#{year}" if params[:amendments] || params[:corrigendums]
  opts[:with_date] && ":#{year}" || ""
end