Class: Car::CarAdd
- Inherits:
-
Object
- Object
- Car::CarAdd
- Defined in:
- lib/car_add.rb
Instance Attribute Summary collapse
-
#full_name ⇒ Object
Returns the value of attribute full_name.
-
#model ⇒ Object
Returns the value of attribute model.
-
#plate ⇒ Object
Returns the value of attribute plate.
Instance Method Summary collapse
- #add ⇒ Object
-
#initialize(plate, model, full_name) ⇒ CarAdd
constructor
A new instance of CarAdd.
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_name ⇒ Object
Returns the value of attribute full_name.
6 7 8 |
# File 'lib/car_add.rb', line 6 def full_name @full_name end |
#model ⇒ Object
Returns the value of attribute model.
6 7 8 |
# File 'lib/car_add.rb', line 6 def model @model end |
#plate ⇒ Object
Returns the value of attribute plate.
6 7 8 |
# File 'lib/car_add.rb', line 6 def plate @plate end |
Instance Method Details
#add ⇒ Object
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 |