diff --git a/Gemfile.lock b/Gemfile.lock index 3cbeae8..3d189f7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,4 +1,5 @@ GEM + remote: https://rubygems.org/ specs: minitest (5.8.1) diff --git a/address_book.rb b/address_book.rb index e5406d1..78285a7 100644 --- a/address_book.rb +++ b/address_book.rb @@ -1,13 +1,23 @@ +require "./person.rb" +require 'csv' class AddressBook - def initialize(csv_path) - - end - - def print_people - - end - - def search_person(person_name) - - end + attr_accessor :people + def initialize(csv_path) + @book = [] + CSV.foreach(csv_path) do |row| + @book << Person.new(row[0],row[1],row[2],row[3]) + end + end + def print_people + @book.each do |person| + puts "# #{person.id},#{person.full_name},#{person.phone_number},#{person.city}" + end + end + def search_person(person_name) + @book.each do |person| + if person.full_name.include? person_name + puts "#{person.id},#{person.full_name},#{person.phone_number},#{person.city}" + end + end + end end diff --git a/main.rb b/main.rb index 3996187..2ce62c8 100644 --- a/main.rb +++ b/main.rb @@ -3,4 +3,4 @@ address_book = AddressBook.new("people.csv") address_book.print_people -address_book.search_person("Michael") +address_book.search_person("Emily") diff --git a/person.rb b/person.rb index ab139ec..445878c 100644 --- a/person.rb +++ b/person.rb @@ -1,3 +1,10 @@ class Person + attr_accessor :id, :full_name, :phone_number, :city + def initialize(id,full_name,phone_number,city) + @id = id + @full_name = full_name + @phone_number = phone_number + @city = city + end end