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
Data, 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
-
#postrender_stage(stage, opts, _params) ⇒ Object
-
#render(with_edition: true, with_language_code: :iso, with_date: true, annotated: false, **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
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity.
-
#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
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength.
-
#render_stage(stage, _opts, _params) ⇒ Object
-
#render_type_prefix(params, opts) ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#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
86
87
88
89
90
|
# File 'lib/pubid/iso/renderer/base.rb', line 86
def omit_post_publisher_symbol?(typed_stage, stage, opts)
(stage.nil? || stage.empty_abbr?(with_prf: opts[:with_prf])) && typed_stage.nil?
end
|
#postrender_stage(stage, opts, _params) ⇒ Object
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/pubid/iso/renderer/base.rb', line 138
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, annotated: false, **args) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/pubid/iso/renderer/base.rb', line 35
def render(with_edition: true, with_language_code: :iso, with_date: true, annotated: false, **args)
render_base_identifier(**args.merge({ with_date: with_date,
with_language_code: with_language_code,
with_edition: with_edition,
annotated: annotated })) +
@prerendered_params[:language].to_s
end
|
#render_addendum(addendum, _opts, _params) ⇒ Object
173
174
175
176
177
178
179
|
# File 'lib/pubid/iso/renderer/base.rb', line 173
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
43
|
# File 'lib/pubid/iso/renderer/base.rb', line 43
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
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/pubid/iso/renderer/base.rb', line 66
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
149
150
151
|
# File 'lib/pubid/iso/renderer/base.rb', line 149
def render_edition(edition, opts, _params)
" ED#{edition}" if opts[:with_edition]
end
|
#render_identifier(params, opts) ⇒ Object
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/pubid/iso/renderer/base.rb', line 55
def render_identifier(params, opts)
stage = params.key?(:stage) ? postrender_stage(params[:stage], opts, params) : ""
type = render_type_prefix(params, opts)
if opts[:annotated]
stage = annotate_value(:stage, stage) if stage && !stage.to_s.empty?
type = annotate_value(:typed_stage, type) if type && !type.to_s.empty?
end
"%<publisher>s#{stage}#{type} %<number>s%<part>s%<iteration>s%<year>s%" \
"<amendments>s%<corrigendums>s%<addendum>s%<edition>s" % params
end
|
#render_iteration(iteration, _opts, _params) ⇒ Object
153
154
155
|
# File 'lib/pubid/iso/renderer/base.rb', line 153
def render_iteration(iteration, _opts, _params)
".#{iteration}"
end
|
#render_language(language, opts, _params) ⇒ Object
157
158
159
160
161
|
# File 'lib/pubid/iso/renderer/base.rb', line 157
def render_language(language, opts, _params)
return if opts[:with_language_code] == :none
super
end
|
#render_part(part, _opts, _params) ⇒ Object
169
170
171
|
# File 'lib/pubid/iso/renderer/base.rb', line 169
def render_part(part, _opts, _params)
"-#{part}"
end
|
#render_publisher(publisher, opts, params) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
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
118
119
120
121
122
|
# File 'lib/pubid/iso/renderer/base.rb', line 92
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
134
135
136
|
# File 'lib/pubid/iso/renderer/base.rb', line 134
def render_stage(stage, _opts, _params)
stage
end
|
#render_type_prefix(params, opts) ⇒ Object
rubocop:disable Metrics/AbcSize
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
124
125
126
127
128
129
130
131
132
|
# File 'lib/pubid/iso/renderer/base.rb', line 124
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
163
164
165
166
167
|
# File 'lib/pubid/iso/renderer/base.rb', line 163
def render_year(year, opts, params)
return ":#{year}" if params[:amendments] || params[:corrigendums]
opts[:with_date] && ":#{year}" || ""
end
|