Class: HTML::Proofer::Checkable
- Inherits:
-
Object
- Object
- HTML::Proofer::Checkable
- Defined in:
- lib/html/proofer/checkable.rb
Instance Method Summary collapse
- #absolute_path ⇒ Object
-
#exists? ⇒ Boolean
checks if a file exists relative to the current pwd.
-
#external? ⇒ Boolean
path is external to the file.
- #file_path ⇒ Object
- #hash ⇒ Object
- #ignore? ⇒ Boolean
-
#initialize(obj, check) ⇒ Checkable
constructor
A new instance of Checkable.
-
#internal? ⇒ Boolean
path is an anchor.
- #parts ⇒ Object
- #path ⇒ Object
-
#remote? ⇒ Boolean
path is to an external server.
- #url ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(obj, check) ⇒ Checkable
Returns a new instance of Checkable.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/html/proofer/checkable.rb', line 5 def initialize(obj, check) @src = obj['src'] @href = obj['href'] @alt = obj['alt'] @name = obj['name'] @id = obj['id'] @check = check if @href && @check.[:href_swap] [:href_swap].each do |link, replace| @href = @href.gsub(link, replace) end end end |
Instance Method Details
#absolute_path ⇒ Object
99 100 101 102 |
# File 'lib/html/proofer/checkable.rb', line 99 def absolute_path path = file_path || @check.path File. path, Dir.pwd end |
#exists? ⇒ Boolean
checks if a file exists relative to the current pwd
95 96 97 |
# File 'lib/html/proofer/checkable.rb', line 95 def exists? File.exist? absolute_path end |
#external? ⇒ Boolean
path is external to the file
65 66 67 |
# File 'lib/html/proofer/checkable.rb', line 65 def external? !internal? end |
#file_path ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/html/proofer/checkable.rb', line 74 def file_path return if path.nil? if path =~ /^\// #path relative to root base = @check.src elsif File.exist? File. path, @check.src #relative links, path is a file base = File.dirname @check.path else #relative link, path is a directory base = @check.path end file = File.join base, path # implicit /index.html support, with support for tailing slashes file = File.join path, "index.html" if File.directory? File. file, @check.src file end |
#hash ⇒ Object
41 42 43 |
# File 'lib/html/proofer/checkable.rb', line 41 def hash parts.fragment end |
#ignore? ⇒ Boolean
55 56 57 58 59 60 61 62 |
# File 'lib/html/proofer/checkable.rb', line 55 def ignore? uri = URI.parse url %w( mailto ).include?(uri.scheme) || @check.additional_href_ignores.include?(href) rescue URI::BadURIError false rescue URI::InvalidURIError false end |
#internal? ⇒ Boolean
path is an anchor
70 71 72 |
# File 'lib/html/proofer/checkable.rb', line 70 def internal? url[0] == "#" end |
#parts ⇒ Object
33 34 35 |
# File 'lib/html/proofer/checkable.rb', line 33 def parts URI.parse url end |
#path ⇒ Object
37 38 39 |
# File 'lib/html/proofer/checkable.rb', line 37 def path parts.path end |
#remote? ⇒ Boolean
path is to an external server
46 47 48 49 50 51 52 53 |
# File 'lib/html/proofer/checkable.rb', line 46 def remote? uri = URI.parse url %w( http https ).include?(uri.scheme) rescue URI::BadURIError false rescue URI::InvalidURIError false end |
#url ⇒ Object
21 22 23 |
# File 'lib/html/proofer/checkable.rb', line 21 def url @src || @href || "" end |
#valid? ⇒ Boolean
25 26 27 28 29 30 31 |
# File 'lib/html/proofer/checkable.rb', line 25 def valid? begin URI.parse url rescue false end end |