1 00:00:00,470 --> 00:00:05,700 So, when we last left off, we had created these create and 2 00:00:05,700 --> 00:00:07,560 instances class methods and 3 00:00:07,560 --> 00:00:12,480 then extended the classes with them when our inventoriable module was included. 4 00:00:13,840 --> 00:00:19,200 So now, let's go ahead and I have included the inventoriable module 5 00:00:19,200 --> 00:00:23,230 in the pant class and the accessory class. 6 00:00:24,710 --> 00:00:28,660 So, now lets go ahead and create some stock counts to work with. 7 00:00:30,080 --> 00:00:34,300 So, we’re gonna actually create some items and I’m just gonna paste this in. 8 00:00:34,300 --> 00:00:39,100 So, we’re gonna sell some Mike the Frog shirts, some jeans, and 9 00:00:39,100 --> 00:00:41,250 some belts, and a necklace. 10 00:00:42,640 --> 00:00:45,220 Now one thing that you'll notice right here 11 00:00:45,220 --> 00:00:49,530 is that the necklace does not have a size associated with it. 12 00:00:49,530 --> 00:00:52,500 That's gonna come into play very, very shortly. 13 00:00:53,610 --> 00:00:57,400 So what we're going to do is we wanna create a report 14 00:00:57,400 --> 00:01:00,840 of everything that is currently in stock. 15 00:01:00,840 --> 00:01:03,190 And we wanna do that at the class level. 16 00:01:04,510 --> 00:01:08,300 So we would say shirt dot in stock report, and 17 00:01:08,300 --> 00:01:11,910 we want that to return a list of everything that we have in stock. 18 00:01:12,990 --> 00:01:14,610 Now since it's going to be a class method, 19 00:01:14,610 --> 00:01:17,350 we're going to put it inside of our class methods module. 20 00:01:18,680 --> 00:01:26,740 Now, let's just go ahead and call this in_stock_report. 21 00:01:26,740 --> 00:01:30,470 So first we'll print to the screen the name of the class that we're working with 22 00:01:30,470 --> 00:01:36,700 which we can just do by typing self.to_s, in stock report. 23 00:01:38,320 --> 00:01:43,040 Now what we wanna do is select every instance that is in stock. 24 00:01:44,130 --> 00:01:47,810 So, we already have this in stock method, 25 00:01:47,810 --> 00:01:53,232 wouldn't it be great if we could just say instances.select, 26 00:01:53,232 --> 00:01:56,727 instance, and then say it's in stock. 27 00:02:00,001 --> 00:02:04,710 That would be great, but somehow we have to get a numerable in here. 28 00:02:04,710 --> 00:02:10,300 Well, we can do that the same way that we extended the class methods. 29 00:02:10,300 --> 00:02:13,920 We can also extend it with enumerable. 30 00:02:15,480 --> 00:02:20,380 So, when our inventoriable module gets included at the class level, 31 00:02:20,380 --> 00:02:23,440 we get all of these class methods and the enumerable module. 32 00:02:24,880 --> 00:02:27,490 Since we're getting the enumerable model, 33 00:02:27,490 --> 00:02:30,160 that means we need to define our own each method. 34 00:02:33,080 --> 00:02:36,360 And let's go ahead and look back at our enumerable work and 35 00:02:36,360 --> 00:02:37,460 see what we did in that one. 36 00:02:39,030 --> 00:02:44,200 We just defined a method called each, grabbed the block, 37 00:02:44,200 --> 00:02:47,030 and passed it into the players object. 38 00:02:48,360 --> 00:02:51,154 Well we can do the same thing here, and just pass it in to the instances. 39 00:02:57,959 --> 00:03:00,424 So now, whatever it is, if it's shirts, 40 00:03:00,424 --> 00:03:03,270 we'll just be running this against the shirts. 41 00:03:03,270 --> 00:03:06,070 If it's pants, same thing, and same thing with accessories. 42 00:03:07,860 --> 00:03:12,330 So we'll just say we're reporting on these things, so these are reportable, 43 00:03:14,420 --> 00:03:17,930 and now all we have to do is print them out. 44 00:03:17,930 --> 00:03:19,459 We've gone through and selected them, so 45 00:03:19,459 --> 00:03:21,079 we know we've got the ones that are in stock. 46 00:03:25,932 --> 00:03:28,310 And, what we'll do is something kind of interesting. 47 00:03:28,310 --> 00:03:32,790 We're just gonna iterate through them and we're gonna create 48 00:03:32,790 --> 00:03:37,030 an array of what we wanna report on and then print that array out. 49 00:03:37,030 --> 00:03:45,330 But, what we wanna do is, also remember how the size wasn't necessarily in here? 50 00:03:45,330 --> 00:03:47,150 We're gonna put a little if statement there. 51 00:03:47,150 --> 00:03:48,750 This will make a lot more sense in just a moment. 52 00:03:50,360 --> 00:03:57,003 We'll say align is an empty array, and we will push the item name here, 53 00:03:57,003 --> 00:04:01,453 and we have to grab the attributes for the name. 54 00:04:06,051 --> 00:04:11,554 And we will also say stock is the item's stock count 55 00:04:15,106 --> 00:04:21,480 Now remember how not every single item has a size, like this necklace right here? 56 00:04:21,480 --> 00:04:26,413 We’re not gonna print that out, if the item doesn’t have the size attribute. 57 00:04:26,413 --> 00:04:32,501 So, we’ll say if the item attributes, which is just a hash, 58 00:04:32,501 --> 00:04:36,610 include the size then we can print it out. 59 00:04:49,025 --> 00:04:55,339 And now we can just print out the line and we'll separate it with a tab character. 60 00:04:58,774 --> 00:05:02,160 And then we'll end this whole thing with a new line. 61 00:05:03,940 --> 00:05:06,740 Actually we need to interpolate that string. 62 00:05:06,740 --> 00:05:07,240 Okay. 63 00:05:08,680 --> 00:05:13,130 So now let's go ahead and call this and we'll do an in stock report for 64 00:05:13,130 --> 00:05:13,860 our shirts. 65 00:05:16,380 --> 00:05:18,110 And let's just see what happens. 66 00:05:18,110 --> 00:05:19,500 I'm going to make this a little bit bigger. 67 00:05:20,935 --> 00:05:22,710 Uh-oh. 68 00:05:22,710 --> 00:05:25,940 Syntax error, expecting keyword_end. 69 00:05:25,940 --> 00:05:30,000 Now when that happens, it usually means that we forgot an end somewhere. 70 00:05:30,000 --> 00:05:32,350 So let's go ahead and see if we can figure that out. 71 00:05:34,140 --> 00:05:37,000 All right, it looks like we needed a little if statement here. 72 00:05:38,820 --> 00:05:41,580 Let me clear the screen and run that again. 73 00:05:41,580 --> 00:05:42,620 Okay. 74 00:05:42,620 --> 00:05:44,240 And that worked just like we expected it to. 75 00:05:44,240 --> 00:05:46,920 We have an In Stock Report for our shirts. 76 00:05:46,920 --> 00:05:52,830 So let's go ahead and do the same thing for pants, and 77 00:05:52,830 --> 00:05:55,710 for our accessories as well. 78 00:05:58,010 --> 00:06:01,120 I'm gonna clear my screen and run this again. 79 00:06:02,390 --> 00:06:03,697 Make this a little bit bigger so that we can see. 80 00:06:03,697 --> 00:06:04,230 Clear one more time. 81 00:06:06,330 --> 00:06:10,976 Okay, we have our Shirt In Stock Report, our Pant In Stock Report, 82 00:06:10,976 --> 00:06:13,430 and our Accessory In Stock Report. 83 00:06:14,590 --> 00:06:18,740 And you'll notice for our necklace item, this does not list the size, 84 00:06:18,740 --> 00:06:20,250 which is exactly what we wanted. 85 00:06:20,250 --> 00:06:23,860 In our next video, we're going to clean this up just a little bit.