Homework - Class Reps
Tonight we're going to have you repeatedly build classes over and over. The primary goal is for you to become familiar with building classes. We're going to take what you have learned to build a few amazing utilities that you can use once we build servers tomorrow!
1. Movie Class
- Build a class called
Movie. - You are not allowed to use
attr_accessorwith this class. - This means that you need to build manual getters/setters!
- This class has the following attributes as
@instance_variables:@movie_title@movie_description@ombb_url
- This class has the following abilities:
- set_ombd_url with a single argument of url that will set
@omdb_url - get_omdb_url that returns
@ombd_url - fetch_movie that uses
HTTParty.getwith the@urlto receive data. Next, it will update@movie_titleand@movie_descriptionwith - to_s that returns the
@movie_title&@movie_descriptionas a string.
- set_ombd_url with a single argument of url that will set
- Test these methods to verify they work in your code.
- Note: Don't forget to
require 'HTTParty'in your code! - Save this in a file called
movie_class.rb
2. Dictionary Class
- Build a class called
Dictionary - You are not allowed to use
attr_acessorwith this class. - This means that you need to build manual getters/setters!
- This class has the following attributes as
@instance_variables:@internal_hash
- This class has the following abilities:
get_dictionarythat returns@internal_hashaddthat accepts two arguments::keyandvalue. You will then add these to your@internal_hashto_sthat returns the@internal_hashas a string (consider using.eachhere)to_jsonthat returns the@internal_hashas a JSON object.
- Note: Don't forget to
require 'json'in your code! - Test these methods to verify they work in your code.
- Add a
404key with a value ofwomp womp - the page doesn't exist - Add a
403key with a value ofDENIED ACCESS - Add a
500key with a value ofSERVER ERROR OH NOES - Output the Dictionary as JSON using the method you built.
- Add a
- Save this in a file called
dictionary_class.rb
3. RUPS Class
- Build a class called
Rups - You are allowed to use
attr_accessorin this class! - Turn all of your homeworks' methods last night into individual methods that your
Rupsclass owns. - Add instance variables as needed here (you may or may not need them depending on how you build your class)
- Test and verify all of your methods work.
- Save this in a file called
rups_class.rb
To get you started...
class Rups
def lengths(argument)
# some code...
end
end