Forum: Ruby noob question on writing a script in ruby

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
9d0bfe08e6ca87924bc5848a90c1b3fe?d=identicon&s=25 Tom Pap (tomkefal)
on 2009-03-05 10:45
hello to everyone, i am new to ruby and programming. At the moment i am
a bit confused on how to make a program do what i will explain in the
following lines so please any help will be appreciated!

In a few words, what i want to is to write a script which will parse
many .txt files inside a folder. Each file contains text in the format:

FileID: id
Name1: Value
Name2: Value2

, where the Names remain the same in every file but the Values change
(id is number).

So, the program based on id (number) of each file will handle the file

for example if "id" is "1" it will skip the file.
            if "id" is "10" it will process the file.
            if "id" is "20" it will process the file.

When each file will be processed the program will have to compare the
other values (Value, Value2 etc) with the values of a database
(MS-Access db containing same values) and if the values are same do
nothing, if not do something else.

A possible solution im thinking may be:

require 'DBI'

# connection with database
cn = DBI.connect('DBI:ODBC:database')

# parsing each file inside the folder
class File_parse

  basedir = "C:\filefolder"
  files = Dir.glob("*")

    files.each do |file|
    result = {}
    files.readlines do |lines|

but from this point i don't know how to continue, how to compare the
values of each file with the values inside the database..

for example

 if result.FileID=1
  do nothing
  set a flag to false

 if result.FileID=10
  compare Name1: Value1 with values of database
  set a flag to true

 if result.FileID=20
  compare Name2: Value2 with values of database
  set a flag to true


if flag = true
 do something
 do nothing

my programming skills are very limited so any help or explanations on
how to continue will be much appreciated.
Da22709962fc0cf31068e779c78ab6be?d=identicon&s=25 Raveendran .P (jazzezravi)
on 2009-03-05 11:12
Hi Tom,

I don't have script.But i will give simple idea to you.

1. DB contains --> value1,value2,value3 ...

2. collect all the fields as an array @db=["value1","value2","value3"]

3. new record set -> "value2","value4"

4. if @db.include?("value2")== false then
       SAVE DB

I feel it was not a good code. Anyway let us see this thread for new

This topic is locked and can not be replied to.