class CrawlerDetect::Detector
since 0.1.0
Public Class Methods
new(user_agent)
click to toggle source
@param user_agent [String] User-agent string to detect @return [CrawlerDetect::Detector] instance of detector class
# File lib/crawler_detect/detector.rb, line 8 def initialize(user_agent) @user_agent = user_agent.to_s.dup end
Public Instance Methods
crawler_name()
click to toggle source
@return [String] The detected crawler name from RAW data
# File lib/crawler_detect/detector.rb, line 20 def crawler_name return unless is_crawler? @crawler_name end
is_crawler?()
click to toggle source
@return [true, false] Is User-agent a crawler?
# File lib/crawler_detect/detector.rb, line 13 def is_crawler? @is_crawler ||= begin !completely_exclusion? && matches_crawler_list? end end
Private Instance Methods
completely_exclusion?()
click to toggle source
@private @return [true, false] Is User-agent in white-list?
# File lib/crawler_detect/detector.rb, line 29 def completely_exclusion? @user_agent.gsub!(exclusions_matcher, "") @user_agent.strip.length.zero? end
crawlers_matcher()
click to toggle source
@private @return [Regexp] Black-list of User-agents
# File lib/crawler_detect/detector.rb, line 49 def crawlers_matcher CrawlerDetect::Library.get_regexp("crawlers") end
exclusions_matcher()
click to toggle source
@private @return [Regexp] White-list of User-agents
# File lib/crawler_detect/detector.rb, line 43 def exclusions_matcher CrawlerDetect::Library.get_regexp("exclusions") end
matches_crawler_list?()
click to toggle source
@private @return [true, false] Is User-agent in black-list?
# File lib/crawler_detect/detector.rb, line 36 def matches_crawler_list? @crawler_name = crawlers_matcher.match(@user_agent).to_s.strip !@crawler_name.empty? end