Forum: Ruby Re: add to words syntaxes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E59545b25529b8ae09caffe860663296?d=identicon&s=25 Dani (Guest)
on 2006-03-17 12:56
(Received via mailing list)
Hi!
Sorry for me, I've puted the lines what you wrote but it can be, that to
wrong place or something, because I can't bring it to life. Would you
please look for it? Ive attach my script...
Regards:

Daniel
A9b6a93b860020caf9d2d1d58c32478f?d=identicon&s=25 Ross Bamford (Guest)
on 2006-03-17 15:00
(Received via mailing list)
On Fri, 2006-03-17 at 20:54 +0900, Dani wrote:
> Hi!
> Sorry for me, I've puted the lines what you wrote but it can be, that to
> wrong place or something, because I can't bring it to life. Would you
> please look for it? Ive attach my script...

If I had to do this quickly (and without too much thought) I'd do
something like this:

def process(text_data, &blk)
  text_data.split(/^$/m).each do |e|
    dta = e.strip.gsub(/;$/,'').split(/\n/)
    yield *(dta.slice!(0..5) + [dta])
  end
end

Which you'd then use like this:

process(File.read('teszt.data')) do |ny, ne, ados, adoa, to, ig,
columns|
  puts "#{ny} :: #{ne} :: #{ados} :: #{adoa} :: #{to} :: #{ig}"
  p columns
end

# => 0608A :: Teszt Kft :: 33445566222 ::  :: 20060101 :: 20060131
#    ["0A0001C002A 33445566222", "0A0001C007A Teszt kft"]
#    0608M :: Oscar Wild :: 123456789 ::  :: 20060101 :: 20060131
#    ["0A0001C002A 33445566222", "0A0001C007A Teszt kft"]

Obviously you'd change the output to suit your needs. Bear in mind I've
not extensively tested this...
This topic is locked and can not be replied to.