From 25d1543281fc906e0ed37b0c0ae2756c46e73b84 Mon Sep 17 00:00:00 2001 From: Erkam Kucet Date: Mon, 7 Mar 2016 16:31:06 +0200 Subject: [PATCH 1/2] First --- .DS_Store | Bin 0 -> 6148 bytes .idea/.name | 1 + .idea/encodings.xml | 6 + .idea/misc.xml | 14 ++ .idea/modules.xml | 8 + .idea/odev-01ruby.iml | 31 ++++ .idea/vcs.xml | 6 + .idea/workspace.xml | 337 ++++++++++++++++++++++++++++++++++++++++++ Gemfile | 2 + Gemfile.lock | 1 + address_book.rb | 19 ++- main.rb | 2 +- 12 files changed, 423 insertions(+), 4 deletions(-) create mode 100644 .DS_Store create mode 100644 .idea/.name create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/odev-01ruby.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..bd899355e3d199f52418a3e9977765ca107374d8 GIT binary patch literal 6148 zcmeHK!A`i=n^E03ipi32O^=Nj8To>JvR`AG0r}tRkg~u&&lv~l}_=^n4 zyF0-Ya~>#)L<6`poIllyE$AL5zMRMPT^m@(t5e2Xh+AMdq3dYZFhWVyQvq?b5j zf-%mK;hH$4&Egu`MLnZ~wQ{`P+eJN^B*diwD~~=ME^Izr zsO-WH#c6fkKhbcw)T3Erz!-=bIPj-^S^vlT_y2K{of!khz`tU^wX>US#FoO^y49Sl twF&i(Dk5=}$4v?cx)d{3mf};Y3jK);h-tveBRv%R5l|Y;7z4k`z&E-Qdd~m= literal 0 HcmV?d00001 diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..dedc45b --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +odev-01ruby \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..267d569 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..4709cc6 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/odev-01ruby.iml b/.idea/odev-01ruby.iml new file mode 100644 index 0000000..56cd710 --- /dev/null +++ b/.idea/odev-01ruby.iml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..2100dd3 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,337 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + Ruby + + + + + RubyResolve + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1457359416994 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Gemfile b/Gemfile index 90531fb..2b8ce04 100644 --- a/Gemfile +++ b/Gemfile @@ -1 +1,3 @@ +source 'https://rubygems.org' + gem 'minitest' 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..85d5199 100644 --- a/address_book.rb +++ b/address_book.rb @@ -1,13 +1,26 @@ +require 'csv' + class AddressBook - def initialize(csv_path) + @people = Array.new + + def initialize(csv_path) + @people = CSV.read(csv_path) end def print_people - + @people.each do |person| + print person + puts + end end def search_person(person_name) - + if @people.include?(person_name) + puts "bulundu" + return 1 + else + puts "bulunamadı" + end end end diff --git a/main.rb b/main.rb index 3996187..023ad3a 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("Roy") From 2188f9c0efdecc30f03e62bffb2b87fb64b3cbb7 Mon Sep 17 00:00:00 2001 From: Erkam Kucet Date: Mon, 7 Mar 2016 16:54:24 +0200 Subject: [PATCH 2/2] Final --- .idea/workspace.xml | 42 +++++++++++++++++++++--------------------- address_book.rb | 24 ++++++++++++++---------- person.rb | 9 +++++++++ 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2100dd3..4634b51 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,10 +2,9 @@ - - + - + @@ -19,7 +18,7 @@ - + @@ -272,16 +272,16 @@ - + - + - + @@ -301,10 +301,10 @@ - + - + @@ -320,15 +320,15 @@ - + - + - - + + diff --git a/address_book.rb b/address_book.rb index 85d5199..8099edc 100644 --- a/address_book.rb +++ b/address_book.rb @@ -1,26 +1,30 @@ require 'csv' +require './person.rb' class AddressBook - @people = Array.new + attr_accessor :people def initialize(csv_path) - @people = CSV.read(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 - @people.each do |person| - print person - puts + people.each do |person| + puts "#{person.id}, #{person.full_name}, #{person.phone_number}, #{person.city}" end end def search_person(person_name) - if @people.include?(person_name) - puts "bulundu" - return 1 - else - puts "bulunamadı" + people.each do |person| + if person.full_name.to_s.include? person_name + puts "#{person.id}, #{person.full_name}, #{person.phone_number}, #{person.city}" + return + end end + puts "#{person_name} bulunamadı." end end diff --git a/person.rb b/person.rb index ab139ec..889fb13 100644 --- a/person.rb +++ b/person.rb @@ -1,3 +1,12 @@ 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