mobile_detect 0.0.2 → 0.0.3

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 CHANGED
@@ -37,6 +37,16 @@ you can run that without second argument, but then gem cannot get device from cl
37
37
 
38
38
  => "iOS"
39
39
 
40
+ ### Bot detection
41
+
42
+ detect.bot?
43
+
44
+ => true
45
+
46
+ detect.bot
47
+
48
+ => 'Google'
49
+
40
50
  ## Contributing
41
51
 
42
52
  1. Fork it
@@ -59,14 +59,30 @@ class MobileDetect
59
59
 
60
60
  }
61
61
 
62
+ BotAgents = {
63
+ 'Google' => 'Googlebot',
64
+ 'Yahoo!' => 'Slurp|Yahoo! Slurp',
65
+ 'AOL' => 'Slurp',
66
+ 'MSN' => 'MSNBot',
67
+ 'Live' => 'MNSBot',
68
+ 'Ask' => 'Teoma',
69
+ 'AltaVista' => 'Scooter',
70
+ 'Alexa' => 'ia_archiver',
71
+ 'Lycos' => 'Lycos',
72
+ 'Yandex' => 'Yandex',
73
+ 'Rambler' => 'StackRambler',
74
+ 'Mail.ru' => 'Mail.ru',
75
+ 'Aport' => 'Aport',
76
+ 'Webalta' => 'WebAlta|WebAlta Crawler/2.0'
77
+ }
78
+
62
79
 
63
80
  def initialize(user_agent, req_headers = nil)
64
81
  @user_agent = user_agent
65
82
  @req_headers = req_headers
66
- @device = nil
67
- @is_tablet = nil
68
- @is_mobile = nil
69
- @os = nil
83
+
84
+ @is_tablet, @is_mobile = nil
85
+ @os, @device = nil
70
86
  end
71
87
 
72
88
  def tablet?
@@ -77,10 +93,15 @@ class MobileDetect
77
93
  @is_mobile.nil? ? is_mobile : @is_mobile
78
94
  end
79
95
 
96
+ def bot?
97
+ @is_bot.nil? ? is_bot : @is_bot
98
+ end
99
+
80
100
  def info
81
101
  tablet = tablet?
82
102
  mobile = mobile?
83
- {:device => device, :user_agent => user_agent, :mobile => mobile, :tablet => tablet}
103
+ bot = bot?
104
+ {:device => device, :user_agent => user_agent, :mobile => mobile, :tablet => tablet, :bot => bot}
84
105
  end
85
106
 
86
107
  def device
@@ -92,15 +113,38 @@ class MobileDetect
92
113
  @os.nil? ? detect_os : @os
93
114
  end
94
115
 
116
+ def bot
117
+ @bot.nil? ? detect_bot : @bot
118
+ end
119
+
95
120
  private
96
121
  def is_tablet
97
122
  @is_tablet = regexp_device(TabletDevices)
98
123
  end
99
124
 
100
125
  def detect_os
101
- @os = regexp_os(OperatingSystems)
126
+ res = regexp(OperatingSystems)
127
+ if res
128
+ @os = res
129
+ return @os
130
+ else
131
+ return false
132
+ end
102
133
  end
103
134
 
135
+ def detect_bot
136
+ res = regexp(BotAgents)
137
+ if res
138
+ @bot = res
139
+ return @bot
140
+ else
141
+ return false
142
+ end
143
+ end
144
+
145
+ def is_bot
146
+ @is_bot = detect_bot ? true : false
147
+ end
104
148
 
105
149
  def is_mobile
106
150
  @is_mobile = (is_mobile_headers || is_mobile_regexp)
@@ -130,16 +174,6 @@ class MobileDetect
130
174
  end
131
175
  end
132
176
 
133
- def regexp_os(reg_hash)
134
- res = regexp(reg_hash)
135
- if res
136
- @os = res
137
- return @os
138
- else
139
- return false
140
- end
141
- end
142
-
143
177
  def regexp_device(reg_hash)
144
178
  res = regexp(reg_hash)
145
179
  if res
@@ -1,3 +1,3 @@
1
1
  class MobileDetect
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -31,3 +31,15 @@ describe "Test os detection" do
31
31
  md.os.should == 'AndroidOS'
32
32
  end
33
33
  end
34
+
35
+
36
+ describe "Test bot detection" do
37
+ it 'googlebot test' do
38
+ md = MobileDetect.new('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)')
39
+ md.bot.should == 'Google'
40
+ end
41
+ it 'mail.ru test' do
42
+ md = MobileDetect.new('Mozilla/5.0 (compatible; Linux x86_64; Mail.RU_Bot/2.0; +http://go.mail.ru/help/robots)')
43
+ md.bot.should == 'Mail.ru'
44
+ end
45
+ end
metadata CHANGED
@@ -1,32 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobile_detect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
4
  prerelease:
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dmitry Gruzd
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-06 00:00:00.000000000 Z
12
+ date: 2013-07-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: !ruby/object:Gem::Requirement
16
+ version_requirements: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
- type: :development
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
22
+ requirement: !ruby/object:Gem::Requirement
25
23
  none: false
26
24
  requirements:
27
25
  - - ! '>='
28
26
  - !ruby/object:Gem::Version
29
27
  version: '0'
28
+ type: :development
29
+ prerelease: false
30
30
  description: ! ' gem detect mobile device or not, tablet or mobile phone'
31
31
  email:
32
32
  - donotsendhere@gmail.com
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  requirements: []
66
66
  rubyforge_project:
67
- rubygems_version: 1.8.24
67
+ rubygems_version: 1.8.25
68
68
  signing_key:
69
69
  specification_version: 3
70
70
  summary: Mobile_Detect is a lightweight gem for detecting mobile devices. It uses