Class: Pubid::Iso::Transformer

Inherits:
Parslet::Transform
  • Object
show all
Defined in:
lib/pubid/iso/transformer.rb

Constant Summary collapse

ROMAN_TO_INT =
{
  "I" => 1,
  "V" => 5,
  "X" => 10,
  "L" => 50,
  "C" => 100,
  "D" => 500,
  "M" => 1000,
}

Class Method Summary collapse

Class Method Details

.convert_language(code) ⇒ Object



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

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

.convert_stage(code) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/pubid/iso/transformer.rb', line 141

def self.convert_stage(code)
  russian_code = Pubid::Iso::Renderer::Base::TRANSLATION[:russian][:stage].key(code.to_s)
  return { stage: russian_code } if russian_code

  case code
  when "NWIP"
    { stage: "NP" }
  when "D", "FPD"
    { stage: "DIS" }
  when "FD", "F"
    { stage: "FDIS" }
  when "Fpr"
    { stage: "PRF" }
  when "PDTR"
    { stage: "CD", type: "TR" }
  when "PDTS"
    { stage: "CD", type: "TS" }
  else
    { stage: code }
  end
end

.roman_to_int(roman) ⇒ Object



132
133
134
135
136
137
138
139
# File 'lib/pubid/iso/transformer.rb', line 132

def self.roman_to_int(roman)
  sum = ROMAN_TO_INT[roman.to_s[0]]
  roman.to_s.chars.each_cons(2) do |c1, c2|
    sum += ROMAN_TO_INT[c2]
    sum -= ROMAN_TO_INT[c1] * 2 if ROMAN_TO_INT[c1] < ROMAN_TO_INT[c2]
  end
  sum
end