WEBVTT

1
00:00:00.500 --> 00:00:06.420
So, when we just left off,
we had added the ability to add a contact

2
00:00:06.420 --> 00:00:08.480
to append to the internal contacts array.

3
00:00:08.480 --> 00:00:13.710
Now, what we're gonna do is add
the ability to add addresses and

4
00:00:13.710 --> 00:00:15.900
phone numbers to this
contact when we add them.

5
00:00:17.440 --> 00:00:22.740
So, we're gonna do that right here and
we're gonna do this using another loop.

6
00:00:22.740 --> 00:00:26.270
So we'll say loop do and end.

7
00:00:27.280 --> 00:00:31.360
So now we'll just display another menu, so

8
00:00:31.360 --> 00:00:36.390
when we add this contact we'll
say add phone number or address.

9
00:00:38.460 --> 00:00:41.860
And then we can use the letter
p to add a phone number

10
00:00:44.230 --> 00:00:48.070
and a to add an address.

11
00:00:52.080 --> 00:00:54.390
And then we will ask for a response.

12
00:00:57.240 --> 00:00:58.090
And make it lowercase.

13
00:01:02.030 --> 00:01:06.460
And now we have our response case method.

14
00:01:08.050 --> 00:01:10.530
Now what do we do when we have a response?

15
00:01:10.530 --> 00:01:14.650
Well, when it's the letter p,
we'll add a phone number,

16
00:01:14.650 --> 00:01:18.800
when it's the letter a we'll add
an address, and if it's anything else,

17
00:01:20.920 --> 00:01:24.510
we'll go back which will bring
us back into the main menu loop.

18
00:01:25.580 --> 00:01:28.860
And let's go ahead and
just add a little message for that,

19
00:01:28.860 --> 00:01:32.720
that says, Any other key to go back.

20
00:01:34.940 --> 00:01:39.120
Okay, and actually let's go ahead and
print out a new line before we go back.

21
00:01:40.400 --> 00:01:44.570
All right, so when the letter p happens,
let's go ahead and add a phone number.

22
00:01:45.660 --> 00:01:50.830
Now, the way that we do this is similar
to how we just added a contact up here.

23
00:01:50.830 --> 00:01:56.160
First we will initialize a new instance
of the phone number class, and

24
00:01:56.160 --> 00:01:57.840
then we'll just ask the user for input.

25
00:02:00.310 --> 00:02:01.590
So it's the letter p.

26
00:02:01.590 --> 00:02:04.580
We'll say a phone is a new phone number.

27
00:02:09.600 --> 00:02:12.630
And then we'll print out,

28
00:02:12.630 --> 00:02:18.174
what kind of phone number is it,
Home, work etc.

29
00:02:21.013 --> 00:02:25.920
And then the kind of phone number
is standard input once again.

30
00:02:28.010 --> 00:02:30.281
And now that we have the kind we'll
ask them to input the number.

31
00:02:35.261 --> 00:02:41.422
And then we can append

32
00:02:41.422 --> 00:02:47.246
this phone number.

33
00:02:47.246 --> 00:02:51.968
And that should bring us back to
the menu with the option to add

34
00:02:51.968 --> 00:02:55.440
another phone number or an address.

35
00:02:55.440 --> 00:03:01.480
And so adding the address is going
to follow the exact same pattern.

36
00:03:01.480 --> 00:03:03.156
So I'm just gonna go ahead and
paste that in here.

37
00:03:09.236 --> 00:03:13.617
So we initialize a new address instance,
ask what kind it is,

38
00:03:13.617 --> 00:03:17.340
allow them to enter all of
the address information.

39
00:03:17.340 --> 00:03:20.880
I'm gonna append it to
the internal addresses array.

40
00:03:22.010 --> 00:03:24.731
At the end of all this, it will be
pushed on to the contacts array.

41
00:03:28.011 --> 00:03:32.821
So now, let's go ahead and
run this and see how it's looking.

42
00:03:32.821 --> 00:03:36.861
Go ahead and type in ruby Address_book.rb.

43
00:03:36.861 --> 00:03:40.891
Let's go ahead and
just print the address book.

44
00:03:40.891 --> 00:03:42.830
Okay, there's no one in the contact list.

45
00:03:44.220 --> 00:03:47.800
Oh, the choice is not one,
it is a to add a contact,

46
00:03:47.800 --> 00:03:51.590
Jason, middle name no middle name,
last name Seifer.

47
00:03:51.590 --> 00:03:53.710
Do I wanna add a phone number or
an address?

48
00:03:53.710 --> 00:03:57.301
Yeah, I think I'd like
to add a phone number.

49
00:03:57.301 --> 00:04:02.721
Home phone number, 123-456-7890.

50
00:04:02.721 --> 00:04:03.861
That is my actual phone number.

51
00:04:03.861 --> 00:04:05.741
Please do not call me.

52
00:04:05.741 --> 00:04:08.381
Okay, and let me add an address too.

53
00:04:08.381 --> 00:04:15.041
Add a home address, 123 Home Address.

54
00:04:15.041 --> 00:04:20.601
And that's in Orlando, Florida.

55
00:04:20.601 --> 00:04:22.761
Postal code is 12345.

56
00:04:22.761 --> 00:04:24.150
Okay, that seems to be working.

57
00:04:24.150 --> 00:04:24.890
Let's go back.

58
00:04:25.900 --> 00:04:28.350
Let's go ahead and print the address
book and see how it looks.

59
00:04:28.350 --> 00:04:33.960
All right, got the contact list,
with Jason Seifer, looks good.

60
00:04:38.310 --> 00:04:44.900
So I can go ahead and press e to exit and
next up we'll add the ability to search.
