From 524acfa614de45f98e8a3ddb1cf4ff988e3b7a9e Mon Sep 17 00:00:00 2001 From: Furkan Celik Date: Tue, 8 Mar 2016 01:05:02 +0200 Subject: [PATCH 1/3] =?UTF-8?q?AdressBook=20s=C4=B1n=C4=B1f=C4=B1=20eklend?= =?UTF-8?q?i=20ve=20main=20dosyas=C4=B1=20duzenlendi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- address_book.rb | 13 ++++++++++--- main.rb | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/address_book.rb b/address_book.rb index e5406d1..0803fa8 100644 --- a/address_book.rb +++ b/address_book.rb @@ -1,13 +1,20 @@ +require 'csv' class AddressBook + def initialize(csv_path) - + @csv_path = csv_path end def print_people - + CSV.foreach(@csv_path) do |row| + print row.to_csv + end end def search_person(person_name) - + CSV.foreach(@csv_path) do |row| + print row.to_csv if person_name == row[1].split(" ")[0] + end end + end diff --git a/main.rb b/main.rb index 3996187..7650e84 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("Margaret") From f067f3dbcb4524e6df6069799f915d51643bdc57 Mon Sep 17 00:00:00 2001 From: Furkan Celik Date: Tue, 8 Mar 2016 01:39:15 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Person=20s=C4=B1nf=C4=B1=20eklendi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- person.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/person.rb b/person.rb index ab139ec..1b69851 100644 --- a/person.rb +++ b/person.rb @@ -1,3 +1,9 @@ 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 From b06549c54dbde209d12c330ba44881f47ea7bb9d Mon Sep 17 00:00:00 2001 From: Furkan Celik Date: Tue, 8 Mar 2016 01:39:38 +0200 Subject: [PATCH 3/3] =?UTF-8?q?AdressBook=20S=C4=B1n=C4=B1f=C4=B1=20d?= =?UTF-8?q?=C3=BCzenlendi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- address_book.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/address_book.rb b/address_book.rb index 0803fa8..98d2e4b 100644 --- a/address_book.rb +++ b/address_book.rb @@ -1,20 +1,28 @@ require 'csv' + class AddressBook - + attr_accessor :people + def initialize(csv_path) - @csv_path = csv_path + @people = [] + CSV.foreach(csv_path) do |row| + @people.push(Person.new(row[0], row[1], row[2],row[3])) + end end def print_people - CSV.foreach(@csv_path) do |row| - print row.to_csv + @people.each do |person| + puts print_row_person person end end def search_person(person_name) - CSV.foreach(@csv_path) do |row| - print row.to_csv if person_name == row[1].split(" ")[0] + @people.each do |person| + puts print_row_person(person) if person.full_name.include? person_name end end + def print_row_person(person) + "#{person.id}, #{person.full_name}, #{person.phone_number}, #{person.city}" + end end