diff --git a/address_book.rb b/address_book.rb index e5406d1..2c1c5fc 100644 --- a/address_book.rb +++ b/address_book.rb @@ -1,13 +1,26 @@ -class AddressBook - def initialize(csv_path) +require 'csv' +require './person.rb' +class AddressBook + attr_accessor :people #Getter ve Setter + def initialize(csv_path) #Constructor + @people = [] + #print '#' + CSV.foreach(csv_path,{ :col_sep => ',' }) do |row| + people.push(Person.new(row[0],row[1],row[2],row[3])) + end end - def print_people - + people.each do |person| + puts "# #{person.id},#{person.full_name},#{person.phone_number},#{person.city}" + end end - def search_person(person_name) - + people.each do |person| + if person.full_name.to_s.include? person_name + puts "# #{person.id},#{person.full_name},#{person.phone_number},#{person.city}" + end + end + puts "!!!!! Cannot find #{person_name} named person!" end end diff --git a/main.rb b/main.rb index 3996187..73af39a 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("Melahat") diff --git a/person.rb b/person.rb index ab139ec..659be99 100644 --- a/person.rb +++ b/person.rb @@ -1,3 +1,9 @@ -class Person - -end +class Person + attr_accessor :id, :full_name, :phone_number, :city #Getter Setter + def initialize(id,full_name,phone_number,city) #Constructor + @id = id + @full_name = full_name + @phone_number = phone_number + @city = city + end +end