From 96d250d656581d15b9988133f9a9d941e536f6b1 Mon Sep 17 00:00:00 2001 From: Mike Mondragon Date: Wed, 4 Jul 2012 10:51:51 -0700 Subject: [PATCH] print debugging info about an mms2r object --- lib/mms2r.rb | 59 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/lib/mms2r.rb b/lib/mms2r.rb index c0a8133..66e9651 100644 --- a/lib/mms2r.rb +++ b/lib/mms2r.rb @@ -42,14 +42,67 @@ class MMS2R::Media USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.120 Safari/535.2" end + ## # Simple convenience function to make it a one-liner: - # MMS2R.parse raw_mail or MMS2R.parse File.load(raw_mail) + # MMS2R.parse raw_mail or + # MMS2R.parse File.load(file) + # MMS2R.parse File.load(path_to_file) # Combined w/ the method_missing delegation, this should behave as an enhanced Mail object, more or less. - def self.parse raw_mail, options = {} - mail = Mail.new raw_mail + + def self.parse thing, options = {} + mail = case + when File.exist?(thing); Mail.new(open(thing).read) + when thing.respond_to?(:read); Mail.new(thing.read) + else + Mail.new(thing) + end + MMS2R::Media.new(mail, options) end + ## + # Compare original MMS2R results with original mail values and other metrics. + # + # Takes a file path, mms2r object, mail object, or mail text blob. + + def self.debug(thing, options = {}) + mms = case thing + when MMS2R::Media; thing + when Mail::Message; MMS2R::Media.new(thing, options) + else + self.parse(thing, options) + end + + <