[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Pass data to a variable

Seth Doe

5/8/2007 8:17:00 AM

Hello,

I've create a simple screen scraper which sends a message to a Jabber
client for notification. The scraper portion works as does the Jabber
portion but I'm having trouble passing the data from the scraper to the
Jabber client.

Here's what gets all the data in the scraper portion


link.search("//font[@class='hosts']").each do |host|

host.to_html.match(/[a-z]+[0-9]*\.(foo|bar)\.[a-z]+/)

end

I then have Jabber setup as follows

cl = Client::new(myJID, false)
cl.connect
cl.auth(myPassword)
m = Message::new(to,
body).set_type(:normal).set_id('1').set_subject(subject)
cl.send(m)
cl.close

I somehow have to get the data into the body variable. Any ideas?

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

19 Answers

Charles L.

5/8/2007 11:37:00 AM

0

Seth .. wrote:
> Hello,
>
> I've create a simple screen scraper which sends a message to a Jabber
> client for notification. The scraper portion works as does the Jabber
> portion but I'm having trouble passing the data from the scraper to the
> Jabber client.
>
> Here's what gets all the data in the scraper portion
>
>
> link.search("//font[@class='hosts']").each do |host|
>
> host.to_html.match(/[a-z]+[0-9]*\.(foo|bar)\.[a-z]+/)
>
> end
>
> I then have Jabber setup as follows
>
> cl = Client::new(myJID, false)
> cl.connect
> cl.auth(myPassword)
> m = Message::new(to,
> body).set_type(:normal).set_id('1').set_subject(subject)
> cl.send(m)
> cl.close
>
> I somehow have to get the data into the body variable. Any ideas?

Not quite sure if I understand the question, but you can pass any
arbitrary ruby object as the text body by serializing it using YAML. ie:

require 'yaml'

body = hosts.to_yaml
m = Message::new(to, body).....


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

Chris Carter

5/8/2007 11:47:00 AM

0

On 5/8/07, Seth .. <seth@animejunkie.org> wrote:
> Hello,
>
> I've create a simple screen scraper which sends a message to a Jabber
> client for notification. The scraper portion works as does the Jabber
> portion but I'm having trouble passing the data from the scraper to the
> Jabber client.
>
> Here's what gets all the data in the scraper portion
>
>
> link.search("//font[@class='hosts']").each do |host|
>
> host.to_html.match(/[a-z]+[0-9]*\.(foo|bar)\.[a-z]+/)
>
> end
>
> I then have Jabber setup as follows
>
> cl = Client::new(myJID, false)
> cl.connect
> cl.auth(myPassword)
> m = Message::new(to,
> body).set_type(:normal).set_id('1').set_subject(subject)
> cl.send(m)
> cl.close
>
> I somehow have to get the data into the body variable. Any ideas?
>
> --
> Posted via http://www.ruby-....
>
>
#map and #to_yaml should do it

body = link.search("//font[@class='hosts']").map do |host|
host.to_html.match(/[a-z]+[0-9]*\.(foo|bar)\.[a-z]+/)
end.to_yaml


--
Chris Carter
concentrationstudios.com
brynmawrcs.com

Enrique Comba Riepenhausen

5/8/2007 11:59:00 AM

0

Hi everyone!

I have recently joined this group to see what things are being
discussed Ruby. And I have to say that there is a lot of interesting
information shared in this group!

I come from a Java environment (have been coding in Java for the past
11 years) and I must admit that I was amazed by Ruby when I stumbled
onto it not long ago.

One of my hobbies has always been the study of design patterns,
refactoring, etc... And in general the way we can improve code to
make it more maintainable, etc.

A sentence comes into my mind on this:

Any fool can write code that a computer understands, it takes a good
developer to write code that a human being understands

I think it was Kent Beck who said this... Not sure though.

Anyway, Ruby, as far as I can tell really adapts to this words pretty
well and I consider it a fantastic OO language.

Being so I just set up a web site http://www.rubypa... where I
hope we can all share pattern knowledge in Ruby. It is a wiki and be
warned, there is no content at all there yet. Just a blank page to be
edited by anyone so that we can start a pattern catalogue for all the
Ruby developers out there...

Well, I hope you like the idea!

Best regards,

Enrique Comba Riepenhausen
http://www.rubypa...

James Gray

5/8/2007 12:04:00 PM

0

On May 8, 2007, at 6:58 AM, Enrique Comba Riepenhausen wrote:

> Being so I just set up a web site http://www.rubypa... where
> I hope we can all share pattern knowledge in Ruby. It is a wiki and
> be warned, there is no content at all there yet. Just a blank page
> to be edited by anyone so that we can start a pattern catalogue for
> all the Ruby developers out there...

Just FYI:

http://wiki.rubygarden.org/Ruby/page/show/ExampleDesignPatt...

James Edward Gray II

Robert Dober

5/8/2007 12:24:00 PM

0

On 5/8/07, James Edward Gray II <james@grayproductions.net> wrote:
> On May 8, 2007, at 6:58 AM, Enrique Comba Riepenhausen wrote:
>
> > Being so I just set up a web site http://www.rubypa... where
> > I hope we can all share pattern knowledge in Ruby. It is a wiki and
> > be warned, there is no content at all there yet. Just a blank page
> > to be edited by anyone so that we can start a pattern catalogue for
> > all the Ruby developers out there...
>
> Just FYI:
>
> http://wiki.rubygarden.org/Ruby/page/show/ExampleDesignPatt...
>
> James Edward Gray II
>
>
Enrique
I just left my footprints on your Wiki, but I did not understand
"pattern" in the strict sense of "Design Patterns".
I strongly believe that Design Patterns are not related to specific languages.
[That does not mean at all that it is not interesting to see how you
implement them best in Ruby, just that I did not interpret your idea
as such]

Cheers
Robert

--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

Phlip

5/8/2007 12:24:00 PM

0

> Being so I just set up a web site http://www.rubypa... where

Is it too late to switch to a Ruby wiki? Instead of PHP?

--
Phlip
http://flea.sourceforge.net/Pigleg...


Enrique Comba Riepenhausen

5/8/2007 12:31:00 PM

0

Thanks for the link!

;)

On 8 May 2007, at 14:04, James Edward Gray II wrote:

> On May 8, 2007, at 6:58 AM, Enrique Comba Riepenhausen wrote:
>
>> Being so I just set up a web site http://www.rubypa...
>> where I hope we can all share pattern knowledge in Ruby. It is a
>> wiki and be warned, there is no content at all there yet. Just a
>> blank page to be edited by anyone so that we can start a pattern
>> catalogue for all the Ruby developers out there...
>
> Just FYI:
>
> http://wiki.rubygarden.org/Ruby/page/show/ExampleDesignPatt...
>
> James Edward Gray II
>


Enrique Comba Riepenhausen

5/8/2007 12:35:00 PM

0

Hey Robert,

you are absolutely right with the statement that a design pattern is
language independent, still the way to implement a specific design
pattern differs from language to language...

Take the Observer for example. In Java for instance no one would
think to implement this pattern from scratch (unless there is a very
specific need not covered by the language) as it is available in the
language (aka Observer and Observable).

I do strongly believe that we would profit in general by a body of
knowledge in Ruby Patterns as there might be even patterns that only
apply to Ruby development... and for those patterns that are commonly
known (Visitor, Strategy, Factory Method, etc) we still can build
some advice for other novice developers that need advice...

Thanks a lot for your input!

Cheers,

Enrique Comba Riepenhausen

On 8 May 2007, at 14:23, Robert Dober wrote:

> On 5/8/07, James Edward Gray II <james@grayproductions.net> wrote:
>> On May 8, 2007, at 6:58 AM, Enrique Comba Riepenhausen wrote:
>>
>> > Being so I just set up a web site http://www.rubypa... where
>> > I hope we can all share pattern knowledge in Ruby. It is a wiki and
>> > be warned, there is no content at all there yet. Just a blank page
>> > to be edited by anyone so that we can start a pattern catalogue for
>> > all the Ruby developers out there...
>>
>> Just FYI:
>>
>> http://wiki.rubygarden.org/Ruby/page/show/ExampleDesignPatt...
>>
>> James Edward Gray II
>>
>>
> Enrique
> I just left my footprints on your Wiki, but I did not understand
> "pattern" in the strict sense of "Design Patterns".
> I strongly believe that Design Patterns are not related to specific
> languages.
> [That does not mean at all that it is not interesting to see how you
> implement them best in Ruby, just that I did not interpret your idea
> as such]
>
> Cheers
> Robert
>
> --
> You see things; and you say Why?
> But I dream things that never were; and I say Why not?
> -- George Bernard Shaw
>


Enrique Comba Riepenhausen

5/8/2007 12:39:00 PM

0

Hey Philip,

well, it is never to late ;)

I just wanted to start this and see what happens, but definitely we
can look forward to change to a Ruby wiki :)

Cheers,

Enrique Comba Riepenhausen

On 8 May 2007, at 14:25, Phlip wrote:

>> Being so I just set up a web site http://www.rubypa... where
>
> Is it too late to switch to a Ruby wiki? Instead of PHP?
>
> --
> Phlip
> http://flea.sourceforge.net/Pigleg...
>
>
>


Robert Dober

5/8/2007 1:02:00 PM

0

On 5/8/07, Enrique Comba Riepenhausen <ecomba@mac.com> wrote:
> Hey Robert,
>
> you are absolutely right with the statement that a design pattern is
> language independent, still the way to implement a specific design
> pattern differs from language to language...
>
> Take the Observer for example. In Java for instance no one would
> think to implement this pattern from scratch (unless there is a very
> specific need not covered by the language) as it is available in the
> language (aka Observer and Observable).
>
> I do strongly believe that we would profit in general by a body of
> knowledge in Ruby Patterns as there might be even patterns that only
> apply to Ruby development... and for those patterns that are commonly
> known (Visitor, Strategy, Factory Method, etc) we still can build
> some advice for other novice developers that need advice...
>
> Thanks a lot for your input!
>
> Cheers,
Sure I did not say the contrary, go ahead and delete my entry about
blocks or I can do it myself if you are busy.

Cheers
Robert
>
> Enrique Comba Riepenhausen


--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw