Skip to content

group-of-ruby-adepts/ruby-exercise-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 

Repository files navigation

ruby exercise 1 - Music Store

We will be learning Ruby on task:

Target
Create music album store terminal application in ruby
Teaching way
After any step will be suggestions and refactoring
Suggestions
please don't read next step if you didn't done prev( because it could suggest you something wrong)

Step one:

You have to create terminal application which after run show:

What do you want to do? 
1. Add Album
2. Remove Album 
3. Show Albums 
4. Quit 
  • Add Album - get only name and store it in array
  • Remove Album - get album name and remove from array if exist
  • Show Albums - print all albums
  • Quit - close app

After any command(except Quit) application should back to this menu.

Step two:

Please not read if you didn't make first step.

Great you done part one. You know loops, conditions, sample array, and important/sample methods. I'm not sure this step is good now. We will be learning more about arrays and hash.

I decide to chenge this step to few smaller to not make big jump.

Music store with only album names... not good. We need add to our data(array) also album songs and change everything to serve this so:

  1. add also songs after album( "Add album") with options add songs to existing album
  2. remove album with all songs( "Remove Album" )
  3. show also songs("Show Albums")
  4. add new menu option to remove songs from albums or rebuild second menu option to include submenu with two options... remove album remove song from album
Hints
to implement this data use nasted arrays/hash(or both mixed)
album should be still uniqe but songs could have the same name differents album

Step three(or it could be also step 4... your choose):

Please not read if you didn't make second step because you can create chaos in your head;)

Now our music store looks better but good to know albums artists. please implement also artist in our data structure.

Lets think a little about it. We can add artist to album but better will be add album/albums to artist because one artist can have a lot of albums. You need make also changes to serve it:

  1. add artist before album( "Add album") - if artist exist add to him other album
  2. add options to remove artist
  3. show also artist ("Show Albums") -capitalize list to show correct structure so show albums option can look:
	jackson
		thriler
			song 1
			song 2
			song 3
			...
		bad
			song 1
			...
	MrWhite
		album_one
			song 1
			song 2
			...
Hints
to implement this data use nasted arrays/hash(or both mixed)
artist should be uniqe but albums could have the same name to differen artist but one artist can't have two the same name
if you remove artist you also remove all him albums
album structure should stay not change

Step four:

if you make this step before step 3 then step 3 will(should) be easier.

good work but it's not look like should. You know conditions, loops, arrays, hashs, iterations, simple methods etc. Nice but this application look like spagetti... all things in one loop. Could you imagine this application if we will have 20-30 options in menu(not 6)? How we can find something and read this code? We can't...

so now is good moment to learn about class, module, creating methods, declaring methods visibility... please first read about it and think...

First you can input everything in one class and generate execute method which will be run our program. every options should be in own method.

It's really important point... you need know what it is class, module, method... how working OOP to understand this language

Step five:

Nice It should look better but we have to make a lot of more with this. But first one smaller step.

We should make something to store our data more then one application session. Data structure is perfect to store it in yaml. Yaml is important in ruby so good to learn it.

So our application should load yaml file on start and save changes after any change( or before quit - decide which better). Also if we havent yaml application should first create it.

application should load/create this file next to your application rb file but we not need know your music store so read about gitignore. It will be task to learn more about git.

Step six:

Now could be difficulty because we have to make changes to full OOP. So our artist,album and song should have own classes. It will be a lot of changes so we can separate it to three steps:

Step a separate only song. You have to:

  • create new class Song with 'name' instance variable. The best will be make it in new file.
  • change way how you add song to album(because now it's not string -> you have to generate new class instance)
  • show song
  • find (/check existing) song

it should be only ~12 lines code. If you have any problem please ask because it's really important part.

Step b separate album. It will be more difficulty(more changes and data schema will be change). You have to:

  • create new class Album with 'name' and 'songs' instance variables. 'songs' variable should be array. It will change schema because prev hash key was name(now it will be 'name' instance variable) and hash value was songs array(now we have to store it inside songs instance variable)
  • methods like add_song/find_song/remove_song should be inside Album class
  • change way how you add/remove album
  • show album
  • find (/check existing) album

Step c separate artist. (details comming soon)

About

Learning Ruby on task

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published