CSE190M [Ruby Section] Assignment #4
Object Oriented Programming in Ruby: Battwitter
Assignment Clarification
Twitter is one of the sites we introduced as using Ruby on Rails. The site works by prompting users for status updates that are 140 characters or less, fondly referred to as "tweets". It then posts these "tweets" to user pages, in which other users may read, reply, etc. It might help to think of each "tweet" as an Object for the purposes of this assignment.
Your mission is to make the "tweet" Object that effectively drives Batman's personal twitter page. The Dark Knight has customized his Twitter account to be a little more sophisticated than a normal one. Each time he updates, he submits a criminal name, the crime committed, and a rank of priority [how urgent / important this update is]. The object is described in detail below. We will provide you with a skeleton .erb document that will include most of the file processing and Object manipulation code. You only need to write the Object itself.
Data Management
baddies.txt - The .txt file in which all "tweets" should be stored. Each individual criminal update is stored on a single line of text as "<name>,<crime>,<rank>"
For example, when Batman is chasing Catwoman and The Joker, baddies.txt will look like this:
Catwoman,meowing too much,1 Joker,wearing too much make up,5
Object Implementation
Your implementation of the object should include all of the following methods:
-
initialize(name, crime, rank)
Creates a new Badguy object with the specified name, crime, and priority ranking. -
Attribute Access
You will need to allow access to the fields of your objects including the name, crime, and rank by creating methods of the same name. You may wish to take advantage of attr_reader, attr_writer, and/or attr_accessor. -
write_to_file(filename)
Appends the String representation of a Badguy to the file specified by "filename". Each Badguy object should be represented as a String in the following format: <name>,<crime>, <rank>. -
from_s(data)
Accepts a String "data" as a paramater and creates a Badyguy from the String representation described above.
Expected Behavior
To see a working example, check out Kelly's Battwitter
Skeleton Code
The skeleton code is available here. You should not need to modify the skeleton erb file.