From 9ad7f9888256825e2d0ad44bf04ee78fab42a141 Mon Sep 17 00:00:00 2001 From: jonny gamba Date: Sun, 9 Feb 2014 13:49:23 -0500 Subject: [PATCH 01/13] exercise completed --- .bundle/install.log | 7 +++++++ lib/phonebook.rb | 24 ++++++++++++++++++++++++ spec/lib/phonebook_spec.rb | 23 ++++++++++++++++++++++- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 .bundle/install.log diff --git a/.bundle/install.log b/.bundle/install.log new file mode 100644 index 0000000..af78ffb --- /dev/null +++ b/.bundle/install.log @@ -0,0 +1,7 @@ +# Logfile created on 2014-02-08 19:08:46 -0500 by logger.rb/36483 +I, [2014-02-08T19:08:46.099960 #1715] INFO -- : 0: diff-lcs (1.2.5) from /Library/Ruby/Gems/2.0.0/specifications/diff-lcs-1.2.5.gemspec +I, [2014-02-08T19:08:46.100799 #1715] INFO -- : 0: rspec-core (2.14.7) from /Library/Ruby/Gems/2.0.0/specifications/rspec-core-2.14.7.gemspec +I, [2014-02-08T19:13:20.805190 #1715] INFO -- : 0: rspec-expectations (2.14.5) from /Library/Ruby/Gems/2.0.0/specifications/rspec-expectations-2.14.5.gemspec +I, [2014-02-08T19:13:23.637206 #1715] INFO -- : 0: rspec-mocks (2.14.5) from /Library/Ruby/Gems/2.0.0/specifications/rspec-mocks-2.14.5.gemspec +I, [2014-02-08T19:13:23.661979 #1715] INFO -- : 0: rspec (2.14.1) from /Library/Ruby/Gems/2.0.0/specifications/rspec-2.14.1.gemspec +I, [2014-02-08T19:13:23.662442 #1715] INFO -- : 0: bundler (1.5.0.rc.2) from /Library/Ruby/Gems/2.0.0/specifications/bundler-1.5.0.rc.2.gemspec diff --git a/lib/phonebook.rb b/lib/phonebook.rb index 6693a1e..eb4711c 100644 --- a/lib/phonebook.rb +++ b/lib/phonebook.rb @@ -4,4 +4,28 @@ class Phonebook def initialize(contacts) @contacts = contacts end + + def contacts_names + @contacts.map(&:name) + end + + def contacts_numbers + @contacts.map(&:phone_numbers) + end + + def contacts_info + data = Hash.new + @contacts.map do |contact| + data << [contact.name, contact.phone_numbers] + end + data + end + + def every_contact_has_number? + @contacts.all? { |contact| !contact.phone_numbers.nil?} + end + + def contacts_with_no_number + @contacts.select { |contact| contact.phone_numbers.nil? } + end end diff --git a/spec/lib/phonebook_spec.rb b/spec/lib/phonebook_spec.rb index b7daa32..e447b5a 100644 --- a/spec/lib/phonebook_spec.rb +++ b/spec/lib/phonebook_spec.rb @@ -1,8 +1,11 @@ require 'spec_helper' require './lib/phonebook' +require './lib/contact' describe Phonebook do - let(:contacts) { [double('first contact'), double('second contact')] } + let(:contact1) { double('first contact', name: 'first name', phone_numbers: '3217889909') } + let(:contact2) { double('second contact', name: 'second name', phone_numbers: '32456563') } + let(:contacts) { [contact1, contact2] } let(:phonebook) { Phonebook.new(contacts) } describe "#contacts" do @@ -10,4 +13,22 @@ expect(phonebook.contacts).to eq(contacts) end end + + describe "contact_names" do + it "returns list of names" do + expect(phonebook.contacts_names).to eq([contact1.name, contact2.name]) + end + end + + describe "contact_numbers" do + it "returns list of contact's numbers" do + expect(phonebook.contacts_numbers).to eq([contact1.phone_numbers, contact2.phone_numbers]) + end + end + + describe "every_contact_has_number" do + it "returns that every contact has numbers" do + expect(phonebook.every_contact_has_number?).to be_true + end + end end From 01064e3786619c4ac42c09210d2b8da8fed9b564 Mon Sep 17 00:00:00 2001 From: jonny gamba Date: Sun, 16 Feb 2014 15:17:34 -0500 Subject: [PATCH 02/13] @ removed because it is not needed --- .gitignore | 1 + lib/phonebook.rb | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..397b4a7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.log diff --git a/lib/phonebook.rb b/lib/phonebook.rb index eb4711c..40ea503 100644 --- a/lib/phonebook.rb +++ b/lib/phonebook.rb @@ -1,31 +1,31 @@ -class Phonebook + attr_reader :contacts def initialize(contacts) - @contacts = contacts + contacts = contacts end def contacts_names - @contacts.map(&:name) + contacts.map(&:name) end def contacts_numbers - @contacts.map(&:phone_numbers) + contacts.map(&:phone_numbers) end def contacts_info data = Hash.new - @contacts.map do |contact| + contacts.map do |contact| data << [contact.name, contact.phone_numbers] end data end def every_contact_has_number? - @contacts.all? { |contact| !contact.phone_numbers.nil?} + contacts.all? { |contact| !contact.phone_numbers.nil?} end def contacts_with_no_number - @contacts.select { |contact| contact.phone_numbers.nil? } + contacts.select { |contact| contact.phone_numbers.nil? } end end From c79fce6b3adbff2200444df6c4a4dcf65507f559 Mon Sep 17 00:00:00 2001 From: jonny gamba Date: Sun, 16 Feb 2014 15:29:59 -0500 Subject: [PATCH 03/13] flatten the phone numbers array --- lib/phonebook.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/phonebook.rb b/lib/phonebook.rb index 40ea503..ddb74c0 100644 --- a/lib/phonebook.rb +++ b/lib/phonebook.rb @@ -10,7 +10,7 @@ def contacts_names end def contacts_numbers - contacts.map(&:phone_numbers) + contacts.map(&:phone_numbers).flatten end def contacts_info From faf26520c25ad08fc8378da1c5ac952b5516c001 Mon Sep 17 00:00:00 2001 From: jonny gamba Date: Sun, 16 Feb 2014 15:32:00 -0500 Subject: [PATCH 04/13] install log removed --- .bundle/install.log | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .bundle/install.log diff --git a/.bundle/install.log b/.bundle/install.log deleted file mode 100644 index af78ffb..0000000 --- a/.bundle/install.log +++ /dev/null @@ -1,7 +0,0 @@ -# Logfile created on 2014-02-08 19:08:46 -0500 by logger.rb/36483 -I, [2014-02-08T19:08:46.099960 #1715] INFO -- : 0: diff-lcs (1.2.5) from /Library/Ruby/Gems/2.0.0/specifications/diff-lcs-1.2.5.gemspec -I, [2014-02-08T19:08:46.100799 #1715] INFO -- : 0: rspec-core (2.14.7) from /Library/Ruby/Gems/2.0.0/specifications/rspec-core-2.14.7.gemspec -I, [2014-02-08T19:13:20.805190 #1715] INFO -- : 0: rspec-expectations (2.14.5) from /Library/Ruby/Gems/2.0.0/specifications/rspec-expectations-2.14.5.gemspec -I, [2014-02-08T19:13:23.637206 #1715] INFO -- : 0: rspec-mocks (2.14.5) from /Library/Ruby/Gems/2.0.0/specifications/rspec-mocks-2.14.5.gemspec -I, [2014-02-08T19:13:23.661979 #1715] INFO -- : 0: rspec (2.14.1) from /Library/Ruby/Gems/2.0.0/specifications/rspec-2.14.1.gemspec -I, [2014-02-08T19:13:23.662442 #1715] INFO -- : 0: bundler (1.5.0.rc.2) from /Library/Ruby/Gems/2.0.0/specifications/bundler-1.5.0.rc.2.gemspec From 8cbe769719132178ce5a3e327d74eba954389d66 Mon Sep 17 00:00:00 2001 From: jonny gamba Date: Sun, 16 Feb 2014 15:41:58 -0500 Subject: [PATCH 05/13] domain languaged fixed --- lib/phonebook.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/phonebook.rb b/lib/phonebook.rb index ddb74c0..9ec9ada 100644 --- a/lib/phonebook.rb +++ b/lib/phonebook.rb @@ -21,11 +21,11 @@ def contacts_info data end - def every_contact_has_number? + def every_contact_has_phone_number? contacts.all? { |contact| !contact.phone_numbers.nil?} end - def contacts_with_no_number + def contacts_without_phone_number contacts.select { |contact| contact.phone_numbers.nil? } end end From 1d75be8a3e0a4205014852f28c029f725dda023d Mon Sep 17 00:00:00 2001 From: jonny gamba Date: Sun, 16 Feb 2014 15:42:28 -0500 Subject: [PATCH 06/13] contacts_info method refactorized --- lib/phonebook.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/phonebook.rb b/lib/phonebook.rb index 9ec9ada..5963d32 100644 --- a/lib/phonebook.rb +++ b/lib/phonebook.rb @@ -14,11 +14,9 @@ def contacts_numbers end def contacts_info - data = Hash.new - contacts.map do |contact| - data << [contact.name, contact.phone_numbers] + contacts.inject({}) do |result, contact| + result.merge(contact.name => contact.phone_numbers) end - data end def every_contact_has_phone_number? From dfcf9f0b346903ffd4971d6d582a670be1ccceb9 Mon Sep 17 00:00:00 2001 From: jonny gamba Date: Sun, 16 Feb 2014 15:44:28 -0500 Subject: [PATCH 07/13] typo fixed --- lib/phonebook.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/phonebook.rb b/lib/phonebook.rb index 5963d32..349bb10 100644 --- a/lib/phonebook.rb +++ b/lib/phonebook.rb @@ -26,4 +26,3 @@ def every_contact_has_phone_number? def contacts_without_phone_number contacts.select { |contact| contact.phone_numbers.nil? } end -end From 2d8aae5bd591ab45990a0d2021d6e935b5d66e10 Mon Sep 17 00:00:00 2001 From: jonny gamba Date: Sun, 16 Feb 2014 15:46:59 -0500 Subject: [PATCH 08/13] typo fixed --- lib/phonebook.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/phonebook.rb b/lib/phonebook.rb index 349bb10..77a80a6 100644 --- a/lib/phonebook.rb +++ b/lib/phonebook.rb @@ -1,4 +1,4 @@ - +class contact attr_reader :contacts def initialize(contacts) @@ -26,3 +26,4 @@ def every_contact_has_phone_number? def contacts_without_phone_number contacts.select { |contact| contact.phone_numbers.nil? } end +end From fe2ecfc8bc5262ebc59f09794148b5f6eb8ab653 Mon Sep 17 00:00:00 2001 From: jonny gamba Date: Sun, 16 Feb 2014 15:48:24 -0500 Subject: [PATCH 09/13] typo fixed --- lib/phonebook.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/phonebook.rb b/lib/phonebook.rb index 77a80a6..853c83a 100644 --- a/lib/phonebook.rb +++ b/lib/phonebook.rb @@ -1,4 +1,4 @@ -class contact +class Phonebook attr_reader :contacts def initialize(contacts) From 5a132f69cf6d2e1e826e2be89d43b47462cf893f Mon Sep 17 00:00:00 2001 From: jonny gamba Date: Sun, 16 Feb 2014 15:52:09 -0500 Subject: [PATCH 10/13] @ needed for the constructor --- lib/phonebook.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/phonebook.rb b/lib/phonebook.rb index 853c83a..75d4cce 100644 --- a/lib/phonebook.rb +++ b/lib/phonebook.rb @@ -2,7 +2,7 @@ class Phonebook attr_reader :contacts def initialize(contacts) - contacts = contacts + @contacts = contacts end def contacts_names From 511c3dcf5792a7409e068a11ff1c24fc9c043ff1 Mon Sep 17 00:00:00 2001 From: jonny gamba Date: Sun, 16 Feb 2014 15:53:37 -0500 Subject: [PATCH 11/13] language domain updated --- lib/phonebook.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/phonebook.rb b/lib/phonebook.rb index 75d4cce..4fc3277 100644 --- a/lib/phonebook.rb +++ b/lib/phonebook.rb @@ -9,7 +9,7 @@ def contacts_names contacts.map(&:name) end - def contacts_numbers + def contacts_phone_numbers contacts.map(&:phone_numbers).flatten end From fb3bf45ae8e9745adc7b184150599e94e96724f8 Mon Sep 17 00:00:00 2001 From: jonny gamba Date: Sun, 16 Feb 2014 15:53:55 -0500 Subject: [PATCH 12/13] specs updated --- spec/lib/phonebook_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/lib/phonebook_spec.rb b/spec/lib/phonebook_spec.rb index e447b5a..b52a699 100644 --- a/spec/lib/phonebook_spec.rb +++ b/spec/lib/phonebook_spec.rb @@ -3,8 +3,8 @@ require './lib/contact' describe Phonebook do - let(:contact1) { double('first contact', name: 'first name', phone_numbers: '3217889909') } - let(:contact2) { double('second contact', name: 'second name', phone_numbers: '32456563') } + let(:contact1) { double('first contact', name: 'first name', phone_numbers: ['3217889909', '6733']) } + let(:contact2) { double('second contact', name: 'second name', phone_numbers: ['32456563']) } let(:contacts) { [contact1, contact2] } let(:phonebook) { Phonebook.new(contacts) } @@ -14,19 +14,19 @@ end end - describe "contact_names" do + describe "#contact_names" do it "returns list of names" do expect(phonebook.contacts_names).to eq([contact1.name, contact2.name]) end end - describe "contact_numbers" do + describe "#contact_phone_numbers" do it "returns list of contact's numbers" do expect(phonebook.contacts_numbers).to eq([contact1.phone_numbers, contact2.phone_numbers]) end end - describe "every_contact_has_number" do + describe "#every_contact_has_number" do it "returns that every contact has numbers" do expect(phonebook.every_contact_has_number?).to be_true end From e8b811f32b5972223f4e1760fd93022b3e243888 Mon Sep 17 00:00:00 2001 From: jonny gamba Date: Sun, 16 Feb 2014 15:55:48 -0500 Subject: [PATCH 13/13] contacts_phone_numbers updated --- spec/lib/phonebook_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/phonebook_spec.rb b/spec/lib/phonebook_spec.rb index b52a699..3a0c3e0 100644 --- a/spec/lib/phonebook_spec.rb +++ b/spec/lib/phonebook_spec.rb @@ -22,7 +22,7 @@ describe "#contact_phone_numbers" do it "returns list of contact's numbers" do - expect(phonebook.contacts_numbers).to eq([contact1.phone_numbers, contact2.phone_numbers]) + expect(phonebook.contacts_phone_numbers).to eq([contact1.phone_numbers[0], contact1.phone_numbers[1], contact2.phone_numbers[0]]) end end