class AdvancedBotDetection::MobileAgentsParser

Public Class Methods

new() click to toggle source
# File lib/advanced_bot_detection/mobile_agents_parser.rb, line 5
def initialize
  url = 'https://raw.githubusercontent.com/serbanghita/Mobile-Detect/master/Mobile_Detect.json'
  @mobile_hash = JSON.load(open(url))
end

Public Instance Methods

agents() click to toggle source
# File lib/advanced_bot_detection/mobile_agents_parser.rb, line 10
def agents
  agents = []
  parse_browsers(agents)
  parse_tablets(agents)
  parse_phones(agents)
  agents
end
to_a()
Alias for: to_array
to_array() click to toggle source
# File lib/advanced_bot_detection/mobile_agents_parser.rb, line 18
def to_array
  agents
end
Also aliased as: to_a
to_yaml() click to toggle source
# File lib/advanced_bot_detection/mobile_agents_parser.rb, line 23
def to_yaml
  agents.to_yaml
end

Private Instance Methods

parse_agent(type, name, match) click to toggle source
# File lib/advanced_bot_detection/mobile_agents_parser.rb, line 50
def parse_agent(type, name, match)
  {
    'string' => match.gsub('\\b', '\b').gsub('/', '\/'),
    'string_match' => 'regex', # exact or regex
    'types' => type,
    'description' => name
  }
end
parse_browsers(agents) click to toggle source
# File lib/advanced_bot_detection/mobile_agents_parser.rb, line 29
def parse_browsers(agents)
  phones = @mobile_hash['uaMatch']['browsers'].each_pair { |k, v| puts "#{k}: #{v}" }
  phones.each_pair do |name, match|
    agents << parse_agent('mobile_browser', name, match)
  end
end
parse_phones(agents) click to toggle source
# File lib/advanced_bot_detection/mobile_agents_parser.rb, line 36
def parse_phones(agents)
  phones = @mobile_hash['uaMatch']['phones'].each_pair { |k, v| puts "#{k}: #{v}" }
  phones.each_pair do |name, match|
    agents << parse_agent('phone', name, match)
  end
end
parse_tablets(agents) click to toggle source
# File lib/advanced_bot_detection/mobile_agents_parser.rb, line 43
def parse_tablets(agents)
  tablets = @mobile_hash['uaMatch']['tablets'].each_pair { |k, v| puts "#{k}: #{v}" }
  tablets.each_pair do |name, match|
    agents << parse_agent('tablet', name, match)
  end
end