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



112
113
114
115
# File 'lib/pubid/iso/transformer.rb', line 112

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

.convert_language(code) ⇒ Object



165
166
167
168
169
170
171
172
173
# File 'lib/pubid/iso/transformer.rb', line 165

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



107
108
109
110
# File 'lib/pubid/iso/transformer.rb', line 107

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



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/pubid/iso/transformer.rb', line 124

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 { stage: convert_stage_code(code.to_s) }
  end
end

.convert_stage_code(code) ⇒ Object



157
158
159
160
161
162
163
# File 'lib/pubid/iso/transformer.rb', line 157

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



194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/pubid/iso/transformer.rb', line 194

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



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

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



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

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



142
143
144
145
146
147
# File 'lib/pubid/iso/transformer.rb', line 142

def self.convert_urn_sup_stage_code(sup)
  stage_type = convert_urn_sup_type(sup[:type])
  abbr = convert_stage_code(sup[:typed_stage])
  stage_type[:typed_stage] = abbr if abbr
  stage_type
end

.convert_urn_sup_type(type) ⇒ Object



149
150
151
152
153
154
155
# File 'lib/pubid/iso/transformer.rb', line 149

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