Class: Reaxar::Element::A
- Inherits:
-
Object
- Object
- Reaxar::Element::A
- Defined in:
- lib/reaxar/element/a.rb
Overview
Represents an HTML anchor (‘<a>`) element on a page.
Instance Attribute Summary collapse
-
#element ⇒ Nokogiri::XML::Element
readonly
The underlying Nokogiri element.
-
#page ⇒ Reaxar::Page
readonly
The page this element belongs to.
Instance Method Summary collapse
-
#click {|page| ... } ⇒ Async::Task
Opens the link in a new page context.
-
#href ⇒ String
Returns the absolute URL for the link.
-
#initialize(element, page) ⇒ A
constructor
Initializes a new anchor element wrapper.
Constructor Details
#initialize(element, page) ⇒ A
Initializes a new anchor element wrapper.
22 23 24 25 |
# File 'lib/reaxar/element/a.rb', line 22 def initialize(element, page) @element = element @page = page end |
Instance Attribute Details
#element ⇒ Nokogiri::XML::Element (readonly)
Returns The underlying Nokogiri element.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/reaxar/element/a.rb', line 16 class A attr_reader :element, :page # Initializes a new anchor element wrapper. # @param element [Nokogiri::XML::Element] The Nokogiri element. # @param page [Reaxar::Page] The parent page. def initialize(element, page) @element = element @page = page end # Returns the absolute URL for the link. # @return [String] The resolved href attribute. def href URI.join(page.url, element[:href]).to_s end # Opens the link in a new page context. # @yield [page] Optional block with the new page instance. # @return [Async::Task] The async task wrapping the new page. def click(&block) Page.open(href, page.client, &block) end end |
#page ⇒ Reaxar::Page (readonly)
Returns The page this element belongs to.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/reaxar/element/a.rb', line 16 class A attr_reader :element, :page # Initializes a new anchor element wrapper. # @param element [Nokogiri::XML::Element] The Nokogiri element. # @param page [Reaxar::Page] The parent page. def initialize(element, page) @element = element @page = page end # Returns the absolute URL for the link. # @return [String] The resolved href attribute. def href URI.join(page.url, element[:href]).to_s end # Opens the link in a new page context. # @yield [page] Optional block with the new page instance. # @return [Async::Task] The async task wrapping the new page. def click(&block) Page.open(href, page.client, &block) end end |
Instance Method Details
#click {|page| ... } ⇒ Async::Task
Opens the link in a new page context.
36 37 38 |
# File 'lib/reaxar/element/a.rb', line 36 def click(&block) Page.open(href, page.client, &block) end |
#href ⇒ String
Returns the absolute URL for the link.
29 30 31 |
# File 'lib/reaxar/element/a.rb', line 29 def href URI.join(page.url, element[:href]).to_s end |