Class: MercosurPlateConverter::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/mercosur_plate_converter/converter.rb

Overview

MercosurPlateConverter::Converter.new(“ABC1C34”) where “ABC1C34” is the vehicle’s plate.

Constant Summary collapse

FIFTH_TERM_MAP =
("A".."J").to_a.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plate) ⇒ Converter

Returns a new instance of Converter.



10
11
12
13
14
15
16
17
18
# File 'lib/mercosur_plate_converter/converter.rb', line 10

def initialize(plate)
  @original_plate = sanitize_plate(plate)
  @plate = @original_plate.dup
  @type = nil

  validate_plate
  detect_type
  convert
end

Instance Attribute Details

#original_plateObject (readonly)

Returns the value of attribute original_plate.



8
9
10
# File 'lib/mercosur_plate_converter/converter.rb', line 8

def original_plate
  @original_plate
end

#plateObject (readonly)

Returns the value of attribute plate.



8
9
10
# File 'lib/mercosur_plate_converter/converter.rb', line 8

def plate
  @plate
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/mercosur_plate_converter/converter.rb', line 8

def type
  @type
end

Instance Method Details

#convertObject



20
21
22
# File 'lib/mercosur_plate_converter/converter.rb', line 20

def convert
  send("convert_from_#{type}")
end

#mercosur?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/mercosur_plate_converter/converter.rb', line 28

def mercosur?
  @original_plate.match?(/^(BR\s?)?[A-Z]{3}[0-9]{1}[A-Z]{1}[0-9]{2}$/)
end

#old_brazilian?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/mercosur_plate_converter/converter.rb', line 32

def old_brazilian?
  @original_plate.match?(/^[A-Z]{3}[0-9]{4}$/)
end

#valid?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/mercosur_plate_converter/converter.rb', line 24

def valid?
  mercosur? || old_brazilian?
end