This repository contains a partially implemented Person Management System. Your task is to complete the implementation according to the requirements below. The goal is to create a simple system that can create, store, and retrieve person records.
The repository contains the following files:
person.rb- Contains a partially implementedPersonclassperson_repo.rb- Contains a partially implementedPersonRepoclassapp.rb- Contains code that creates and saves person objectsGemfile- Lists project dependencies (RSpec for testing)spec/person_repo_spec.rb- Tests for thePersonRepoclassspec/person_spec.rb- Tests for thePersonclass
You need to implement:
-
The
Personclass with:- Constructor that accepts first name, last name, and age
- A unique identifier (id) for each person
- A
full_namemethod that returns the person's full name - A
savemethod that usesPersonRepoto save the person
-
The
PersonRepoclass with:- Functionality to save person data to
tmp/persons.json - Ability to read/retrieve stored person data
- Functionality to save person data to
-
Install dependencies:
bundle install -
Run the failing tests to understand what needs to be implemented:
bundle exec rspec -
Implement the required functionality in the
PersonandPersonRepoclasses -
Make sure all tests pass and the main script runs without errors
- You'll need to create a
tmpdirectory if it doesn't exist - The
PersonReposhould handle JSON serialization and deserialization - Think about how to structure the JSON data for easy retrieval
- Consider what instance variables the
Personclass needs - The
full_namemethod should combine first and last names appropriately - Each person should have a unique ID (think about using a universally unique identifier)
- Make sure IDs persist when saving and loading person records
- All tests pass
- Running
ruby app.rbsuccessfully saves all person records - Person data persists between program runs
- Code is clean, readable, and follows Ruby best practices
Good luck!