add runtime error
parent
cbcf025c33
commit
71b97b6a38
|
@ -2,6 +2,7 @@ require "./mechanize/http/agent"
|
|||
require "./mechanize/form"
|
||||
require "./mechanize/node"
|
||||
require "./mechanize/page"
|
||||
require "./mechanize/errors/*"
|
||||
|
||||
class Mechanize
|
||||
VERSION = "0.1.0"
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
# Base Error class
|
||||
class MechanizeCr::Error < RuntimeError
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
require "./base_error"
|
||||
class MechanizeCr::ElementNotFoundError < MechanizeCr::Error
|
||||
getter element : Symbol
|
||||
getter conditions : String
|
||||
|
||||
def initialize(element, conditions)
|
||||
@element = element
|
||||
@conditions = conditions
|
||||
|
||||
super "Element #{element} with conditions #{conditions} was not found"
|
||||
end
|
||||
|
||||
end
|
|
@ -72,15 +72,17 @@ class MechanizeCr::Form
|
|||
# TODO
|
||||
# when args whose type isn't String is given
|
||||
end
|
||||
fields.select do |field|
|
||||
f = fields.select do |field|
|
||||
value.all? do |k,v|
|
||||
v === field.name
|
||||
end
|
||||
end
|
||||
f.empty? ? nil : f
|
||||
end
|
||||
|
||||
def field_with(criteria)
|
||||
f = fields_with(criteria)
|
||||
f.empty? ? Array(MechanizeCr::FormContent::Field).new : f.first
|
||||
raise MechanizeCr::ElementNotFoundError.new(:field, criteria) if f.nil?
|
||||
f.first
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue