|
3 | 3 | [](https://codeclimate.com/github/SelenaSmall/ruby_invoice) |
4 | 4 | [](https://codeclimate.com/github/SelenaSmall/ruby_invoice/coverage) |
5 | 5 |
|
| 6 | +Invoicing System written in Ruby. |
| 7 | + |
| 8 | +## Installation |
| 9 | + |
| 10 | +Environment: Built on Mac OSX 10.11.6 using Ruby -v 2.4.1 |
| 11 | + |
| 12 | +Make sure you have the correct version of ruby installed https://www.ruby-lang.org/en/documentation/installation/ |
| 13 | + |
| 14 | +1. Clone this Repo |
| 15 | + |
| 16 | +> $ git clone https://github.com/selenasmall/ruby_invoice.git |
| 17 | +
|
| 18 | +2. In root of the app run bundle install |
| 19 | + |
| 20 | +> $ gem install bundler && bundle install |
| 21 | +
|
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +Run the program from the app root |
| 26 | + |
| 27 | +> $ ruby app.rb |
| 28 | +
|
| 29 | +Expected terminal output: |
| 30 | + |
| 31 | +> Main menu: LIST available products, SHOP (add items to your order), VIEW basket, EXIT |
| 32 | +
|
| 33 | +__Main Menu__ |
| 34 | + |
| 35 | +Commands | Description |
| 36 | +--- | --- |
| 37 | +SHOP | Redirect to the shop menu where you can add products to your order |
| 38 | +LIST | Output a list of all available products along with their pack sizes and prices |
| 39 | +VIEW | Output an itemised invoice of all products that have been added to your order |
| 40 | +EXIT | Gracefully exit the program |
| 41 | + |
| 42 | +### Actions |
| 43 | + |
| 44 | +*** |
| 45 | +__SHOP__ |
| 46 | + |
| 47 | +Expected terminal output: |
| 48 | + |
| 49 | +``` |
| 50 | +Type BACK at any time to return to the main menu. |
| 51 | +Add qty and items to your order, example input: 3 watermelons |
| 52 | +$ __ |
| 53 | +``` |
| 54 | + |
| 55 | +* __Shop Menu__ |
| 56 | + |
| 57 | +Commands | Description |
| 58 | +--- | --- |
| 59 | +X products | Order a specified quantity of a product, where ‘x’ represents the quantity and ‘product’ represents the name of the product. |
| 60 | +BACK | Return to the main menu |
| 61 | + |
| 62 | + |
| 63 | +* __Shop Order Responses__ |
| 64 | + * __That is not a valid product__ Order will not be updated because the product is not valid |
| 65 | + * __Inconsistent quantity__ Order will not be updated because the quantity can not be made up with available packs for the specified product |
| 66 | + * __Product added__ Order will be updated with new product |
| 67 | + |
| 68 | +*** |
| 69 | + |
| 70 | +__LIST__ |
| 71 | + |
| 72 | +Expected terminal output: |
| 73 | + |
| 74 | +``` |
| 75 | +Products Available |
| 76 | +
|
| 77 | +Watermelons |
| 78 | + 3 pack @ $6.99 |
| 79 | + 5 pack @ $8.99 |
| 80 | +--------------------- |
| 81 | +
|
| 82 | +Pineapples |
| 83 | + 2 pack @ $9.95 |
| 84 | + 5 pack @ $16.95 |
| 85 | + 8 pack @ $24.95 |
| 86 | +--------------------- |
| 87 | +
|
| 88 | +Rockmelons |
| 89 | + 3 pack @ $5.95 |
| 90 | + 5 pack @ $9.95 |
| 91 | + 9 pack @ $16.99 |
| 92 | +--------------------- |
| 93 | +
|
| 94 | +$ __ |
| 95 | +``` |
| 96 | + |
| 97 | +*** |
| 98 | + |
| 99 | +__VIEW__ |
| 100 | + |
| 101 | +Expected terminal output: |
| 102 | + |
| 103 | +``` |
| 104 | +Customer Invoice |
| 105 | +qty item sub |
| 106 | +------------------------------------- |
| 107 | +------------------------------------- |
| 108 | +TOTAL |
| 109 | +
|
| 110 | +$ __ |
| 111 | +``` |
| 112 | + |
| 113 | +*** |
| 114 | + |
| 115 | +__EXIT__ |
| 116 | + |
| 117 | +Expected terminal output: |
| 118 | + |
| 119 | +``` |
| 120 | +Goodbye! |
| 121 | +``` |
| 122 | + |
| 123 | +*** |
| 124 | + |
| 125 | + |
| 126 | +## Testing |
| 127 | + |
| 128 | +Test by running rspec http://rspec.info/ |
| 129 | + |
| 130 | +> $ rake rspec |
| 131 | +
|
| 132 | +Expected terminal output: |
| 133 | + |
| 134 | +``` |
| 135 | +... ..CUSTOMER INVOICE |
| 136 | +qty item sub |
| 137 | +------------------------------------- |
| 138 | +------------------------------------- |
| 139 | +TOTAL 0 |
| 140 | +
|
| 141 | +.Type BACK at any time to return to the main menu. |
| 142 | +Add qty and items to backet, example input: 3 watermelons |
| 143 | +.CUSTOMER INVOICE |
| 144 | +qty item sub |
| 145 | +------------------------------------- |
| 146 | +10 watermelons 17.98 |
| 147 | + 2x 5 packs @ 8.99 |
| 148 | +------------------------------------- |
| 149 | +TOTAL 17.98 |
| 150 | +
|
| 151 | +... ... ... ... |
| 152 | +Watermelons |
| 153 | +3 pack @ 6.99 |
| 154 | +5 pack @ 8.99 |
| 155 | +
|
| 156 | +Pineapples |
| 157 | +2 pack @ 9.95 |
| 158 | +5 pack @ 16.95 |
| 159 | +8 pack @ 24.95 |
| 160 | +
|
| 161 | +Rockmelons |
| 162 | +3 pack @ 5.95 |
| 163 | +5 pack @ 9.95 |
| 164 | +9 pack @ 16.99 |
| 165 | +
|
| 166 | +... ... ... ... ... ... ... .Type BACK at any time to return to the main menu. |
| 167 | +Add qty and items to backet, example input: 3 watermelons |
| 168 | +..That's not a valid input |
| 169 | +... |
| 170 | +
|
| 171 | +Finished in 0.03877 seconds (files took 0.36899 seconds to load) |
| 172 | +46 examples, 0 failures |
| 173 | +
|
| 174 | +Coverage report generated for RSpec to /Users/selenasmall/devroot/ruby-projects/ruby_invoice/coverage. 395 / 398 LOC (99.25%) covered. |
| 175 | +
|
| 176 | +``` |
| 177 | + |
| 178 | +*** |
| 179 | + |
| 180 | +## Specifications |
| 181 | + |
| 182 | +### Description |
| 183 | + |
| 184 | +A fresh food supplier sells product items to customers in packs. |
| 185 | +The bigger the pack, the cheaper the cost per item. |
| 186 | + |
| 187 | +*** |
| 188 | + |
| 189 | +* __The supplier currently sells the following products__ |
| 190 | + |
| 191 | +``` |
| 192 | +Product Packs |
| 193 | +---------------------------------- |
| 194 | +Watermelons 3 pack @ $6.99 |
| 195 | + 5 pack @ $8.99 |
| 196 | + |
| 197 | +Pineapples 2 pack @ $9.95 |
| 198 | + 5 pack @ $16.95 |
| 199 | + 8 pack @ $24.95 |
| 200 | + |
| 201 | +Rockmelons 3 pack @ $5.95 |
| 202 | + 5 pack @ $9.95 |
| 203 | + 9 pack @ $16.99 |
| 204 | +``` |
| 205 | + |
| 206 | +*** |
| 207 | + |
| 208 | +* __Your task is to build a system that can take a customer order…__ |
| 209 | + |
| 210 | +For example, something like: |
| 211 | + |
| 212 | +10 Watermelons |
| 213 | +14 Pineapples |
| 214 | +13 Rockmelons |
| 215 | + |
| 216 | +*** |
| 217 | + |
| 218 | +* __And generate an invoice for the order…__ |
| 219 | + |
| 220 | +For example, something like: |
| 221 | + |
| 222 | +``` |
| 223 | +10 Watermelons $17.98 |
| 224 | + - 2 x 5 pack @ $8.99 |
| 225 | +14 Pineapples $54.80 |
| 226 | + - 1 x 8 pack @ $24.95 |
| 227 | + - 3 x 2 pack @ $9.95 |
| 228 | +13 Rockmelons $25.85 |
| 229 | + - 2 x 5 pack @ $9.95 |
| 230 | + - 1 x 3 pack @ $5.95 |
| 231 | +----------------------------- |
| 232 | +TOTAL $98.63 |
| 233 | +``` |
| 234 | + |
| 235 | +*** |
| 236 | + |
| 237 | +* __Note__ that the system has determined the optimal packs to fill the order. |
| 238 | +You can assume that bigger packs will always have a cheaper cost per unit price. |
| 239 | + |
| 240 | +*** |
| 241 | + |
| 242 | +### Constraints |
| 243 | + |
| 244 | +The system must be able to determine the optimal packs to fill the order. |
| 245 | + |
| 246 | +Example Input and Output: |
| 247 | + |
| 248 | +*** |
| 249 | +__1. Add items and view invoice__ |
| 250 | +``` |
| 251 | +> Main menu: LIST available products, SHOP (add items to your order), VIEW basket, EXIT |
| 252 | +``` |
| 253 | + |
| 254 | +> $_ SHOP |
| 255 | +
|
| 256 | +``` |
| 257 | +Type BACK at any time to return to the main menu. |
| 258 | +Add qty and items to your order, example input: 3 watermelons |
| 259 | +``` |
| 260 | + |
| 261 | +> $_ 10 watermelons |
| 262 | +> |
| 263 | +> $_ 14 pineapples |
| 264 | +> |
| 265 | +> $_ 13 rockmelons |
| 266 | +> |
| 267 | +> $_ BACK |
| 268 | +
|
| 269 | +``` |
| 270 | +Main menu: LIST available products, SHOP (add items to your order), VIEW basket, EXIT |
| 271 | +``` |
| 272 | + |
| 273 | +> $_ VIEW |
| 274 | +
|
| 275 | +``` |
| 276 | +Customer Invoice |
| 277 | +Items rounded up to nearest available qty |
| 278 | +qty item sub |
| 279 | +------------------------------------- |
| 280 | +10 watermelons 17.98 |
| 281 | + 2x 5 packs @ 8.99 |
| 282 | +13 rockmelons 25.85 |
| 283 | + 2x 5 packs @ 9.95 |
| 284 | + 1x 3 packs @ 5.95 |
| 285 | +14 pineapples 54.80 |
| 286 | + 1x 8 packs @ 24.95 |
| 287 | + 3x 2 packs @ 9.95 |
| 288 | +------------------------------------- |
| 289 | +TOTAL 98.63 |
| 290 | +``` |
| 291 | + |
| 292 | +*** |
| 293 | + |
| 294 | +__2. View invoice and add more items__ |
| 295 | +``` |
| 296 | +Main menu: LIST available products, SHOP (add items to your order), VIEW basket, EXIT |
| 297 | +``` |
| 298 | + |
| 299 | +> $_ SHOP |
| 300 | +
|
| 301 | +``` |
| 302 | +Type BACK at any time to return to the main menu. |
| 303 | +Add qty and items to your order, example input: 3 watermelons |
| 304 | +``` |
| 305 | + |
| 306 | +> $_ 10 watermelons |
| 307 | +> |
| 308 | +> $_ BACK |
| 309 | +
|
| 310 | +``` |
| 311 | +Main menu: LIST available products, SHOP (add items to your order), VIEW basket, EXIT |
| 312 | +``` |
| 313 | + |
| 314 | +> $_ VIEW |
| 315 | +
|
| 316 | +``` |
| 317 | +Customer Invoice |
| 318 | +Items rounded up to nearest available qty |
| 319 | +qty item sub |
| 320 | +------------------------------------- |
| 321 | +10 watermelons 17.98 |
| 322 | + 2x 5 packs @ 8.99 |
| 323 | +------------------------------------- |
| 324 | +TOTAL 17.98 |
| 325 | +``` |
| 326 | + |
| 327 | +> $_ SHOP |
| 328 | +
|
| 329 | +``` |
| 330 | +Type BACK at any time to return to the main menu. |
| 331 | +Add qty and items to your order, example input: 3 watermelons |
| 332 | +``` |
| 333 | + |
| 334 | +> $_ 13 rockmelons |
| 335 | +> |
| 336 | +> $_ 14 pineapples |
| 337 | +> |
| 338 | +> $_ BACK |
| 339 | +
|
| 340 | +``` |
| 341 | +Main menu: LIST available products, SHOP (add items to your order), VIEW basket, EXIT |
| 342 | +``` |
| 343 | + |
| 344 | +> $_ VIEW |
| 345 | +
|
| 346 | +``` |
| 347 | +Customer Invoice |
| 348 | +Items rounded up to nearest available qty |
| 349 | +qty item sub |
| 350 | +------------------------------------- |
| 351 | +10 watermelons 17.98 |
| 352 | + 2x 5 packs @ 8.99 |
| 353 | +13 rockmelons 25.85 |
| 354 | + 2x 5 packs @ 9.95 |
| 355 | + 1x 3 packs @ 5.95 |
| 356 | +14 pineapples 54.80 |
| 357 | + 1x 8 packs @ 24.95 |
| 358 | + 3x 2 packs @ 9.95 |
| 359 | +------------------------------------- |
| 360 | +TOTAL 98.63 |
| 361 | +``` |
| 362 | +*** |
| 363 | + |
| 364 | +### Assumptions |
| 365 | + |
| 366 | +* Orders which do not equate to the product of any given combination of packs will be ignored and not be added to the order |
| 367 | + |
| 368 | +*** |
| 369 | + |
| 370 | +## Additional Reading |
| 371 | +I wrote up my process of building this app, including one major tangent which completely ignored the premise of the brief and threw my design sideways for a period before finally resolving the solution. You can read about it here: http://webgeek.selenasmall.com/ruby-invoice/ |
0 commit comments