class Spreewald::Steps::FollowTheLink
Constants
- URL_PATTERN
Public Class Methods
new(mail, index_in_words)
click to toggle source
# File lib/steps/follow_the_link.rb, line 20 def initialize(mail, index_in_words) @mail = mail @index_in_words = index_in_words end
Public Instance Methods
run()
click to toggle source
# File lib/steps/follow_the_link.rb, line 25 def run index = { nil => 0, 'first' => 0, 'second' => 1, 'third' => 2 }[@index_in_words] paths = if @mail.html_part || body_text_html? search_for_links_in_html else search_for_links_in_plaintext end if paths[index] visit_path paths[index] else raise NoVisitableLinkFound.new(paths, @index_in_words) unless paths[index] end end
Private Instance Methods
body_text_html?()
click to toggle source
# File lib/steps/follow_the_link.rb, line 47 def body_text_html? @mail.body.to_s.include? "<html>" end
search_for_links_in_html()
click to toggle source
# File lib/steps/follow_the_link.rb, line 51 def search_for_links_in_html body = @mail.html_part ? @mail.html_part.body : @mail.body dom = Nokogiri::HTML(body.to_s) (dom / 'a[href]').map { |a| a['href'].match(URL_PATTERN) }.compact.map { |match| match[1] } end
search_for_links_in_plaintext()
click to toggle source
# File lib/steps/follow_the_link.rb, line 57 def search_for_links_in_plaintext mail_body = MailFinder.email_text_body(@mail).to_s mail_body.scan(URL_PATTERN).flatten(1) end
visit_path(path)
click to toggle source
# File lib/steps/follow_the_link.rb, line 43 def visit_path(path) Capybara.visit(path) end