Forum: Ruby Strange StringScanner behaviour

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.
Neowulf (Guest)
on 2005-12-22 11:41
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
Dan D. (Guest)
on 2005-12-22 11:50
(Received via mailing list)
>NameError: uninitialized constant StringScanner

  require 'strscan'
s = StringScanner.new("My test string")
Neowulf (Guest)
on 2005-12-22 14:44
(Received via mailing list)
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
James G. (Guest)
on 2005-12-22 15:56
(Received via mailing list)
On Dec 22, 2005, at 3:41 AM, Neowulf wrote:

> 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 G. II
Neowulf (Guest)
on 2005-12-22 16:36
(Received via mailing list)
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
Anandh K. (Guest)
on 2009-06-15 13:24
Hi everybody



    Can the Stringscanner be also used in linux and also can it be used
in parsing the entire open office documents... if so hhow can i call
that document...
Anandh K. (Guest)
on 2009-06-15 13:28
Anandh K. wrote:
>
> 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...
Anandh K. (Guest)
on 2009-06-16 10:56

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
Robert K. (Guest)
on 2009-06-16 12:19
(Received via mailing list)
2009/6/16 Anandh K. <removed_email_address@domain.invalid>:
>     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
Anandh K. (Guest)
on 2009-06-16 12:28
  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
kranthi reddy (Guest)
on 2009-06-16 13:17
(Received via mailing list)
Hey,
You can use LibXML-Ruby 1.1.2,  Hpricot or REXML for parsing the xml and
retrieving the data.

http://code.whytheluckystiff.net/doc/hpricot/ -Hpricot
http://www.ruby-doc.org/stdlib/libdoc/rexml/rdoc/index.html -REXML
http://libxml.rubyforge.org/rdoc/index.html -LibXML

From the above links you find the required information.




On Tue, Jun 16, 2009 at 1:58 PM, Anandh K.
Christopher D. (Guest)
on 2009-06-16 17:48
(Received via mailing list)
On Mon, Jun 15, 2009 at 11:56 PM, Anandh
Kumar<removed_email_address@domain.invalid> wrote:
>
>
> 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.

Isn't OOo's native format ODF, which is an XML format? So why do you
need to convert it to XML?
Anandh K. (Guest)
on 2009-06-16 17:56
I'm not exactly getting what you are trying to say. Can you please make
it clear.
Srijayanth S. (Guest)
on 2009-06-16 18:08
(Received via mailing list)
On Tue, Jun 16, 2009 at 7:26 PM, Anandh K.
<removed_email_address@domain.invalid>wrote:

> I'm not exactly getting what you are trying to say. Can you please make
> it clear.
> --
> Posted via http://www.ruby-forum.com/.
>
>
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
Anandh K. (Guest)
on 2009-06-16 19:16
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
Tim H. (Guest)
on 2009-06-16 20:27
(Received via mailing list)
On Jun 16, 2:56 am, Anandh K. <removed_email_address@domain.invalid> wrote:
> 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.
James B. (Guest)
on 2009-06-16 21:48
(Received via mailing list)
Tim H. wrote:
>
> 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 B.

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
This topic is locked and can not be replied to.