--8323328-1258920798-1141227858699
Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-1258920798-1141227858=:5699"

  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--8323328-1258920798-1141227858699
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

Hi --

On Thu, 2 Mar 2006, Krekna Mektek wrote:

> AFAIC See, this works all right, but my question is, just to learn the
> Ruby style, can this be done shorter (better)?
>
> class LineChecker
>  def checkline(line)
>      if line =~ /Checking:/
>         line =~ /<(.*?)>.*<(.*)>/
>         from = $1; rcpt = $2
>         from = "Unknown" if from == ""
>         rcpt = "Unknown" if rcpt == ""
>         return ([from,rcpt])
>      elsif line =~ /ClamAV-clamd\ result:\ /
>        return $'
>      else>        return []ен
>      end
>
>  end
> end

Here's a slightly different way that might give you some ideas:

class LineChecker

   REG=/<(.*?)>.*<(.*)>/

   def checkline(line)
     case line
     when /Checking:/
        m = REG.match(line)
        from, rcpt = m.captures if m
        [from || "Unknown", rcpt || "Unknown"]
     when /ClamAV-clamd result: /
       $'
     else
       []
     end
   end
end


David

-- 
David A. Black (dblack / wobblini.net)
Ruby Power and Light (http://www.rubypowerandlight.com)

"Ruby for Rails" chapters now available
from Manning Early Access Program! http://www.manning.com/books/black
--8323328-1258920798-1141227858699--
--8323328-1258920798-1141227858699--