From e5d1a8ecc38fed7b023b3e02550fc208025a6bdc Mon Sep 17 00:00:00 2001 From: Benjamin Curtis Date: Tue, 3 Jan 2017 01:57:46 -0800 Subject: [PATCH] Tidied up Faker::Vehicle with fixes for Rails Closes #627, #644, and #705 --- lib/faker/vehicle.rb | 24 +++--- lib/locales/en.yml | 188 +++++++++++-------------------------------- 2 files changed, 59 insertions(+), 153 deletions(-) diff --git a/lib/faker/vehicle.rb b/lib/faker/vehicle.rb index abe9c82c17..85b77fa2b8 100644 --- a/lib/faker/vehicle.rb +++ b/lib/faker/vehicle.rb @@ -1,17 +1,17 @@ module Faker class Vehicle < Base - @vin_chars = '0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ' - @vin_map = '0123456789X' - @vin_weights = '8765432X098765432' + VIN_CHARS = '0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ' + VIN_MAP = '0123456789X' + VIN_WEIGHTS = '8765432X098765432' class << self #ISO 3779 def vin - manufacture = fetch_all('vehicle.manufacture').sample + _, wmi, wmi_ext = fetch_all('vehicle.manufacture').sample - c = @vin_chars.split('').reject{ |n| n == '.'} - vehicle_identification_number = manufacture["wmi"].split('').concat( Array.new(14) { c.sample } ) - (12..14).to_a.each_with_index { |n, i| vehicle_identification_number[n] = manufacture["win_ext"][i] } unless manufacture["win_ext"].nil? + c = VIN_CHARS.split('').reject{ |n| n == '.'} + vehicle_identification_number = wmi.split('').concat( Array.new(14) { c.sample } ) + (12..14).to_a.each_with_index { |n, i| vehicle_identification_number[n] = wmi_ext[i] } unless wmi_ext.nil? vehicle_identification_number[10] = fetch('vehicle.year') vehicle_identification_number[8] = vin_checksum(vehicle_identification_number) @@ -19,19 +19,19 @@ def vin end def manufacture - fetch_all('vehicle.manufacture').sample["name"] + fetch_all('vehicle.manufacture').sample.first end - + private def calculate_vin_weight(character, i) - (@vin_chars.index(character) % 10) * @vin_map.index(@vin_weights [i]) + (VIN_CHARS.index(character) % 10) * VIN_MAP.index(VIN_WEIGHTS[i]) end def vin_checksum(vehicle_identification_number) - @vin_map[vehicle_identification_number.each_with_index.map(&method(:calculate_vin_weight)).inject(:+) % 11] + VIN_MAP[vehicle_identification_number.each_with_index.map(&method(:calculate_vin_weight)).inject(:+) % 11] end end end -end \ No newline at end of file +end diff --git a/lib/locales/en.yml b/lib/locales/en.yml index 077bb0b788..7f16ba3acd 100755 --- a/lib/locales/en.yml +++ b/lib/locales/en.yml @@ -370,147 +370,53 @@ en: vehicle: year: [A, L, Y, B, M, '1', C, N, '2', D, P, '3', E, R, '4', F, S, '5', G, T, '6', H, V, '7', J, W, '8', K, X, '9'] manufacture: - - name: MARQUESS ELECTRIC CAR COMPANY - wmi: 15E - wmi_ext: - - name: AJAX MANUFACTURING COMPANY, INC. - wmi: 1A9 - wmi_ext: '396' - - name: DAIMLERCHRYSLER CORPORATION - wmi: 1B6 - wmi_ext: - - name: BAY EQUIPMENT & REPAIR - wmi: 1B9 - wmi_ext: '290' - - name: CHOPPER GUY'S, INC. - wmi: 1C9 - wmi_ext: '564' - - name: COMMERCIAL MOBILE SYSTEMS - wmi: 1C9 - wmi_ext: ACA - - name: FORD MOTOR COMPANY - wmi: 1F1 - wmi_ext: - - name: AMERICAN TRANSPORTATION CORPORATION - wmi: 1F8 - wmi_ext: - - name: FMC CORP - wmi: 1F9 - wmi_ext: '041' - - name: GENERAL MOTORS CORPORATION - wmi: 1G8 - wmi_ext: - - name: AUTOMOTRIZ PEYCHA, S.A. DE C.V. - wmi: 3A9 - wmi_ext: '068' - - name: REGIOBUS, S.A. DE C.V. - wmi: 3R9 - wmi_ext: '097' - - name: Interstate West Corporation - wmi: 4RA - wmi_ext: - - name: HONDA MANUFACTURING OF ALABAMA - wmi: 5FS - wmi_ext: - - name: IMECA S.R.L. - wmi: 8C9 - wmi_ext: ME1 - - name: FIAT DIESEL BRASIL S/A - wmi: 9BE - wmi_ext: - - name: WOODGATE HOLDINGS LIMITED - wmi: DLA - wmi_ext: - - name: SOMACOA (STE. MALGACHE DE - wmi: GA1 - wmi_ext: - - name: ISUZU MOTORS LIMITED - wmi: J81 - wmi_ext: - - name: HYUNDAI MOTOR CO LTD - wmi: KPH - wmi_ext: - - name: SSANGYONG MOTOR COMPANY - wmi: KPL - wmi_ext: - - name: HUBEI CHILE AUTOMOBILE CO.LTD - wmi: L1C - wmi_ext: - - name: SICHUAN LESHAN BUS WORKS - wmi: LLD - wmi_ext: - - name: HERO HONDA MOTORS LTD - wmi: MB4 - wmi_ext: - - name: AEON MOTOR CO., LTD. - wmi: RF3 - wmi_ext: - - name: CHYONG HORNG ENTERPRISE CO., LTD. - wmi: RF4 - wmi_ext: - - name: YULON MOTOR CO., LTD. - wmi: RF5 - wmi_ext: - - name: DIN-LI METAL INDUSTRIAL CO LTD - wmi: RFW - wmi_ext: - - name: JAGUAR CARS LTD - wmi: SAJ - wmi_ext: - - name: LAND ROVER GROUP LTD - wmi: SAL - wmi_ext: - - name: ROVER GROUP LTD - wmi: SAR - wmi_ext: - - name: ZAKLAD BUDOWY I REMONTOW NACZEP WIE - wmi: SU9 - wmi_ext: WL1 - - name: SANOCKA FABRYKA AUTOBUSOW SFA - wmi: SUA - wmi_ext: - - name: Z.P.U.P.S. TRAMP TRAIL - wmi: SUB - wmi_ext: - - name: WYTWORNIA POJAZDOW MELEX - wmi: SXM - wmi_ext: - - name: MOWAG - wmi: TAM - wmi_ext: - - name: CSEPEL AUTOGYAR - wmi: TRC - wmi_ext: - - name: AUTOMOBILES TALBOT - wmi: VF4 - wmi_ext: - - name: IVECO UNIC SA - wmi: VF5 - wmi_ext: - - name: RENAULT VEHICULES INDUSTRIELS - wmi: VF6 - wmi_ext: - - name: KIBO KOMMUNALMASCHINEN GMBH & CO.KG - wmi: W09 - wmi_ext: K10 - - name: BMW MOTORSPORT GMBH - wmi: WBS - wmi_ext: - - name: P. BARTHAU STAHLBAU - wmi: WBT - wmi_ext: - - name: BMW AG - wmi: WBW - wmi_ext: - - name: DAIMLERCHRYLSER AG - wmi: WD2 - wmi_ext: - - name: DAIMLERCHRYSLER AG - wmi: WD3 - wmi_ext: - - name: MANDOS S.A. - wmi: XF9 - wmi_ext: D41 + - [ 'MARQUESS ELECTRIC CAR COMPANY', '15E', null ] + - [ 'AJAX MANUFACTURING COMPANY, INC.', '1A9', '396' ] + - [ 'DAIMLERCHRYSLER CORPORATION', '1B6', null ] + - [ 'BAY EQUIPMENT & REPAIR', '1B9', '290' ] + - [ "CHOPPER GUY'S, INC.", '1C9', '564' ] + - [ 'COMMERCIAL MOBILE SYSTEMS', '1C9', 'ACA' ] + - [ 'FORD MOTOR COMPANY', '1F1', null ] + - [ 'AMERICAN TRANSPORTATION CORPORATION', '1F8', null ] + - [ 'FMC CORP', '1F9', '041' ] + - [ 'GENERAL MOTORS CORPORATION', '1G8', null ] + - [ 'AUTOMOTRIZ PEYCHA, S.A. DE C.V.', '3A9', '068' ] + - [ 'REGIOBUS, S.A. DE C.V.', '3R9', '097' ] + - [ 'Interstate West Corporation', '4RA', null ] + - [ 'HONDA MANUFACTURING OF ALABAMA', '5FS', null ] + - [ 'IMECA S.R.L.', '8C9', 'ME1' ] + - [ 'FIAT DIESEL BRASIL S/A', '9BE', null ] + - [ 'WOODGATE HOLDINGS LIMITED', 'DLA', null ] + - [ 'SOMACOA (STE. MALGACHE DE', 'GA1', null ] + - [ 'ISUZU MOTORS LIMITED', 'J81', null ] + - [ 'HYUNDAI MOTOR CO LTD', 'KPH', null ] + - [ 'SSANGYONG MOTOR COMPANY', 'KPL', null ] + - [ 'HUBEI CHILE AUTOMOBILE CO.LTD', 'L1C', null ] + - [ 'SICHUAN LESHAN BUS WORKS', 'LLD', null ] + - [ 'HERO HONDA MOTORS LTD', 'MB4', null ] + - [ 'AEON MOTOR CO., LTD.', 'RF3', null ] + - [ 'CHYONG HORNG ENTERPRISE CO., LTD.', 'RF4', null ] + - [ 'YULON MOTOR CO., LTD.', 'RF5', null ] + - [ 'DIN-LI METAL INDUSTRIAL CO LTD', 'RFW', null ] + - [ 'JAGUAR CARS LTD', 'SAJ', null ] + - [ 'LAND ROVER GROUP LTD', 'SAL', null ] + - [ 'ROVER GROUP LTD', 'SAR', null ] + - [ 'ZAKLAD BUDOWY I REMONTOW NACZEP WIE', 'SU9', 'WL1' ] + - [ 'SANOCKA FABRYKA AUTOBUSOW SFA', 'SUA', null ] + - [ 'Z.P.U.P.S. TRAMP TRAIL', 'SUB', null ] + - [ 'WYTWORNIA POJAZDOW MELEX', 'SXM', null ] + - [ 'MOWAG', 'TAM', null ] + - [ 'CSEPEL AUTOGYAR', 'TRC', null ] + - [ 'AUTOMOBILES TALBOT', 'VF4', null ] + - [ 'IVECO UNIC SA', 'VF5', null ] + - [ 'RENAULT VEHICULES INDUSTRIELS', 'VF6', null ] + - [ 'KIBO KOMMUNALMASCHINEN GMBH & CO.KG', 'W09', 'K10' ] + - [ 'BMW MOTORSPORT GMBH', 'WBS', null ] + - [ 'P. BARTHAU STAHLBAU', 'WBT', null ] + - [ 'BMW AG', 'WBW', null ] + - [ 'DAIMLERCHRYLSER AG', 'WD2', null ] + - [ 'DAIMLERCHRYSLER AG', 'WD3', null ] + - [ 'MANDOS S.A.', 'XF9', 'D41' ] file: extension: ["flac", "mp3", "wav", "bmp", "gif", "jpeg", "jpg", "png", "tiff", "css", "csv", "html", "js", "json", "txt", "mp4", "avi", "mov", "webm", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "odt", "ods", "odp", "pages", "numbers", "key", "pdf"]