Class: Pubid::Iso::Renderer::Base
- Inherits:
-
Core::Renderer::Base
- Object
- Core::Renderer::Base
- Pubid::Iso::Renderer::Base
show all
- Defined in:
- lib/pubid/iso/renderer/base.rb
Direct Known Subclasses
Dir, Guide, InternationalStandard, InternationalStandardizedProfile, InternationalWorkshopAgreement, PubliclyAvailableSpecification, Recommendation, Supplement, TechnicalCommittee, TechnicalReport, TechnicalSpecification, TechnologyTrendsAssessments
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
-
#omit_post_publisher_symbol?(typed_stage, stage, opts) ⇒ Boolean
-
#render(with_edition: true, with_language_code: :iso, with_date: true, **args) ⇒ Object
-
#render_addendum(addendum, _opts, _params) ⇒ Object
-
#render_base(_base, _opts, _params) ⇒ Object
-
#render_base_identifier(**args) ⇒ Object
-
#render_copublisher_string(publisher, copublishers, opts) ⇒ Object
-
#render_edition(edition, opts, _params) ⇒ Object
-
#render_identifier(params, opts) ⇒ Object
-
#render_iteration(iteration, _opts, _params) ⇒ Object
-
#render_language(language, opts, _params) ⇒ Object
-
#render_part(part, opts, _params) ⇒ Object
-
#render_publisher(publisher, opts, params) ⇒ Object
-
#render_stage(stage, opts, params) ⇒ Object
-
#render_type_prefix(params) ⇒ Object
-
#render_typed_stage(typed_stage, opts, params) ⇒ Object
-
#render_year(year, opts, params) ⇒ Object
Instance Attribute Details
#prerendered_params ⇒ Object
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
79
80
81
82
83
|
# File 'lib/pubid/iso/renderer/base.rb', line 79
def omit_post_publisher_symbol?(typed_stage, stage, opts)
(stage.nil? || stage.empty_abbr?(with_prf: opts[:with_prf])) && typed_stage.nil?
end
|
#render(with_edition: true, with_language_code: :iso, with_date: true, **args) ⇒ Object
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
164
165
166
167
168
169
170
|
# File 'lib/pubid/iso/renderer/base.rb', line 164
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/pubid/iso/renderer/base.rb', line 59
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).sort).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
140
141
142
|
# File 'lib/pubid/iso/renderer/base.rb', line 140
def render_edition(edition, opts, _params)
" ED#{edition}" if opts[:with_edition]
end
|
#render_identifier(params, opts) ⇒ Object
55
56
57
|
# File 'lib/pubid/iso/renderer/base.rb', line 55
def render_identifier(params, opts)
"%{publisher}%{typed_stage}%{stage}#{render_type_prefix(params)} %{number}%{part}%{iteration}%{year}%{amendments}%{corrigendums}%{addendum}%{edition}" % params
end
|
#render_iteration(iteration, _opts, _params) ⇒ Object
144
145
146
|
# File 'lib/pubid/iso/renderer/base.rb', line 144
def render_iteration(iteration, _opts, _params)
".#{iteration}"
end
|
#render_language(language, opts, _params) ⇒ Object
148
149
150
151
|
# File 'lib/pubid/iso/renderer/base.rb', line 148
def render_language(language, opts, _params)
return if opts[:with_language_code] == :none
super
end
|
#render_part(part, opts, _params) ⇒ Object
158
159
160
161
162
|
# File 'lib/pubid/iso/renderer/base.rb', line 158
def render_part(part, opts, _params)
return "-#{part.reverse.join('-')}" if part.is_a?(Array)
"-#{part}"
end
|
#render_publisher(publisher, opts, params) ⇒ Object
85
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
|
# File 'lib/pubid/iso/renderer/base.rb', line 85
def render_publisher(publisher, opts, params)
if opts[:language]
publisher = TRANSLATION[opts[:language]][:publisher][publisher] || publisher
end
unless params[:copublisher]
if omit_post_publisher_symbol?(params[:typed_stage], params[:stage], opts)
return publisher
end
return "#{publisher}/"
end
publisher_string = render_copublisher_string(publisher, params[:copublisher], opts)
publisher_string.sub!("/IEC", "/CEI") if opts[:language] == :french
if omit_post_publisher_symbol?(params[:typed_stage], params[:stage], opts)
return publisher_string
end
publisher_string + " "
end
|
#render_stage(stage, opts, params) ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/pubid/iso/renderer/base.rb', line 128
def render_stage(stage, opts, params)
return if params[:typed_stage]
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_type_prefix(params) ⇒ Object
45
46
47
48
49
50
51
52
53
|
# File 'lib/pubid/iso/renderer/base.rb', line 45
def render_type_prefix(params)
result = params[:typed_stage].nil? || params[:typed_stage].empty? ? self.class::TYPE : ""
if params[:stage] && !params[:stage].empty? && !result.empty?
" #{result}"
else
result
end
end
|
#render_typed_stage(typed_stage, opts, params) ⇒ Object
118
119
120
121
122
123
124
125
126
|
# File 'lib/pubid/iso/renderer/base.rb', line 118
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
153
154
155
156
|
# File 'lib/pubid/iso/renderer/base.rb', line 153
def render_year(year, opts, params)
return ":#{year}" if params[:amendments] || params[:corrigendums]
opts[:with_date] && ":#{year}" || ""
end
|