Pass data to a variable

Discussion in 'Ruby' started by Seth .., May 8, 2007.

  1. Seth ..

    Seth .. Guest

    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-forum.com/.
     
    Seth .., May 8, 2007
    #1
    1. Advertising

  2. Seth ..

    Charles Lowe Guest

    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-forum.com/.
     
    Charles Lowe, May 8, 2007
    #2
    1. Advertising

  3. Seth ..

    Chris Carter Guest

    On 5/8/07, 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?
    >
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >

    #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
     
    Chris Carter, May 8, 2007
    #3
  4. [ANN] - Ruby Patterns

    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.rubypatterns.org 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.rubypatterns.org
     
    Enrique Comba Riepenhausen, May 8, 2007
    #4
  5. Re: [ANN] - Ruby Patterns

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

    > Being so I just set up a web site http://www.rubypatterns.org 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/ExampleDesignPatternsInRuby

    James Edward Gray II
     
    James Edward Gray II, May 8, 2007
    #5
  6. Seth ..

    Robert Dober Guest

    Re: [ANN] - Ruby Patterns

    On 5/8/07, 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.rubypatterns.org 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/ExampleDesignPatternsInRuby
    >
    > 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
     
    Robert Dober, May 8, 2007
    #6
  7. Seth ..

    Phlip Guest

    Phlip, May 8, 2007
    #7
  8. Re: [ANN] - Ruby Patterns

    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.rubypatterns.org
    >> 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/ExampleDesignPatternsInRuby
    >
    > James Edward Gray II
    >
     
    Enrique Comba Riepenhausen, May 8, 2007
    #8
  9. Re: [ANN] - Ruby Patterns

    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 <> wrote:
    >> On May 8, 2007, at 6:58 AM, Enrique Comba Riepenhausen wrote:
    >>
    >> > Being so I just set up a web site http://www.rubypatterns.org 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/ExampleDesignPatternsInRuby
    >>
    >> 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, May 8, 2007
    #9
  10. Re: [ANN] - Ruby Patterns

    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.rubypatterns.org where

    >
    > Is it too late to switch to a Ruby wiki? Instead of PHP?
    >
    > --
    > Phlip
    > http://flea.sourceforge.net/PiglegToo_1.html
    >
    >
    >
     
    Enrique Comba Riepenhausen, May 8, 2007
    #10
  11. Seth ..

    Robert Dober Guest

    Re: [ANN] - Ruby Patterns

    On 5/8/07, Enrique Comba Riepenhausen <> 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
     
    Robert Dober, May 8, 2007
    #11
  12. Re: [ANN] - Ruby Patterns

    Why should we delete it?

    Actually I think that the block is a valid pattern specifically for
    the Ruby language!

    I really appreciate your input and I hope we can get this moving...

    Cheers,

    Enrique Comba Riepenhausen

    On 8 May 2007, at 15:02, Robert Dober wrote:

    > On 5/8/07, Enrique Comba Riepenhausen <> 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
    >
     
    Enrique Comba Riepenhausen, May 8, 2007
    #12
  13. Seth ..

    Robert Dober Guest

    Re: [ANN] - Ruby Patterns

    On 5/8/07, Enrique Comba Riepenhausen <> wrote:
    > Why should we delete it?

    Donnu I have difficulties to grasp the idea...
    >
    > Actually I think that the block is a valid pattern specifically for
    > the Ruby language!

    I guess so ;)
    >
    > I really appreciate your input and I hope we can get this moving...


    ... but maybe it will become clearer in the future.
    >
    > Cheers,

    Robert
     
    Robert Dober, May 8, 2007
    #13
  14. Seth ..

    Seth .. Guest

    Chris Carter wrote:

    > #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



    Holy crap! That's why I love this site. Thanks a million. I'm slowly
    learning Ruby but I've always been more of an admin than a developer.

    Thanks again

    --seth

    --
    Posted via http://www.ruby-forum.com/.
     
    Seth .., May 8, 2007
    #14
  15. Seth ..

    John Carter Guest

    Re: [ANN] - Ruby Patterns

    On Tue, 8 May 2007, Enrique Comba Riepenhausen wrote:
    > 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.


    Be warned that several Javarish design patterns become practically
    null ops in Ruby because...
    * Everything in Ruby, including and especially Classes are objects.
    * Everything in Ruby is open for extension at compile time.
    * The Ruby module / class structure is hackable at run time.

    Thus, especially the construction patterns from the GoF practically
    vanish into the background of ruby just doing what ruby does.

    So don't be disappointed when some of your Design Pattern translation
    efforts seem to give trivial results, that should be make you say Wow!
    Ruby is powerful!


    John Carter Phone : (64)(3) 358 6639
    Tait Electronics Fax : (64)(3) 359 4632
    PO Box 1645 Christchurch Email :
    New Zealand
     
    John Carter, May 8, 2007
    #15
  16. Re: [ANN] - Ruby Patterns

    > 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.


    That was Martin Fowler in "Refactoring."

    I just want to echo the sentiment that design patterns are less useful
    in Ruby than in Java or C. However, I'm not totally sure about that.
    It's definitely a popular view, and definitely true in some cases, but
    I'd stop short of dismissing the entire book. Some of the Gang of Four
    examples are in Smalltalk, not C, and some Smalltalkers say they
    consider Ruby to be a Unix dialect of Smalltalk. Some design patterns
    break down into about a line and a half of Ruby, Decorator I think
    being a good example, but really you should view "Design Patterns" as
    a set of tools whose usefulness varies by language. I think the
    Flyweight pattern is probably useful in any language, it seems more a
    sanity preservation device than anything else. Could be wrong though.

    --
    Giles Bowkett
    http://www.gilesgoatboy.org
    http://gilesbowkett.blogspot.com
    http://giles.tumblr.com/
     
    Giles Bowkett, May 9, 2007
    #16
  17. Re: [ANN] - Ruby Patterns

    Another take on Ruby Patterns - you might be better off looking for
    Ruby **idioms**. Programming Java and programming Ruby can be very
    different experiences, and it's always good to approach a new topic
    with the mind of a beginner. Techniques that would be impossible or
    insane in Java are sometimes the best way to do something in Ruby.

    --
    Giles Bowkett
    http://www.gilesgoatboy.org
    http://gilesbowkett.blogspot.com
    http://giles.tumblr.com/
     
    Giles Bowkett, May 9, 2007
    #17
  18. Seth ..

    John Carter Guest

    Re: [ANN] - Ruby Patterns

    On Wed, 9 May 2007, Giles Bowkett wrote:

    > I think the Flyweight pattern is probably useful in any language, it
    > seems more a sanity preservation device than anything else. Could be
    > wrong though.


    I cannot resist...

    :just_a_symbol_of_its_usefulness



    John Carter Phone : (64)(3) 358 6639
    Tait Electronics Fax : (64)(3) 359 4632
    PO Box 1645 Christchurch Email :
    New Zealand
     
    John Carter, May 9, 2007
    #18
  19. Re: [ANN] - Ruby Patterns

    Hi John!

    Thanks for the warnings ;)

    Actually I am not only trying to translate the GoF patterns into
    Ruby, there are zillions of different patterns...

    "Each pattern is a three-part rule, which expresses a relation
    between a certain context, a problem, and a solution." as Christopher
    Alexander says.

    And I don't believe that this cases don't apply for Ruby, they just
    do it in a different way. If you take the creational patterns in GoF
    they might be differences in the implementation, but the problems
    still exists...

    I will not be disappointed ;) Ruby is powerful! But with any language
    in the world you can use it wrong and lose most of it's power...

    Cheers,

    Enrique Comba Riepenhausen

    On 9 May 2007, at 00:27, John Carter wrote:

    > On Tue, 8 May 2007, Enrique Comba Riepenhausen wrote:
    >> 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.

    >
    > Be warned that several Javarish design patterns become practically
    > null ops in Ruby because...
    > * Everything in Ruby, including and especially Classes are objects.
    > * Everything in Ruby is open for extension at compile time.
    > * The Ruby module / class structure is hackable at run time.
    >
    > Thus, especially the construction patterns from the GoF practically
    > vanish into the background of ruby just doing what ruby does.
    >
    > So don't be disappointed when some of your Design Pattern translation
    > efforts seem to give trivial results, that should be make you say Wow!
    > Ruby is powerful!
    >
    >
    > John Carter Phone : (64)(3) 358 6639
    > Tait Electronics Fax : (64)(3) 359 4632
    > PO Box 1645 Christchurch Email :
    > New Zealand
    >
    >
     
    Enrique Comba Riepenhausen, May 9, 2007
    #19
  20. Re: [ANN] - Ruby Patterns

    Completely agree with you, still patterns solve a problem in a given
    context and obviously (if we are talking about developing software)
    in different languages. I don't believe this problems don't exist
    just because the language is called Ruby or Java or any other name...

    The main idea is to capture the essence of the language and to see
    which patterns apply in with way in the language. I posted an
    implementation of the Factory Method yesterday in the pattern
    catalogue and I made it (on purpose and maybe a bit of lack in Ruby
    experience) as it is described in the book. I am sure there is a
    Ruby way to do exactly that in a nicer, more elegant way, but exactly
    that is what I want to achieve. I would love that people can see the
    AHA, WOW. In the book (or other languages) this seemed so difficult
    and in Ruby I can do this in a bliss... :)

    Cheers,

    Enrique Comba Riepenhausen

    On 9 May 2007, at 04:21, Giles Bowkett wrote:

    > Another take on Ruby Patterns - you might be better off looking for
    > Ruby **idioms**. Programming Java and programming Ruby can be very
    > different experiences, and it's always good to approach a new topic
    > with the mind of a beginner. Techniques that would be impossible or
    > insane in Java are sometimes the best way to do something in Ruby.
    >
    > --
    > Giles Bowkett
    > http://www.gilesgoatboy.org
    > http://gilesbowkett.blogspot.com
    > http://giles.tumblr.com/
    >
     
    Enrique Comba Riepenhausen, May 9, 2007
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. weiwei

    pass variable in data grid view

    weiwei, Mar 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,886
    weiwei
    Mar 20, 2006
  2. Ben Kial
    Replies:
    1
    Views:
    676
    Eric Enright
    Nov 15, 2004
  3. Tricky
    Replies:
    0
    Views:
    591
    Tricky
    Mar 19, 2009
  4. Tricky
    Replies:
    0
    Views:
    1,026
    Tricky
    Mar 19, 2009
  5. Reuven
    Replies:
    0
    Views:
    604
    Reuven
    Mar 19, 2009
Loading...

Share This Page