Class: Pubid::Itu::Renderer::Base

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

Direct Known Subclasses

Contribution, ImplementersGuide

Constant Summary collapse

TYPE_PREFIX =
"".freeze

Instance Method Summary collapse

Instance Method Details

#render(**args) ⇒ Object



5
6
7
# File 'lib/pubid/itu/renderer/base.rb', line 5

def render(**args)
  render_base_identifier(**args) + @prerendered_params[:language].to_s
end

#render_addendum(addendum, opts, params) ⇒ Object



115
116
117
# File 'lib/pubid/itu/renderer/base.rb', line 115

def render_addendum(addendum, opts, params)
  "#{render_date(addendum[:date], opts, params)} Add. #{addendum[:number]}"
end

#render_amendment(amendment, _opts, _params) ⇒ Object



79
80
81
# File 'lib/pubid/itu/renderer/base.rb', line 79

def render_amendment(amendment, _opts, _params)
  " Amd #{amendment[:number]}"
end

#render_annex(annex, _opts, _params) ⇒ Object



103
104
105
# File 'lib/pubid/itu/renderer/base.rb', line 103

def render_annex(annex, _opts, _params)
  " Annex #{annex[:number]}" if annex[:number]
end

#render_appendix(appendix, _opts, _params) ⇒ Object



119
120
121
# File 'lib/pubid/itu/renderer/base.rb', line 119

def render_appendix(appendix, _opts, _params)
  " App. #{appendix[:number]}"
end

#render_base_identifier(**args) ⇒ Object



13
14
15
16
17
18
# File 'lib/pubid/itu/renderer/base.rb', line 13

def render_base_identifier(**args)
  prerender(**args)

  # pass args to render_identifier
  render_identifier(@prerendered_params, args)
end

#render_corrigendum(corrigendum, opts, params) ⇒ Object



107
108
109
# File 'lib/pubid/itu/renderer/base.rb', line 107

def render_corrigendum(corrigendum, opts, params)
  "#{render_date(corrigendum[:date], opts, params)} Cor. #{corrigendum[:number]}"
end

#render_date(date, opts, _params) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/pubid/itu/renderer/base.rb', line 57

def render_date(date, opts, _params)
  return if opts[:without_date]

  return " (#{date[:year]})" unless date[:month]

  " (%<month>02d/%<year>d)" % date
end

#render_identifier(params, opts) ⇒ Object

can prepend entity, can postpend, can use item holder



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pubid/itu/renderer/base.rb', line 22

def render_identifier(params, opts)
  postfix = prefix = ""
  if @params[:annex] && @params[:annex][:number].nil?
    prefix += "Annex to "
  elsif opts[:language] &&
      (type_translation = Pubid::Itu::I18N["type"][@params[:type]]&.fetch(opts[:language].to_s, nil))
    if opts[:language] == :cn
      postfix =+ type_translation
    elsif opts[:language] == :ar
      postfix += " #{type_translation}"
    else
      prefix += "#{type_translation} "
    end
  end

  "#{prefix}%{publisher}-%{sector} #{render_type_series(params)}%{number}%{subseries}"\
  "%{part}%{second_number}%{range}%{annex}%{amendment}%{corrigendum}%{supplement}"\
  "%{addendum}%{appendix}%{date}#{postfix}" % params
end

#render_language(language, _opts, _params) ⇒ Object



123
124
125
# File 'lib/pubid/itu/renderer/base.rb', line 123

def render_language(language, _opts, _params)
  "-#{LANGUAGES[language]}"
end

#render_number(number, _opts, params) ⇒ Object



51
52
53
54
55
# File 'lib/pubid/itu/renderer/base.rb', line 51

def render_number(number, _opts, params)
  return " No. #{number}" if params[:series] == "OB"

  number
end

#render_part(part, opts, _params) ⇒ Object



69
70
71
72
73
# File 'lib/pubid/itu/renderer/base.rb', line 69

def render_part(part, opts, _params)
  return "-#{part.reverse.join('-')}" if part.is_a?(Array)

  "-#{part}"
end

#render_publisher(publisher, opts, params) ⇒ Object



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

def render_publisher(publisher, opts, params)
  if opts[:language] &&
      (publisher_translation = Pubid::Itu::I18N["publisher"][publisher]&.fetch(opts[:language].to_s, nil))
    return super(publisher_translation, opts, params)
  end

  super
end

#render_range(range, _opts, params) ⇒ Object



111
112
113
# File 'lib/pubid/itu/renderer/base.rb', line 111

def render_range(range, _opts, params)
  "-#{params[:series]}.#{range[:number]}"
end

#render_second_number(second_number, _opts, _params) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/pubid/itu/renderer/base.rb', line 87

def render_second_number(second_number, _opts, _params)
  result = "/#{second_number[:series]}.#{second_number[:number]}"
  if second_number[:subseries]
    result += ".#{second_number[:subseries]}"
  end
  if second_number[:part]
    result += "-#{second_number[:part]}"
  end

  result
end

#render_series(series, _opts, params) ⇒ Object



75
76
77
# File 'lib/pubid/itu/renderer/base.rb', line 75

def render_series(series, _opts, params)
  series + (params[:series] != "OB" && params[:number] ? "." : "")
end

#render_subseries(subseries, _opts, _params) ⇒ Object



83
84
85
# File 'lib/pubid/itu/renderer/base.rb', line 83

def render_subseries(subseries, _opts, _params)
  ".#{subseries}"
end

#render_supplement(supplement, _opts, _params) ⇒ Object



99
100
101
# File 'lib/pubid/itu/renderer/base.rb', line 99

def render_supplement(supplement, _opts, _params)
  " Suppl. #{supplement[:number]}"
end

#render_type(type, opts, _params) ⇒ Object



65
66
67
# File 'lib/pubid/itu/renderer/base.rb', line 65

def render_type(type, opts, _params)
  "#{type}-" if opts[:with_type]
end

#render_type_series(params) ⇒ Object



9
10
11
# File 'lib/pubid/itu/renderer/base.rb', line 9

def render_type_series(params)
  "%{type}%{series}" % params
end