useragents 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ unless Object.respond_to? :blank?
2
+
3
+ class Object
4
+ # An object is blank if it's false, empty, or a whitespace string.
5
+ # For example, "", " ", +nil+, [], and {} are all blank.
6
+ #
7
+ # This simplifies:
8
+ #
9
+ # if address.nil? || address.empty?
10
+ #
11
+ # ...to:
12
+ #
13
+ # if address.blank?
14
+ def blank?
15
+ respond_to?(:empty?) ? empty? : !self
16
+ end
17
+
18
+ end
19
+
20
+ end
data/lib/fetch.rb ADDED
@@ -0,0 +1,23 @@
1
+ module UserAgents
2
+ def fetch
3
+ require 'nokogiri'
4
+ require 'open-uri'
5
+
6
+ urls = [
7
+ 'http://www.useragentstring.com/pages/Chrome/',
8
+ 'http://www.useragentstring.com/pages/Firefox/',
9
+ 'http://www.useragentstring.com/pages/Internet%20Explorer/',
10
+ 'http://www.useragentstring.com/pages/Opera/',
11
+ 'http://www.useragentstring.com/pages/Safari/'
12
+ ]
13
+
14
+ agents = urls.inject([]) do |sum, url|
15
+ puts "Requesting #{url}"
16
+ doc = Nokogiri::HTML(open(url))
17
+ sum + doc.css('#liste ul li a').map{|link| link.content.strip }
18
+ end
19
+
20
+ File.write(File.expand_path('../useragents.txt', __FILE__), agents.join("\n"))
21
+ puts "Fetch complete, got useragent count #{agents.length}!"
22
+ end
23
+ end
data/lib/useragents.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'core_ext/blank'
1
+ require File.expand_path('../core_ext/blank', __FILE__)
2
2
 
3
3
  module UserAgents
4
4