Extracting AreaLocator object
This commit is contained in:
parent
2e69cb1911
commit
9e030a1b05
@ -106,16 +106,9 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def find_area(id_or_title) #:nodoc:
|
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
|
AreaLocator.new(self, id_or_title).locate ||
|
||||||
|
|
||||||
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) ||
|
|
||||||
raise(NotFoundError.new("Could not find area with name #{id_or_title}"))
|
raise(NotFoundError.new("Could not find area with name #{id_or_title}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
27
lib/webrat/core/locators/area_locator.rb
Normal file
27
lib/webrat/core/locators/area_locator.rb
Normal file
@ -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
Block a user