Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > New guy... Intoduction and first question on some direction.

Reply
Thread Tools

New guy... Intoduction and first question on some direction.

 
 
Oscar Gonzalez
Guest
Posts: n/a
 
      12-08-2005
Well thats a lot of info so I have to digest on it. I'll post back as
soon as I have a better grasp of your responses... However I do not want
to use Lua for this because I want to learn Ruby... I don't think its a
problem that the data is in Lua syntax, from what I can see, it doesnt
matter what format the data is in. It seems to be a matter of finding a
pattern and being able to merge the data from two files into one.

For the purpose of being accurate on the smple, I've posted the file on
my site so maybe if you see the actual file I'm working with you'll get
a better idea of what I want.

http://www.muychingon.com/gatherer.txt



--
Posted via http://www.ruby-forum.com/.


 
Reply With Quote
 
 
 
 
Bill Guindon
Guest
Posts: n/a
 
      12-09-2005
On 12/8/05, Oscar Gonzalez <(E-Mail Removed)> wrote:
> Well thats a lot of info so I have to digest on it. I'll post back as
> soon as I have a better grasp of your responses... However I do not want
> to use Lua for this because I want to learn Ruby... I don't think its a
> problem that the data is in Lua syntax, from what I can see, it doesnt
> matter what format the data is in. It seems to be a matter of finding a
> pattern and being able to merge the data from two files into one.
>
> For the purpose of being accurate on the smple, I've posted the file on
> my site so maybe if you see the actual file I'm working with you'll get
> a better idea of what I want.
>
> http://www.muychingon.com/gatherer.txt


Ok, seems I was right about the format. Don't peek if you want to
solve it on your own

http://www.mvgo.com/anarchy/lua.rb.txt

a fun little ruby quiz (I _think_ I got it right).

--
Bill Guindon (aka aGorilla)


 
Reply With Quote
 
 
 
 
Steve Litt
Guest
Posts: n/a
 
      12-09-2005
On Thursday 08 December 2005 06:39 pm, Oscar Gonzalez wrote:
> Well thats a lot of info so I have to digest on it. I'll post back as
> soon as I have a better grasp of your responses... However I do not want
> to use Lua for this because I want to learn Ruby... I don't think its a
> problem that the data is in Lua syntax, from what I can see, it doesnt
> matter what format the data is in. It seems to be a matter of finding a
> pattern and being able to merge the data from two files into one.
>
> For the purpose of being accurate on the smple, I've posted the file on
> my site so maybe if you see the actual file I'm working with you'll get
> a better idea of what I want.
>
> http://www.muychingon.com/gatherer.txt


Below my sig is a 45 line program using Node.rb that converts the file into
Node objects, each with a name and value. You can see how Walker objects and
callback routines work. In order to output your chosen format (which I didn't
completely understand), you'd need to create probably a couple more Walkers
and a couple more callback routines.

This program assumes consistent indentation. If that cannot be assumed, you
need to either do something else (maybe what Bill Guindon suggested), or
create a tiny brace to indent converter and then run the result through my
program.

HTH

SteveT

Steve Litt
http://www.troubleshooters.com
http://www.velocityreviews.com/forums/(E-Mail Removed)


#!/usr/bin/ruby
require "Node.rb"

class Callbacks
def cb_look_data(checker, level)
print "\t" * level
print "Name = ", checker.name
print ", Value = " , checker.value unless checker.firstchild
print "\n"
end

def cb_get_fields(checker, level)
if checker.value =~ /\s*}/
checker.deleteSelf()
end
checker.value.gsub!(/,\s*$/, "")
checker.value.strip!
checker.value =~ /\[([^\]]*)\]/
checker.name = $1 if $1
if level == 1
checker.value =~ /(.*)\s*=/
checker.name = $1 if $1
end

checker.value =~ /=\s*(.*)/
checker.value = $1 if $1
checker.value = "" if checker.value == "{"
end
end


cb = Callbacks.new() # INSTANTIATE CALLBACKS OBJECT

#### PARSE THE FILE
parser = OutlineParser.new()
head = parser.parse("/home/slitt/gatherer.txt")

#### PARSE THE NODE TREE NODES INTO NAME AND VALUE FIELDS
walker = Walker.new(head, cb.method(:cb_get_fields), nil)
walker.walk()

#### PRINT THE NAME FIELDS FOR CONTAINERS,
#### AND NAME AND VALUE FIELDS FOR LEAF LEVELS
walker = Walker.new(head, cb.method(:cb_look_data), nil)
walker.walk()


 
Reply With Quote
 
Martin DeMello
Guest
Posts: n/a
 
      12-09-2005
Steve Litt <(E-Mail Removed)> wrote:
> If you can count on indentation like you have above, the easy way might be to
> run it through the OutlineParser object of Node.rb
> (http://www.troubleshooters.com/proje...e.rb/index.htm). Once the data is


Very nice piece of software indeed.

martin
 
Reply With Quote
 
Steve Litt
Guest
Posts: n/a
 
      12-09-2005
On Friday 09 December 2005 09:47 am, Martin DeMello wrote:
> Steve Litt <(E-Mail Removed)> wrote:
> > If you can count on indentation like you have above, the easy way might
> > be to run it through the OutlineParser object of Node.rb
> > (http://www.troubleshooters.com/proje...e.rb/index.htm). Once the
> > data is

>
> Very nice piece of software indeed.
>
> martin


Thanks Martin,

It should be nice. I've written it in three different languages so far

I use VimOutliner (http://www.vimoutliner.org) to create tab indented
outlines, and find that Node.[pm py rb] makes processing outlines trivial for
substantial jobs, and doable for arduous ones (like converting an outline
into a menu system).

Thanks for the compliment.

SteveT

Steve Litt
http://www.troubleshooters.com
(E-Mail Removed)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
" *first = new string(*rhs.first);" cannot compile in MSVC fl C++ 10 01-12-2012 02:41 PM
how common is it to get email spam with your first, first and last and/or home town in it? Lookout Computer Support 16 04-27-2006 07:42 AM
Parent first or child first? (a class structure question) Tony Young C++ 3 03-26-2006 12:59 AM
New site: need some advise (first attempt) ThLog HTML 6 03-02-2006 11:13 AM
Forms Authentication question: How to have some pages open and some requiring forms authentication Eric ASP .Net 2 02-13-2004 02:14 PM



Advertisments