Class: MercosurPlateConverter::Converter
- Inherits:
-
Object
- Object
- MercosurPlateConverter::Converter
- 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
-
#original_plate ⇒ Object
readonly
Returns the value of attribute original_plate.
-
#plate ⇒ Object
readonly
Returns the value of attribute plate.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(plate) ⇒ Converter
constructor
A new instance of Converter.
- #mercosur? ⇒ Boolean
- #old_brazilian? ⇒ Boolean
- #valid? ⇒ Boolean
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_plate ⇒ Object (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 |
#plate ⇒ Object (readonly)
Returns the value of attribute plate.
8 9 10 |
# File 'lib/mercosur_plate_converter/converter.rb', line 8 def plate @plate end |
#type ⇒ Object (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
#convert ⇒ Object
20 21 22 |
# File 'lib/mercosur_plate_converter/converter.rb', line 20 def convert send("convert_from_#{type}") end |
#mercosur? ⇒ 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
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
24 25 26 |
# File 'lib/mercosur_plate_converter/converter.rb', line 24 def valid? mercosur? || old_brazilian? end |