Extracting AreaLocator object
This commit is contained in:
parent
2e69cb1911
commit
9e030a1b05
|
@ -106,16 +106,9 @@ module Webrat
|
|||
end
|
||||
|
||||
def find_area(id_or_title) #:nodoc:
|
||||
area_elements = Webrat::XML.css_search(dom, "area")
|
||||
require "webrat/core/locators/area_locator"
|
||||
|
||||
matcher = /#{Regexp.escape(id_or_title.to_s)}/i
|
||||
|
||||
area_element = area_elements.detect do |area_element|
|
||||
Webrat::XML.attribute(area_element, "title") =~ matcher ||
|
||||
Webrat::XML.attribute(area_element, "id") =~ matcher
|
||||
end
|
||||
|
||||
area_by_element(area_element) ||
|
||||
AreaLocator.new(self, id_or_title).locate ||
|
||||
raise(NotFoundError.new("Could not find area with name #{id_or_title}"))
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
class AreaLocator
|
||||
|
||||
def initialize(scope, value)
|
||||
@scope = scope
|
||||
@value = value
|
||||
end
|
||||
|
||||
def locate
|
||||
@scope.area_by_element(area_element)
|
||||
end
|
||||
|
||||
def area_element
|
||||
area_elements.detect do |area_element|
|
||||
Webrat::XML.attribute(area_element, "title") =~ matcher ||
|
||||
Webrat::XML.attribute(area_element, "id") =~ matcher
|
||||
end
|
||||
end
|
||||
|
||||
def matcher
|
||||
/#{Regexp.escape(@value.to_s)}/i
|
||||
end
|
||||
|
||||
def area_elements
|
||||
Webrat::XML.css_search(@scope.dom, "area")
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue