useragents 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +19 -28
- data/lib/useragents.rb +12 -4
- data/spec/useragents_spec.rb +25 -0
- data/useragents.gemspec +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -1,28 +1,19 @@
|
|
1
|
-
useragents-rb
|
2
|
-
=============
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
UserAgents.rand()
|
15
|
-
```
|
16
|
-
|
17
|
-
```
|
18
|
-
|
19
|
-
|
20
|
-
UserAgents.use(chrome: {gt:29}, ie: {eq: 9})
|
21
|
-
UserAgents.list()
|
22
|
-
# => Chrome : 29, 30, 31
|
23
|
-
# IE : 9
|
24
|
-
|
25
|
-
UserAgents.use(:all)
|
26
|
-
UserAgents.list()
|
27
|
-
# ...
|
28
|
-
```
|
1
|
+
useragents-rb
|
2
|
+
=============
|
3
|
+
[](https://travis-ci.org/debbbbie/useragents-rb)
|
4
|
+
## Usage
|
5
|
+
|
6
|
+
``` sh
|
7
|
+
gem install useragents
|
8
|
+
```
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
require 'useragents'
|
12
|
+
|
13
|
+
# Generate a random useragent for you
|
14
|
+
UserAgents.rand()
|
15
|
+
```
|
16
|
+
|
17
|
+
``` sh
|
18
|
+
|
19
|
+
```
|
data/lib/useragents.rb
CHANGED
@@ -1,15 +1,23 @@
|
|
1
|
+
require 'core_ext/blank'
|
2
|
+
|
1
3
|
module UserAgents
|
2
4
|
|
3
5
|
class << self
|
4
|
-
def list
|
5
6
|
|
7
|
+
def list
|
8
|
+
@@list
|
6
9
|
end
|
7
10
|
|
8
|
-
def use *args
|
9
|
-
|
10
|
-
end
|
11
11
|
def rand
|
12
|
+
@@list[ Kernel::rand(@@list.length) ]
|
13
|
+
end
|
12
14
|
|
15
|
+
def init()
|
16
|
+
@@list = File.read(File.expand_path("../useragents.txt", __FILE__)).split("\n")
|
13
17
|
end
|
18
|
+
|
14
19
|
end
|
20
|
+
|
15
21
|
end
|
22
|
+
|
23
|
+
UserAgents.init()
|
data/spec/useragents_spec.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UserAgents do
|
4
|
+
describe "self.list" do
|
5
|
+
|
6
|
+
it "should not be empty" do
|
7
|
+
UserAgents.list().blank?.should be(false)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "self.rand()" do
|
12
|
+
it "should be a String" do
|
13
|
+
UserAgents.rand().class.should be(String)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe Object do
|
20
|
+
describe "[]" do
|
21
|
+
it "should be blank" do
|
22
|
+
[].blank?.should be(true)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/useragents.gemspec
CHANGED