Class: WebRobots::RobotsTxt::AccessControlLine
- Inherits:
-
Line
- Object
- Line
- WebRobots::RobotsTxt::AccessControlLine
show all
- Defined in:
- lib/webrobots/robotstxt.rb
Instance Attribute Summary
Attributes inherited from Line
#token, #value
Instance Method Summary
collapse
Methods inherited from Line
#initialize
Instance Method Details
#compile ⇒ Object
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
|
# File 'lib/webrobots/robotstxt.rb', line 687
def compile
@empty = @value.empty?
re_src = '\A'
s = StringScanner.new(@value)
until s.eos?
if t = s.scan(/[^%*$]+/)
re_src << Regexp.quote(t)
elsif t = s.scan(/%([0-9a-f]{2})/i)
c = s[1].to_i(16)
if c == 0x2f
re_src << '%2[fF]'
else
re_src << Regexp.quote('%c' % c)
end
elsif t = s.scan(/\*/)
re_src << '.*'
elsif t = s.scan(/\$/)
re_src << '\z'
break
else
re_src << Regexp.quote(s.scan(/./))
end
end
@pattern = Regexp.new(re_src, Regexp::MULTILINE)
self
end
|
#match?(request_uri) ⇒ Boolean
714
715
716
717
718
|
# File 'lib/webrobots/robotstxt.rb', line 714
def match?(request_uri)
return false if @empty
transformed = request_uri.gsub(/(%2[fF])|%([0-9a-f]{2})/i) { $1 || '%c' % $2.to_i(16) }
!!@pattern.match(transformed)
end
|