Problems porting from Python to Ruby -


i have neat little script in python port ruby , think it's highlighting noobishness @ ruby. i'm getting error there unexpected end statement, don't see how can so. perhaps there keyword requires end or doesn't want end forgot about. here of code leading offending line offending line commented.

begin     require base64     require base32 rescue loaderror     puts "etext requires base32. use 'gem install --remote base32' , try again" end  # string text file disk filename = argv.first textfile = file.open(filename) text = textfile.read()  mailtype = "text only" # set default mailtype  #cut email sections textlist1 = text.split(/\n\n/) header = textlist1[0]  if header.match (/mime-version/)     mailtype = "mime" end  #if mail has no attachments, parse text-only. class class textonlymailparser      def initialize(textlist)         = 1         body = ""         header = textlist[0]         @parsedemail = email.new(header)         while < textlist.count             body += ('\n' + textlist[a] + '\n')             += 1             end         @parsedemail.body = body     end end  def separate(text,boundary = nil)     # returns list of strings , lists containing of parts of email     if !boundary #look in email "boundary= x"         text.scan(/(?<=boundary=).*/) |bound|             textlist = recursivesplit(text,bound)             end         return textlist     end     if boundary          textlist = recursivesplit(text,boundary)     end end   def recursivesplit(chunk,boundary)     if chunk.is_a? string         searchstring = "--" + boundary         ar = cunk.split(searchstring)         return ar     elsif chunk.is_a? array         chunk |bit|             recursivesplit(bit,boundary);         end     end end  class mimeparser     def initialize(textlist)         @textlist = textlist         @nesteditems = []         newitem = nestitem.new(self)         newitem.value = @textlist[0]         newitem.contenttype = "header"         @nesteditems.push(newitem)         #setup parsed email         @parsedemail = email.new(newitem.value)         self._constructnest     end          def checkforcontentspecial(item)         match = item.value.match (/content-disposition: attachment/)         if match             filename = item.value.match (/(?<=filename=").+(?=")/)             encoding = item.value.match (/(?<=content-transfer-encoding: ).+/)             data = item.value.match (/(?<=\n\n).*(?=(\n--)|(--))/m)             datagroup = data.split(/\n/)             datastring = ''             = 0             while < datagroup.count                 datastring += datagroup[i]                 ++             end #<-----this offending line             @parsedemail.attachments.push(attachment.new(filename,encoding,datastring))         end 

your issue i ++ line, ruby not have post or pre increment/decrement operators , line failing parse. can't account why i++ evaluates in irb i ++ not perform action.

instead replace ++ operators += 1 making last while:

while < datagroup.count   datastring += datagroup[i]   += 1 end 

but think ruby way, if you're adding string why not datastring = datagroup.join instead of looping on while construct?


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -