Class: Wrxer::Coercion

Inherits:
Object
  • Object
show all
Defined in:
lib/wrxer/coercion.rb

Class Method Summary collapse

Class Method Details

.call(document, params = {}) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/wrxer/coercion.rb', line 7

def self.call(document, params = {})
  root = @xpath || params[:xpath]
  unless document.name == root
    document = document.at_xpath(root)
  end

  document.nil? ? nil : self.coerce(document)
end

.coerce(document) ⇒ Object



16
17
18
# File 'lib/wrxer/coercion.rb', line 16

def self.coerce(document)
  self.new(document)
end

.xpath(value) ⇒ Object



3
4
5
# File 'lib/wrxer/coercion.rb', line 3

def self.xpath(value)
  @xpath = value
end