Class: Gort::PathRule Abstract

Inherits:
Rule
  • Object
show all
Defined in:
lib/gort/path_rule.rb

Overview

This class is abstract.

A rule that matches a path and query string.

Direct Known Subclasses

AllowRule, DisallowRule

Instance Attribute Summary

Attributes inherited from Rule

#name, #value

Formatting Methods collapse

Instance Method Summary collapse

Methods inherited from Rule

#initialize

Constructor Details

This class inherits a constructor from Gort::Rule

Instance Method Details

#inspectString

A human readable representation of the rule.

Returns:

  • (String)


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.

Parameters:

  • path_and_query (String)

Returns:

  • (nil, (Integer, PathRule))
    • nil if the rule does not match the path and query string.

    • An array with the number of bytes matched and the rule itself if the rule matches.



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.

Parameters:

  • pp (PrettyPrint)

    pretty printer



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

Returns:

  • (Boolean)


17
18
19
# File 'lib/gort/path_rule.rb', line 17

def valid?
  value.match?(PATH_PATTERN)
end