Class: Pubid::Iso::Transformer

Inherits:
Core::Transformer
  • Object
show all
Defined in:
lib/pubid/iso/transformer.rb

Class Method Summary collapse

Class Method Details

.convert_copublisher(copublisher) ⇒ Object



123
124
125
126
# File 'lib/pubid/iso/transformer.rb', line 123

def self.convert_copublisher(copublisher)
  copblsh = convert_publisher copublisher
  Pubid::Iso::Renderer::Base::TRANSLATION[:french][:publisher].key(copblsh) || copblsh
end

.convert_language(code) ⇒ Object



185
186
187
188
189
190
191
192
193
# File 'lib/pubid/iso/transformer.rb', line 185

def self.convert_language(code)
  case code
  when "R" then "ru"
  when "F" then "fr"
  when "E" then "en"
  when "A" then "ar"
  else code
  end
end

.convert_publisher(publisher) ⇒ Object



118
119
120
121
# File 'lib/pubid/iso/transformer.rb', line 118

def self.convert_publisher(publisher)
  pblsh = publisher.to_s.upcase
  Pubid::Iso::Renderer::Base::TRANSLATION[:russian][:publisher].key(pblsh) || pblsh
end

.convert_stage(code) ⇒ Hash

Convert ISO stage to Russian and other formats if needed

Parameters:

  • code (String)

    ISO stage code

Returns:

  • (Hash)

    a hash with keys :stage and optionally :type



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/pubid/iso/transformer.rb', line 135

def self.convert_stage(code) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
  russian_code = Pubid::Iso::Renderer::Base::TRANSLATION[:russian][:stage].key(code.to_s)
  return { stage: russian_code } if russian_code

  case code
  when "NWIP" then { stage: "NP" }
  when "D", "FPD" then { stage: "DIS" }
  when "FD", "F" then { stage: "FDIS" }
  when "Fpr" then { stage: "PRF" }
  when "PDTR" then { stage: "CD", type: "TR" }
  when "PDTS" then { stage: "CD", type: "TS" }
  when "preCD" then { stage: "PreCD" }
  when "published" then { stage: "IS" }
  # when "draft" then { stage: "WD" }
  else
    if /\A[\d.]+\z/.match?(code.to_s)
      { stage: code.to_s }
    else
      { stage: convert_stage_code(code.to_s) }
    end
  end
end

.convert_stage_code(code) ⇒ Object



177
178
179
180
181
182
183
# File 'lib/pubid/iso/transformer.rb', line 177

def self.convert_stage_code(code)
  Identifier::InternationalStandard::TYPED_STAGES.each_value do |v|
    return v[:abbr] if v[:harmonized_stages].include?(code)
  end

  code
end

.convert_type(type) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength



214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/pubid/iso/transformer.rb', line 214

def self.convert_type(type) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
  case type
  # XXX: can't put 2 alternative Russian translations to dictionary, temporary hack
  when "GUIDE", "Guide", "Руководство" then :guide
  when "ТС", "TS" then :ts
  when "ТО", "TR" then :tr
  when "Directives Part", "Directives, Part", "Directives,", "DIR" then :dir
  when "PAS" then :pas
  when "DPAS" then :dpas
  when "R" then :r
  else type
  end
end

.convert_urn_stage(type) ⇒ Object



203
204
205
206
207
208
209
210
211
212
# File 'lib/pubid/iso/transformer.rb', line 203

def self.convert_urn_stage(type)
  case type
  when "tr" then "DTR"
  when "ts" then "DTS"
  when "iwa" then "DIWA"
  when "pas" then "DPAS"
  when "guide" then "DGuide"
  else "D"
  end
end

.convert_urn_sup_draft_type(type) ⇒ Object



195
196
197
198
199
200
201
# File 'lib/pubid/iso/transformer.rb', line 195

def self.convert_urn_sup_draft_type(type)
  if type == "sup"
    { typed_stage: "DSuppl", type: "Suppl" }
  else
    { typed_stage: "WD" }
  end
end

.convert_urn_sup_stage_code(sup) ⇒ Object



158
159
160
161
162
163
164
165
166
167
# File 'lib/pubid/iso/transformer.rb', line 158

def self.convert_urn_sup_stage_code(sup)
  stage_type = convert_urn_sup_type(sup[:type])
  if /\A[\d.]+\z/.match?(sup[:typed_stage].to_s)
    stage_type[:typed_stage] = sup[:typed_stage].to_s
  else
    abbr = convert_stage_code(sup[:typed_stage])
    stage_type[:typed_stage] = abbr if abbr
  end
  stage_type
end

.convert_urn_sup_type(type) ⇒ Object



169
170
171
172
173
174
175
# File 'lib/pubid/iso/transformer.rb', line 169

def self.convert_urn_sup_type(type)
  case type
  when "sup" then { type: "Suppl" }
  when String, Parslet::Slice then { type: type.to_s }
  else {}
  end
end