class Capybara::Email::Driver
Attributes
email[R]
Public Class Methods
new(email)
click to toggle source
# File lib/capybara/email/driver.rb, line 4 def initialize(email) @email = email end
Public Instance Methods
body()
click to toggle source
# File lib/capybara/email/driver.rb, line 16 def body dom.to_xml end
dom()
click to toggle source
Nokogiri object for traversing content
@return Nokogiri::HTML::Document
# File lib/capybara/email/driver.rb, line 23 def dom @dom ||= Nokogiri::HTML(source) end
find(selector)
click to toggle source
Find elements based on given xpath
@param [xpath string]
@return [Array<Capybara::Driver::Node>]
# File lib/capybara/email/driver.rb, line 32 def find(selector) dom.xpath(selector).map { |node| Capybara::Email::Node.new(self, node) } end
Also aliased as: find_xpath
find_css(selector)
click to toggle source
# File lib/capybara/email/driver.rb, line 38 def find_css(selector) dom.css(selector).map { |node| Capybara::Email::Node.new(self, node) } end
follow(url)
click to toggle source
# File lib/capybara/email/driver.rb, line 8 def follow(url) url = URI.parse(url) host = "#{url.scheme}://#{url.host}" host << ":#{url.port}" unless url.port == url.default_port host_with_path = File.join(host, url.path) Capybara.current_session.visit([host_with_path, url.query].compact.join('?')) end
raw()
click to toggle source
Plain text email contents
@return String
# File lib/capybara/email/driver.rb, line 56 def raw if email.mime_type =~ /\Amultipart\/(alternative|related|mixed)\Z/ if email.html_part return email.html_part.body.to_s elsif email.text_part return email.text_part.body.to_s end end return email.body.to_s end
source()
click to toggle source
String version of email HTML source
@return String
# File lib/capybara/email/driver.rb, line 45 def source if email.mime_type == 'text/plain' convert_to_html(raw) else raw end end
Private Instance Methods
convert_links(text)
click to toggle source
# File lib/capybara/email/driver.rb, line 86 def convert_links(text) text.gsub(%r{(https?://\S+)}, %q{<a href="\1">\1</a>}) end
convert_to_html(text)
click to toggle source
# File lib/capybara/email/driver.rb, line 82 def convert_to_html(text) "<html><body>#{convert_links(text)}</body></html>" end
method_missing(meth, *args, &block)
click to toggle source
Calls superclass method
# File lib/capybara/email/driver.rb, line 70 def method_missing(meth, *args, &block) if email.respond_to?(meth) if args.empty? email.send(meth) else email.send(meth, args) end else super end end