Strange StringScanner behaviour

N

Neowulf

Hi all,

I have a really bad feeling about posting this here, but I'm kinda
stumped.

I've only just discovered the wonder that is ruby and so have started
playing around with a number of projects.

One of them involves doing a little string parsing (as you'd expect).

However, when I try to make use of the StringScanner from the core API,
I get the strangest message:

NameError: uninitialized constant StringScanner

To put it in context:

!#/usr/bin/ruby -w

s = StringScanner.new("My test string")

I know... not exactally rocket science here. I just don't understand
why it's not working. Perhaps a corrupt installation?

I can't for the life of me figure out what I'm doing wrong...

I'm running the latest stable release of ruby (that I know of)
ruby 1.8.3 (2005-09-21) [i386-linux]

I get the same problem when attempting to test the code with irb.

Any thoughts suggestions would be greatly appreciated.

Best regards,
~Neowulf
 
D

Dan Diebolt

--0-1242312652-1135244814=:24651
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
NameError: uninitialized constant StringScanner
=20
require 'strscan'
s =3D StringScanner.new("My test string")



__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around=20
http://mail.yahoo.com=20
--0-1242312652-1135244814=:24651--
 
N

Neowulf

Thanks Dan,

I feel like a right idiot.

I suspected it'd be something simple

The API docs weren't real clear to me about which library to include.

Thanks again for the assistance.

~Neowulf
 
J

James Edward Gray II

Hi all,
Howdy.

I have a really bad feeling about posting this here, but I'm kinda
stumped.

Ah, don't say that. We're pretty nice and almost never bite. ;)

Feel free to ask future questions.
However, when I try to make use of the StringScanner from the core
API,

I know you've already got an answer, but this is the source of your
confusion and I thought I would see if I could clear it up for you.

Everything that is "Core Ruby" can be used without a require. Now
Ruby also ships with a "Standard Library", which is a collection of
useful extra libraries you can also use (but with a require).
StringScanner is a Standard Library.

You can tell by looking at which link they are documented under, from
this page:

http://www.ruby-doc.org/

Hope that helps.

James Edward Gray II
 
N

Neowulf

Hi James,

Thanks for the additional information. That makes things much clearer.

Though I greatly appreciate the help, I'll try to keep the annoying
questions to a minimum :)

Does the brain good to do some thinking on ones own sometimes :)

I'll be sure to call again should I hit another wall.

My current exercise is creating a script to scan through my systems log
files and autoblock the script kiddies who insist on trying their luck
with my SSH server.

Seemed like a nice, simple way to try out a few different ideas with
Ruby.

Might even post it when I'm done and see what you guys think.

We'll see how it goes :)

Thanks again.

~Neowulf
 
A

Anandh Kumar

Anandh said:
Hi everybody



Can the Stringscanner be also used in linux and also can it be used
in parsing the particular open office document... if so how should i call that document...
 
A

Anandh Kumar

Hi everybody


I've to parse the open office documents and upload it to the
database in ruby on rails and in linux platform. I've not found any gem
to accomplish that. Now i got a idea of converting the open office
documents to XML format and then to parse the XML content to finish up
with my task.



Is it possible?

Is there standard ruby on rails libraries to do this task?


Guide me in achieving this...




Thanks in advance

Anandh
 
R

Robert Klemme

2009/6/16 Anandh Kumar said:
=A0 =A0 =A0I've to parse the open office documents and upload it to the
database in ruby on rails and in linux platform. I've not found any gem
to accomplish that. Now i got a idea of converting the open office
documents to XML format and then to parse the XML content to finish up
with my task.

=A0 =A0 =A0 Is it possible?

=A0 =A0 =A0 Is there standard ruby on rails libraries to do this task?

=A0 =A0 Guide me in achieving this...

What do you mean by "upload to the database"? Do you want to store it
as blob, in an XML enabled database, as plain text, as...?

Btw, it never hurts to include "please" when asking for something.
Please help keep this a friendly place.

Cheers

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
A

Anandh Kumar

Thanks for your kind reply. I've to create a open office.org document
containing the students details such as name,registernumber etc. Then
i've to parse these strings and map these details into the corresponding
table in the database. can you please guide me in accomplishing this
task.





Thanks in advance


Anandh
 
C

Christopher Dicely

Hi everybody


=C2=A0 =C2=A0 =C2=A0I've to parse the open office documents and upload it= to the
database in ruby on rails and in linux platform. I've not found any gem
to accomplish that. Now i got a idea of converting the open office
documents to XML format and then to parse the XML content to finish up
with my task.

Isn't OOo's native format ODF, which is an XML format? So why do you
need to convert it to XML?
 
S

Srijayanth Sridhar

[Note: parts of this message were removed to make it a legal post.]

I'm not exactly getting what you are trying to say. Can you please make
it clear.
Actually, to be frank, WE aren't clear. What is it you want? What is "The
database"? Mysql? PostGRE? SQL Server? Oracle? sqlite? We have no clue
unless you tell us. Also, we don't know what your schema is, so unless you
give us more specific information other than "I want to parse open office
document and put it into the database", nobody here can help you.

Ok, let me make it a bit easier for you. I want you to fill in the following
blanks:

Hello,

I am trying to build an application that does ____________(please put in
something other than parsing an office document and put it into a database).
The application requires us to commit the contents of a file into a
database. The file is in offfice format and contains data as follows
____________(put in sample data here). I need to take this file and stick
its contents into a database. We are using _______(mysql,oracle...whichever
one you are using).



Thank you,

Jayanth
 
A

Anandh Kumar

Dear Jayanth and others
Thank you for your time.

In simpler terms, I am looking to implement a functionality where the
user of my application would upload a ODT document. My application has
to read the ODT document and write the fields in to some database. I
guess i need a gem which helps me to read the odt document here, writing
it into database is not a problem.

On the other hand, If there is no gem to read the ODT file, then i am
looking for a gem which can help me convert the ODT file in to xml file.
I am comfortable parsing the xml file and go further.

Summary: What do i need to know?
1. Is there a gem which helps me to read ODT file? Similarly is there
any gem available in linux (platform independent) to read MS doc file. I
am expecting my user to upload his document files from any OS and my
server to be running in any platform. I guess i am clear.

2. Is there any gem which can convert the ODT files in to xml file?

Thank you once again for your kind help.

Best Regards
Anandh
 
T

Tim Hunter

Hi everybody

      I've to parse the open office documents and upload it to the
database in ruby on rails and in linux platform. I've not found any gem
to accomplish that. Now i got a idea of converting the open office
documents to XML format and then to parse the XML content to finish up
with my task.

       Is it possible?

An OpenOffice document is a package of XML files zipped into a single
file. Change the .odt extension to .zip, unzip it, and you'll see.
 
J

James Britt

Tim said:
An OpenOffice document is a package of XML files zipped into a single
file. Change the .odt extension to .zip, unzip it, and you'll see.


Once upon a time I wrote a lib to manipulate OOo docs.

I ended up not using it as much as I expected, and eventually abandoned it.

The OOo doc format has since changed, so it's largely useless, but may
offer some ideas on how to manipulate OOo docs in general.'

http://ooo4r.rubyforge.org/

I also wrote about my OOo + Ruby experience for Linux Journal

http://www.linuxjournal.com/article/7236




--
James Britt

www.jamesbritt.com - Playing with Better Toys
www.ruby-doc.org - Ruby Help & Documentation
www.rubystuff.com - The Ruby Store for Ruby Stuff
www.neurogami.com - Smart application development
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top