AutoCat/AutoCat/Models/PlateNumber.swift

30 lines
766 B
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Foundation
class PlateNumber {
private static let lettersMap: [Character: Character] = [
"А": "A", "В": "B", "Е": "E", "К": "K", "М": "M", "Н": "H", "О": "O", "Р": "P", "С": "C", "Т": "T", "У": "Y", "Х": "X"
]
private var number: String
private var numberEnglish: String
init(_ string: String) {
self.number = string
self.numberEnglish = String(self.number.map { PlateNumber.lettersMap[$0] ?? $0 })
}
func asString() -> String {
return self.number
}
func mainPart() -> String {
let index = self.numberEnglish.startIndex(offsetBy: 6)
return String(self.numberEnglish[..<index])
}
func region() -> String {
let index = self.numberEnglish.startIndex(offsetBy: 6)
return String(self.numberEnglish[index...])
}
}