Class: Bot
- Inherits:
-
Object
- Object
- Bot
- Defined in:
- lib/simple-bot.rb
Instance Method Summary collapse
- #create_bot ⇒ Object
- #grab_all_links ⇒ Object
-
#initialize(*args) ⇒ Bot
constructor
A new instance of Bot.
Constructor Details
#initialize(*args) ⇒ Bot
Returns a new instance of Bot.
11 12 13 14 15 16 |
# File 'lib/simple-bot.rb', line 11 def initialize *args args.each do |a| @url = a.to_s if a =~ /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix end create_bot end |
Instance Method Details
#create_bot ⇒ Object
18 19 20 21 |
# File 'lib/simple-bot.rb', line 18 def create_bot @agent = Mechanize.new @agent.get(@url) end |
#grab_all_links ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/simple-bot.rb', line 23 def grab_all_links @all_news_links = [] @agent.page.parser.css('a').each do |link| @all_news_links << {text: link.text, url: link['href']} if (link['href'] =~ /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix) end return @all_news_links end |