Choosing a URI from a colon to avoid this?

I have the following function below that usually spits out a url like path.com/p/12345 .

Sometimes, when a tweet contains a colon before a tweet, for example

RT: something path.com/p/123

function will return:

 personName: path.com/p/12345 

My function:

 $a = 10 def grabTweets() tweet = Twitter.search("[pic] "+" path.com/p/", :rpp => $a, :result_type => "recent").map do |status| tweet = "#{status.text}" #class = string urls = URI::extract(tweet) #returns an array of strings end end 

My goal is to find any tweet with a colon before the url and remove this result from the loop so that it does not return to the created array.

+4
source share
1 answer

You can only select HTTP URLs:

 URI.extract("RT: Something http://path.com/p/123") # => ["RT:", "http://path.com/p/123"] URI.extract("RT: Something http://path.com/p/123", "http") # => ["http://path.com/p/123"] 

Your method can also be cleaned up quite a bit, you have many redundant local variables:

 def grabTweets Twitter.search("[pic] "+" path.com/p/", :rpp => $a, :result_type => "recent").map do |status| URI.extract(status.text, "http") end end 

I also want to strongly discourage the use of the global variable ( $a ).

+3
source

Source: https://habr.com/ru/post/1394725/


All Articles