Class: Car::CarAdd

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plate, model, full_name) ⇒ CarAdd

Returns a new instance of CarAdd.



8
9
10
11
12
# File 'lib/car_add.rb', line 8

def initialize(plate, model, full_name)
    @plate = plate
    @model = model
    @full_name = full_name
end

Instance Attribute Details

#full_nameObject

Returns the value of attribute full_name.



6
7
8
# File 'lib/car_add.rb', line 6

def full_name
  @full_name
end

#modelObject

Returns the value of attribute model.



6
7
8
# File 'lib/car_add.rb', line 6

def model
  @model
end

#plateObject

Returns the value of attribute plate.



6
7
8
# File 'lib/car_add.rb', line 6

def plate
  @plate
end

Instance Method Details

#addObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/car_add.rb', line 14

def add
    city_file = File.read('plates.json')
    city_list = JSON.parse(city_file)
    name_surname = full_name.split(' ')
    name = name_surname[0]
    surname = name_surname[1]
    item = "#{name.upcase} #{surname.upcase} - #{city_list[plate.slice(0,2)]} - #{model.upcase} - #{plate}"
    File.open("cars.yml", "a") {|file| file.write(item.to_yaml)}
    puts "#{plate} vehicle was added."
end