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

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

Constant Summary collapse

TRANSLATION =
{
  russian: {
    publisher: { "ISO" => "ИСО", "IEC" => "МЭК" },
    stage: { "FDIS" => "ОПМС",
             "DIS" => "ПМС",
             "NP" => "НП",
             "AWI" => "АВИ",
             "CD" => "КПК",
             "PD" => "ПД",
             "FPD" => "ФПД" },
    type: { "TS" => "ТС",
            "TR" => "ТО",
            "ISP" => "ИСП" },
  },
  french: {
    publisher: { "IEC" => "CEI" },
  },
}.freeze
TYPE =
"".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#prerendered_paramsObject

Returns the value of attribute prerendered_params.



3
4
5
# File 'lib/pubid/iso/renderer/base.rb', line 3

def prerendered_params
  @prerendered_params
end

Instance Method Details

#omit_post_publisher_symbol?(typed_stage, stage, opts) ⇒ Boolean

Returns:

  • (Boolean)


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

def omit_post_publisher_symbol?(typed_stage, stage, opts)
  # return false unless typed_stage

  (stage.nil? || stage.empty_abbr?(with_prf: opts[:with_prf])) && typed_stage.nil?
end

#postrender_stage(stage, opts, params) ⇒ Object



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

def postrender_stage(stage, opts, params)
  return if stage.empty_abbr?(with_prf: opts[:with_prf])

  if opts[:language]
    return TRANSLATION[opts[:language]][:stage][stage.to_s(with_prf: opts[:with_prf])] ||
      stage.to_s(with_prf: opts[:with_prf])
  end

  stage.to_s(with_prf: opts[:with_prf])
end

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

Render identifier

Parameters:

  • with_edition (Boolean) (defaults to: true)

    include edition in output

See Also:

  • for another options


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

def render(with_edition: true, with_language_code: :iso, with_date: true, **args)
  render_base_identifier(**args.merge({ with_date: with_date,
                                        with_language_code: with_language_code,
                                        with_edition: with_edition })) +
    @prerendered_params[:language].to_s
end

#render_addendum(addendum, _opts, _params) ⇒ Object



166
167
168
169
170
171
172
# File 'lib/pubid/iso/renderer/base.rb', line 166

def render_addendum(addendum, _opts, _params)
  if addendum[:year]
    "/Add #{addendum[:number]}:#{addendum[:year]}"
  else
    "/Add #{addendum[:number]}"
  end
end

#render_base(_base, _opts, _params) ⇒ Object



42
43
# File 'lib/pubid/iso/renderer/base.rb', line 42

def render_base(_base, _opts, _params)
end

#render_base_identifier(**args) ⇒ Object



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

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

  render_identifier(@prerendered_params, args)
end

#render_copublisher_string(publisher, copublishers, opts) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/pubid/iso/renderer/base.rb', line 60

def render_copublisher_string(publisher, copublishers, opts)
  case copublishers
  when String
    if opts[:language]
      copublishers = TRANSLATION[opts[:language]][:publisher][copublishers] || copublishers
    end
    [publisher, copublishers].join("/")
  when Array
    ([publisher] + copublishers.map(&:to_s)).map do |pub|
      if opts[:language]
        (TRANSLATION[opts[:language]][:publisher][pub] || pub).gsub('-', '/')
      else
        pub
      end
    end.join("/")
  else
    raise StandardError.new("copublisher must be a string or an array")
  end
end

#render_edition(edition, opts, _params) ⇒ Object



144
145
146
# File 'lib/pubid/iso/renderer/base.rb', line 144

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

#render_identifier(params, opts) ⇒ Object



55
56
57
58
# File 'lib/pubid/iso/renderer/base.rb', line 55

def render_identifier(params, opts)
  stage = params.key?(:stage) ? postrender_stage(params[:stage], opts, params) : ""
  "%{publisher}#{stage}#{render_type_prefix(params, opts)} %{number}%{part}%{iteration}%{year}%{amendments}%{corrigendums}%{addendum}%{edition}" % params
end

#render_iteration(iteration, _opts, _params) ⇒ Object



148
149
150
# File 'lib/pubid/iso/renderer/base.rb', line 148

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

#render_language(language, opts, _params) ⇒ Object



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

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

#render_part(part, opts, _params) ⇒ Object



162
163
164
# File 'lib/pubid/iso/renderer/base.rb', line 162

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

#render_publisher(publisher, 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
109
110
111
112
113
114
115
116
117
# File 'lib/pubid/iso/renderer/base.rb', line 86

def render_publisher(publisher, opts, params)

  if opts[:language]
    publisher = TRANSLATION[opts[:language]][:publisher][publisher] || publisher
  end
  # No copublishers
  unless params[:copublisher]

    # No copublisher and IS
    # ISO xxx
    if omit_post_publisher_symbol?(params[:typed_stage], params[:stage], opts)
      return publisher
    end

    # No copublisher and not IS
    # ISO/TR xxx
    return "#{publisher}/"
  end

  publisher_string = render_copublisher_string(publisher, params[:copublisher], opts)
  publisher_string.sub!("/IEC", "/CEI") if opts[:language] == :french

  # With copublisher and IS
  # ISO/IEC xxx
  if omit_post_publisher_symbol?(params[:typed_stage], params[:stage], opts)
    return publisher_string
  end

  # With copublisher but not IS
  # ISO/IEC TR xxx
  publisher_string + " "
end

#render_stage(stage, _opts, _params) ⇒ Object



129
130
131
# File 'lib/pubid/iso/renderer/base.rb', line 129

def render_stage(stage, _opts, _params)
  stage
end

#render_type_prefix(params, opts) ⇒ Object



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

def render_type_prefix(params, opts)
  result = params[:stage].nil? || !params[:stage].is_a?(Pubid::Core::TypedStage) ? self.class::TYPE : ""

  if params[:stage] != "" && !params[:stage].to_s(with_prf: opts[:with_prf]).empty? && !result.empty?
    " #{result}"
  else
    result
  end
end

#render_typed_stage(typed_stage, opts, params) ⇒ Object



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

def render_typed_stage(typed_stage, opts, params)
  return nil if typed_stage.to_s.empty?

  if opts[:language]
    return TRANSLATION[opts[:language]][:stage][typed_stage.to_s] || typed_stage.to_s
  end

  typed_stage.to_s
end

#render_year(year, opts, params) ⇒ Object



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

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