Class: Gort::PathRule Abstract
Overview
This class is abstract.
A rule that matches a path and query string.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Rule
Formatting Methods collapse
-
#inspect ⇒ String
A human readable representation of the rule.
-
#pretty_print(pp) ⇒ void
Produces a pretty human readable representation of the rule.
Instance Method Summary collapse
-
#match(path_and_query) ⇒ nil, (Integer, PathRule)
Match the path and query string against the rule.
- #valid? ⇒ Boolean
Methods inherited from Rule
Constructor Details
This class inherits a constructor from Gort::Rule
Instance Method Details
#inspect ⇒ String
A human readable representation of the rule.
47 48 49 |
# File 'lib/gort/path_rule.rb', line 47 def inspect %(#<#{self.class.name}:#{object_id} "#{value}">) end |
#match(path_and_query) ⇒ nil, (Integer, PathRule)
Match the path and query string against the rule. Invalid rules never match. Empty rules never match, either. This is not explicitly stated in the RFC but it is explicitly described in previous robots.txt documents.
30 31 32 33 34 35 36 37 38 |
# File 'lib/gort/path_rule.rb', line 30 def match(path_and_query) return nil if !valid? || value.empty? path_and_query = normalize_path_and_query(path_and_query) match = path_and_query.match(regexp) return nil unless match [match.to_s.bytesize, self] end |
#pretty_print(pp) ⇒ void
This method returns an undefined value.
Produces a pretty human readable representation of the rule.
58 59 60 |
# File 'lib/gort/path_rule.rb', line 58 def pretty_print(pp) pp.text("#{self.class.name}/#{object_id}< #{value} >") end |
#valid? ⇒ Boolean
17 18 19 |
# File 'lib/gort/path_rule.rb', line 17 def valid? value.match?(PATH_PATTERN) end |