Hello,
I wonder if someone would be able to help.
Through necessity I'm learning Ruby and trying to write my own script
and while I am getting there and grasping things more, I'm still on
first rung of the ladder and finding things difficult so please be
patient
Part of my script involves opening a telnet session and then sending a
whois request that returns a lot of text ...
I've managed to get to the point where I have the reply stored in a
variable but what I would now like to do is parse the variable for bits
of the information and I have read and read but can't find something
that I seem to be able to understand.
I have attached a text file with the data that my variable holds and I
need to parse out things like the "Renewal date:" and "Registration
status:". Would anyone be able to offer me some help on how I should go
about parsing.
TIA
Warby
Attachments:
http://www.ruby-forum.com/attachment/4407/test.txt
路路路
--
Posted via http://www.ruby-forum.com/.
You should a bit about regular expressions. If the text has "simple"
rules, regexes are usually enough to extract the pieces of data you
need. In your case, for example:
irb(main):001:0> data =<<EOF
irb(main):002:0" Domain name:
irb(main):003:0" suburbia.co.uk
irb(main):004:0"
[...]
irb(main):053:0> m = data.match(/Renewal date:\s+(.*)/)
=> #<MatchData "Renewal date: 28-Oct-2009" 1:"28-Oct-2009">
irb(main):054:0> m[1]
=> "28-Oct-2009"
If your case is as simple as this, the above solution could be enough.
Hope this helps,
Jesus.
路路路
On Fri, Jan 22, 2010 at 12:32 PM, Sean Warburton <sean_warburton@yahoo.co.uk> wrote:
Hello,
I wonder if someone would be able to help.
Through necessity I'm learning Ruby and trying to write my own script
and while I am getting there and grasping things more, I'm still on
first rung of the ladder and finding things difficult so please be
patient
Part of my script involves opening a telnet session and then sending a
whois request that returns a lot of text ...
I've managed to get to the point where I have the reply stored in a
variable but what I would now like to do is parse the variable for bits
of the information and I have read and read but can't find something
that I seem to be able to understand.
I have attached a text file with the data that my variable holds and I
need to parse out things like the "Renewal date:" and "Registration
status:". Would anyone be able to offer me some help on how I should go
about parsing.
Hello,
I'm new to ruby/rails and am building out models right now.
My question is when extending a has_many attribute of a model as shown below does this cause 2 sequential sql selects, or just one?. Also I am wondering what methods are available on the result... i.e. are all the methods available to has_many available (such as length or clear) to the result of the sub method.
class Prospect < ActiveRecord::Base
has_many :invitations do
def of_campaign(campaign_id)
find :all, :conditions => ['campaign_id = ?', campaign_id]
end
end
end
#...some controller...
AProspect.invitations.of_campaign(1)...
#...
I'm pretty sure the above ruby executes: SELECT * FROM invitations WHERE prospect_id = # AND campaign_id = #
But I'm not sure if it also executes SELECT * FROM invitations WHERE prospect_id = #
Also, I'm not clear as to what methods would be available to the result of 'of_campaign'... would all the has_many methods like length and clear be available.
Thanks in advance for any help/clarification.
Jay Crouch
Thank you, I'll try your suggestion.
路路路
--
Posted via http://www.ruby-forum.com/.
Hello,
Hello!
First things first: A subject line isn't optional, but helps us in picking through the mails to find out what we can help with / are interested in.
I'm new to ruby/rails and am building out models right now.
Thanks in advance for any help/clarification.
Second, you'll have better luck on the Rails mailing lists:
While every Rails user uses Ruby, not every Ruby user uses Rails.
路路路
On 23.01.2010 02:02, Jay Crouch wrote:
--
Phillip Gawlowski