class AdvancedBotDetection::UserAgentsParser
Attributes
types[R]
Public Class Methods
new()
click to toggle source
# File lib/advanced_bot_detection/user_agents_parser.rb, line 8 def initialize @xml = HTTPClient.new.get_content('http://www.user-agents.org/allagents.xml') @types = { b: 'browser', c: 'checker', d: 'downloader', p: 'proxy', r: 'crawler', s: 'spam' } end
Public Instance Methods
agents()
click to toggle source
# File lib/advanced_bot_detection/user_agents_parser.rb, line 13 def agents agents = [] xml = Nokogiri::XML(@xml) xml.xpath('//user-agent').each do |agent| agents << parse_agent(agent) end agents end
to_array()
click to toggle source
# File lib/advanced_bot_detection/user_agents_parser.rb, line 22 def to_array agents end
Also aliased as: to_a
to_yaml()
click to toggle source
# File lib/advanced_bot_detection/user_agents_parser.rb, line 27 def to_yaml agents.to_yaml end
Private Instance Methods
clarify_type(type)
click to toggle source
# File lib/advanced_bot_detection/user_agents_parser.rb, line 42 def clarify_type(type) @types[type.downcase.to_sym] end
parse_agent(agent)
click to toggle source
# File lib/advanced_bot_detection/user_agents_parser.rb, line 33 def parse_agent(agent) { 'string' => agent.xpath('String').text, 'string_match' => 'exact', 'types' => agent.xpath('Type').text.split.map { |t| clarify_type(t) }.compact, 'description' => agent.xpath('Description').text } end