- Build a class that uses an initialize method
- Practice using an attribute accessor macro to make an attribute available to a class's methods
- Learn about Ruby's
String.split
method - Learn about RegEx
You will write a program that, given a string of email addresses, parses that string into an array.
Your class, EmailAddressParser
, should take the string of addresses on
initialization. Instances should respond to a #parse
instance method that
parses the string into individual email addresses and returns them in an array.
Your class should be able to do this:
email_addresses = "[email protected], [email protected]"
parser = EmailAddressParser.new(email_addresses)
parser.parse
# => ["[email protected]", "[email protected]"]
Note: Your EmailAddressParser
class should handle a list of email
addresses that are separated by either spaces or comma-separated values
(CSVs):
EmailAddressParser.new("[email protected], [email protected]").parse
# => ["[email protected]", "[email protected]"]
EmailAddressParser.new("[email protected] [email protected]").parse
# => ["[email protected]", "[email protected]"]
Additionally, the #parse
method should only return unique addresses.
This lab is test-driven, so run the test suite to get started and use the test output to get the program working.
Hints: in order to get this lab passing, you will need to do some research into the following topics:
- Ruby's
String.split
method - RegEx - you'll use this to specify which characters to split the string on
- Look at the Ruby documentation for the Array class. What method could be used to return an array of unique values?