Class: ValidatePage
- Inherits:
-
Object
- Object
- ValidatePage
- Includes:
- Capybara::DSL
- Defined in:
- lib/validate_page.rb
Constant Summary collapse
- @@parser =
nil
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.on(attrib, content, message) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/validate_page.rb', line 19 def self.on(attrib, content, ) @@attrib = attrib @@content = content @@message = return self end |
.set_parser(name) ⇒ Object
11 12 13 |
# File 'lib/validate_page.rb', line 11 def self.set_parser(name) @@parser = name end |
.validator ⇒ Object
15 16 17 |
# File 'lib/validate_page.rb', line 15 def self.validator @@parser end |
Instance Method Details
#present(url) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/validate_page.rb', line 32 def present(url) if @@parser == :text_parser page = Net::HTTP.get_response(URI.parse(url)).response.body @@content.split(/[;,\s\.]+/).any?{|c| page.include?(c)} else uri = URI.parse(url.chomp) Capybara.app_host = uri.scheme + '://' + uri.host visit uri.path @@content.split(/[;,\s\.]+/).any?{|c| page.has_text?(c)} end end |
#validate(record) ⇒ Object
26 27 28 29 30 |
# File 'lib/validate_page.rb', line 26 def validate(record) if(present record[@@attrib]) record.errors.add @@attrib, (@@message.present? ? @@message : 'page contains inappropriate content') end end |