Class: Capybara::Email::Driver
- Inherits:
-
Driver::Base
- Object
- Driver::Base
- Capybara::Email::Driver
- Defined in:
- lib/capybara/email/driver.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
Instance Method Summary collapse
- #body ⇒ Object
-
#dom ⇒ Object
Nokogiri object for traversing content.
-
#find(selector) ⇒ Array<Capybara::Driver::Node>
(also: #find_xpath)
Find elements based on given xpath.
- #find_css(selector) ⇒ Object
- #follow(url) ⇒ Object
-
#initialize(email) ⇒ Driver
constructor
A new instance of Driver.
-
#raw ⇒ Object
Plain text email contents.
-
#source ⇒ Object
String version of email HTML source.
Constructor Details
#initialize(email) ⇒ Driver
Returns a new instance of Driver.
4 5 6 |
# File 'lib/capybara/email/driver.rb', line 4 def initialize(email) @email = email end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object (private)
70 71 72 73 74 75 76 77 78 79 80 |
# 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 |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
2 3 4 |
# File 'lib/capybara/email/driver.rb', line 2 def email @email end |
Instance Method Details
#body ⇒ Object
16 17 18 |
# File 'lib/capybara/email/driver.rb', line 16 def body dom.to_xml end |
#dom ⇒ Object
Nokogiri object for traversing content
23 24 25 |
# File 'lib/capybara/email/driver.rb', line 23 def dom @dom ||= Nokogiri::HTML(source) end |
#find(selector) ⇒ Array<Capybara::Driver::Node> Also known as: find_xpath
Find elements based on given xpath
32 33 34 |
# File 'lib/capybara/email/driver.rb', line 32 def find(selector) dom.xpath(selector).map { |node| Capybara::Email::Node.new(self, node) } end |
#find_css(selector) ⇒ Object
38 39 40 |
# 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) ⇒ Object
8 9 10 11 12 13 14 |
# 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 ⇒ Object
Plain text email contents
56 57 58 59 60 61 62 63 64 65 66 |
# 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 ⇒ Object
String version of email HTML source
45 46 47 48 49 50 51 |
# File 'lib/capybara/email/driver.rb', line 45 def source if email.mime_type == 'text/plain' convert_to_html(raw) else raw end end |