From 9fd2f6feb470669968a32082ebae581ab7be3239 Mon Sep 17 00:00:00 2001 From: gabriel-dehan Date: Thu, 16 Jan 2014 17:38:37 +0100 Subject: [PATCH] Correction --- Wagon-3/01-Mail-spotter/parsing_mail.rb | 34 ++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Wagon-3/01-Mail-spotter/parsing_mail.rb b/Wagon-3/01-Mail-spotter/parsing_mail.rb index 1d0f62b..0e85eb5 100644 --- a/Wagon-3/01-Mail-spotter/parsing_mail.rb +++ b/Wagon-3/01-Mail-spotter/parsing_mail.rb @@ -1,29 +1,29 @@ def parse_mail(mail) - jokes= { "gmail" => "you're an average but modern person", "lewagon" => "you're skilled and capable", "live" => "aren't you born before 1973 ?" } + jokes= { "gmail" => "you're an average but modern person", "lewagon" => "you're skilled and capable", "live" => "aren't you born before 1973 ?" } - if mail.match(/[\w.-]+@[\w.-]+\.com/) + if mail.match(/^[\w.-]+@[\w.-]+\.com$/) - user_name = mail.match(/[\w.-]+@/) - domain = mail.split("@").last.split(".").first + user_name = mail.match(/[\w.-]+@/) + domain = mail.split("@").last.split(".").first - if user_name.to_s.include?(".") - name = user_name.to_s.split(".").first - else - name = mail.split("@").first - end + if user_name.to_s.include?(".") + name = user_name.to_s.split(".").first + else + name = mail.split("@").first + end - if jokes.select{ |x, y| x.include?(domain) } - puts "Hohoh #{name.capitalize}, #{jokes[domain]}" - else - puts "Sorry, I don't know this domain name and can't tell you any joke..." - end + if jokes.select{ |x, y| x.include?(domain) } + puts "Hohoh #{name.capitalize}, #{jokes[domain]}" + else + puts "Sorry, I don't know this domain name and can't tell you any joke..." + end - else - puts "Did you check your email address ?" + else + puts "Did you check your email address ?" end end -parse_mail("boris.coucou@lewagon.com") # => "Well done boris, you're skilled and capable" \ No newline at end of file +parse_mail("boris.coucou@lewagon.com@gmail.com") # => "Well done boris, you're skilled and capable"