module UserAgentList::ParserUa

Public Instance Methods

all() click to toggle source
# File lib/user_agent_list/parser_ua.rb, line 3
def all
  result = {}
  parser.css('h3').each do |item|
    parser.css("a:contains('#{item.text}')").each do |link|
      result[item.text] ||= []
      result[item.text] << link.children.text unless link.children.text =~ /-->>/
    end
    result.delete(item.text) if result[item.text] && result[item.text].empty?
  end
  result
end
by_browser(string) click to toggle source
# File lib/user_agent_list/parser_ua.rb, line 15
def by_browser(string)
  raise BrowserNotSupported, "#{string} is not supported" unless SUPPORTED_BROWSERS.include?(string)

  result = []
  parser.css("a:contains('#{string}')").each do |link|
    result << link.children.text unless link.children.text =~ /-->>/
  end
  result
end

Private Instance Methods

parser() click to toggle source
# File lib/user_agent_list/parser_ua.rb, line 31
def parser
  @doc ||= Nokogiri::HTML(open(useragentstring_url).read)
end
useragentstring_url() click to toggle source
# File lib/user_agent_list/parser_ua.rb, line 27
def useragentstring_url
  "http://www.useragentstring.com/pages/Browserlist/"
end