browserino 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: acb8ac94ab2c1c344c35baadf3a9b4c2467895af
4
- data.tar.gz: 805054e5d7704be888eee25548d813d8d448ff41
3
+ metadata.gz: 5ffc66c9e3aa3d291234c23f01ccffaae0384be2
4
+ data.tar.gz: 92c2d7b5580f8ff7dc6923d65f79b5a563bb8fb2
5
5
  SHA512:
6
- metadata.gz: 1617ffc71a77a90e28bec8d4fb77a5e94491d0930449d0b68ae689a75f5168669e7c6dbaceee6ca8a905938a90a0e18044ef343bf79f156dbb356f3d6381994f
7
- data.tar.gz: 37f7b4465efe6a522c3e1127b0b2911fbbe81ead5039d82ca73f0a35f33ba60723ad055a22fcf4af08df1eda4de43b2bc9b584adb54faf8f5d9964a3a688a396
6
+ metadata.gz: 0250cbb22fc938da833a6785158789354f68f409ae03148ecf926c8ae9a30a71ea365e5c5a40e415b7fd1328943c2a66c750e605e2b48f10994c4152f75c4f64
7
+ data.tar.gz: 9c19e483f50275de5dd1f6c972a3c40bc2187b57d88b173c17ae49dc47920ca858d061b0b3a4417cec1d74081022cc0abae7990c612cd8877f4ea73cf3cb8000
data/CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
1
  ## CHANGELOG
2
2
  _dates are in dd-mm-yyyy format_
3
3
 
4
+ #### 03-01-2016 VERSION 1.6.0
5
+
6
+ - Added more tests
7
+ - Added more browsers to check: *(bolt, opera mini and ucbrowser)*
8
+ - Added `#known?` method to check if the agent is known
9
+ - Added a `#ua` method to return the User Agent string as given to `Browserino::parse()`
10
+ - Added `#x64?` and `#x32?` convenience methods to check system architecture
11
+ - Added `#mobile?` to check wether or not a user agent is mobile
12
+ - Moved older changelogs to its own [CHANGELOG.md](https://github.com/SidOfc/browserino/blob/master/CHANGELOG.md) file
13
+ - Changed `#to_s` to add dashes (`-`) between browser names if they have a space
14
+ - `#to_s` now has an optional (`sep = ''`) parameter that allows info and version numbers to be seperated
15
+
4
16
  #### 31-12-2015 VERSION 1.5.3
5
17
 
6
18
  - Added blackberry support
data/README.md CHANGED
@@ -10,6 +10,11 @@ This gem aims to provide information about the browser that your visitor is usin
10
10
  _dates are in dd-mm-yyyy format_
11
11
  _older changes can be found in the [CHANGELOG.md](https://github.com/SidOfc/browserino/blob/master/CHANGELOG.md)_
12
12
 
13
+ #### 04-01-2016 VERSION 2.2.0
14
+
15
+ - Added more bots
16
+ - `#bot?` method can now take a bot name as argument to check for an exact bot
17
+
13
18
  #### 04-01-2016 VERSION 2.1.0
14
19
 
15
20
  - Small restructuring of test suite
@@ -25,18 +30,6 @@ _older changes can be found in the [CHANGELOG.md](https://github.com/SidOfc/brow
25
30
  - Changed tests to reflect new behaviour
26
31
  - Added convenience methods `#win?`, `#osx?` and `#bb?`
27
32
 
28
- #### 03-01-2016 VERSION 1.6.0
29
-
30
- - Added more tests
31
- - Added more browsers to check: *(bolt, opera mini and ucbrowser)*
32
- - Added `#known?` method to check if the agent is known
33
- - Added a `#ua` method to return the User Agent string as given to `Browserino::parse()`
34
- - Added `#x64?` and `#x32?` convenience methods to check system architecture
35
- - Added `#mobile?` to check wether or not a user agent is mobile
36
- - Moved older changelogs to its own [CHANGELOG.md](https://github.com/SidOfc/browserino/blob/master/CHANGELOG.md) file
37
- - Changed `#to_s` to add dashes (`-`) between browser names if they have a space
38
- - `#to_s` now has an optional (`sep = ''`) parameter that allows info and version numbers to be seperated
39
-
40
33
  ## Installation
41
34
 
42
35
  *supports ruby 1.9.3+*
@@ -100,7 +93,8 @@ agent.x32? # => true for 32bit UA's
100
93
  agent.x64? # => true for 64bit UA's
101
94
 
102
95
  agent.bot_name # => name of bot if the UA was identified as bot
103
- agent.bot? # => returns true or false depending on if the agent is a bot
96
+ agent.bot? # => returns true if the agent is a bot
97
+ agent.bot? :googlebot # => returns true if the agent is the specified bot
104
98
 
105
99
  agent.known? # => true if browser_name or bot_name present
106
100
  agent.mobile? # => true if agent is a mobile device
@@ -117,7 +111,8 @@ agent.to_a # => [
117
111
  # [:engine_version, '537.75.14'],
118
112
  # [:system_name, 'macintosh'],
119
113
  # [:system_version, '10'],
120
- # [:system_architecture, nil]
114
+ # [:system_architecture, nil],
115
+ # [:bot_name, nil]
121
116
  # ]
122
117
  agent.to_h # => {
123
118
  # browser_name: 'safari',
@@ -126,12 +121,13 @@ agent.to_h # => {
126
121
  # engine_version: '537.75.14',
127
122
  # system_name: 'macintosh',
128
123
  # system_version: '10',
129
- # system_architecture: nil
124
+ # system_architecture: nil,
125
+ # bot_name: nil
130
126
  # }
131
127
  ```
132
128
 
133
129
  It is now also possible to call methods to determine a specific OS or browser if it's supported, a `noMethodError` will be thrown otherwise
134
- The function uses the names of the `Browserino::Mapping.constants(true)` or `Browserino::PATTERNS[:browser].keys` output to identify wether or not to throw this exception.
130
+ The function uses the names of the `Browserino::Mapping` constants and the `Browserino::PATTERNS` hashes `:browser` and `:bot` output to identify wether or not to throw this exception.
135
131
  Versions are also supported as an argument to the function, for operating systems versions could include a string, symbol or float / integer to indicate a version.
136
132
  _(examples given for windows, android and ios, for a full list of versions check the **maps** folder)_
137
133
  Browsers can also accept a float / integer to check for a specific version.
@@ -200,6 +196,7 @@ agent.edge?
200
196
  agent.ie?
201
197
  agent.firefox?
202
198
  agent.chrome?
199
+ agent.seamonkey?
203
200
  agent.safari?
204
201
 
205
202
  # or with the .not method (v1.4.0+)
@@ -215,8 +212,14 @@ agent.msnbot?
215
212
  agent.yahoo_slurp?
216
213
  agent.googlebot?
217
214
  agent.bingbot?
215
+ agent.baiduspider?
216
+ agent.yandexbot?
217
+ agent.sosospider?
218
+ agent.exabot?
219
+ agent.sogou_spider?
218
220
 
219
221
  # or with the .not method (v1.4.0+)
222
+
220
223
  agent.not.msnbot?
221
224
  agent.not.yahoo_slurp?
222
225
  # etc etc...
@@ -283,18 +286,25 @@ Valid browser names are defined by __/lib/browserino/patterns.rb__ (the keys are
283
286
  'yahoo_slurp'
284
287
  'msnbot'
285
288
  'bingbot'
289
+ 'baiduspider'
290
+ 'yandexbot'
291
+ 'sosospider'
292
+ 'exabot'
293
+ 'sogou_spider'
286
294
  ```
287
295
 
288
296
  #### system_name examples
289
297
 
290
- _The main reason for not having Linux distro's / versions is because of the fact that there are MANY different distro's with no real structured release system. The best I can do here is allow a `linux?` system to be found atleast_
291
-
292
298
  ```ruby
293
- ['windows', '7'] # where the 'windows' part is the name of the OS and the '7' is the actual version release (e.g. NT 6.1)
294
- ['macintosh', 'yosemite'] # same as above but OSX has different names ofcourse.
295
- ['android', 'lollipop 22'] # etcetera...
296
- ['linux', nil] # in every linux case, the version will be missing on system_name full: true
297
- [nil, nil] # when nothing about the agent could be found
299
+ 'windows'
300
+ 'win'
301
+ 'macintosh'
302
+ 'osx'
303
+ 'blackberry'
304
+ 'bb'
305
+ 'android'
306
+ 'ios'
307
+ 'linux' # => doesn't have versions
298
308
  ```
299
309
 
300
310
  #### system_architecture examples
@@ -17,9 +17,11 @@ module Browserino
17
17
  system_architecture: OperatingSystem::architecture(cleansed_ua),
18
18
  bot_name: nil
19
19
  }
20
+
20
21
  if Browserino::PATTERNS[:bot].include? name
21
22
  info.merge!({browser_name: nil, browser_version: nil, bot_name: name})
22
23
  end
24
+
23
25
  @info = Browserino::check_for_aliases(info)
24
26
  end
25
27
 
@@ -109,8 +111,10 @@ module Browserino
109
111
  allow_inverted_return blackberry?(*arg)
110
112
  end
111
113
 
112
- def bot?
113
- allow_inverted_return (bot_name.nil? ? false : true)
114
+ def bot?(name = nil)
115
+ is_bot = (bot_name.nil? ? false : true)
116
+ is_name = (name.nil? ? true : (name.to_s.downcase.gsub(/_/, ' ') == bot_name))
117
+ allow_inverted_return(is_bot && is_name)
114
118
  end
115
119
 
116
120
  def method_missing(method_sym, *args, &block)
@@ -2,9 +2,9 @@ module Browserino
2
2
  module Browser
3
3
  def self.version(ua, patterns)
4
4
  if patterns
5
- MatchExtractor::extract(ua.match(patterns[:version]), :version)
5
+ Browserino::extract_match(ua.match(patterns[:version]), :version)
6
6
  else
7
- Browserino::UNKNOWN
7
+ UNKNOWN
8
8
  end
9
9
  end
10
10
  end
@@ -1,11 +1,11 @@
1
1
  module Browserino
2
2
  module Engine
3
3
  def self.name(ua)
4
- MatchExtractor::extract(ua.match(Browserino::PATTERNS[:engine][:name]), :name) || Browserino::UNKNOWN
4
+ Browserino::extract_match(ua.match(PATTERNS[:engine][:name]), :name) || UNKNOWN
5
5
  end
6
6
 
7
7
  def self.version(ua)
8
- MatchExtractor::extract(ua.match(Browserino::PATTERNS[:engine][:version]), :version) || Browserino::UNKNOWN
8
+ Browserino::extract_match(ua.match(PATTERNS[:engine][:version]), :version) || UNKNOWN
9
9
  end
10
10
  end
11
11
  end
@@ -1,15 +1,15 @@
1
1
  module Browserino
2
2
  module OperatingSystem
3
3
  def self.name(ua)
4
- MatchExtractor::extract(ua.match(Browserino::PATTERNS[:operating_system][:name]), :name) || Browserino::UNKNOWN
4
+ Browserino::extract_match(ua.match(PATTERNS[:operating_system][:name]), :name) || UNKNOWN
5
5
  end
6
6
 
7
7
  def self.version(ua)
8
- MatchExtractor::extract(ua.match(Browserino::PATTERNS[:operating_system][:version]), :version) || Browserino::UNKNOWN
8
+ Browserino::extract_match(ua.match(PATTERNS[:operating_system][:version]), :version) || UNKNOWN
9
9
  end
10
10
 
11
11
  def self.architecture(ua)
12
- MatchExtractor::extract(ua.match(Browserino::PATTERNS[:operating_system][:architecture]), :architecture) || Browserino::UNKNOWN
12
+ Browserino::extract_match(ua.match(PATTERNS[:operating_system][:architecture]), :architecture) || UNKNOWN
13
13
  end
14
14
  end
15
15
  end
@@ -61,7 +61,12 @@ module Browserino
61
61
  googlebot: { name: /(?<name>googlebot)/i },
62
62
  yahoo_slurp: { name: /(?<name>yahoo\!\sslurp)/i },
63
63
  msnbot: { name: /(?<name>msnbot)/i },
64
- bingbot: { name: /(?<name>bingbot)/i }
64
+ bingbot: { name: /(?<name>bingbot)/i },
65
+ baiduspider: { name: /(?<name>baiduspider)/i },
66
+ yandexbot: { name: /(?<name>yandexbot)/i },
67
+ sosospider: { name: /(?<name>sosospider)/i },
68
+ exabot: { name: /(?<name>exabot)/i },
69
+ sogou_spider: { name: /(?<name>sogou\s?spider)/i }
65
70
  },
66
71
 
67
72
  engine: {
@@ -1,3 +1,3 @@
1
1
  module Browserino
2
- VERSION = "2.1.0"
2
+ VERSION = "2.2.0"
3
3
  end
data/lib/browserino.rb CHANGED
@@ -10,7 +10,6 @@ require "browserino/agent"
10
10
 
11
11
  require "browserino/alias"
12
12
  require "browserino/version"
13
- require "browserino/match_extractor"
14
13
  require "browserino/patterns"
15
14
  require "browserino/browser"
16
15
  require "browserino/engine"
@@ -58,4 +57,13 @@ module Browserino
58
57
  end
59
58
  name ||= Browserino::UNKNOWN
60
59
  end
60
+
61
+ def self.extract_match(match, sym, trim = true)
62
+ if match && match.names.map(&:to_sym).include?(sym)
63
+ match[sym].strip! if trim
64
+ match[sym].to_s.downcase
65
+ else
66
+ Browserino::UNKNOWN
67
+ end
68
+ end
61
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browserino
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sidney Liebrand
@@ -140,7 +140,6 @@ files:
140
140
  - lib/browserino/maps/linux.rb
141
141
  - lib/browserino/maps/macintosh.rb
142
142
  - lib/browserino/maps/windows.rb
143
- - lib/browserino/match_extractor.rb
144
143
  - lib/browserino/operating_system.rb
145
144
  - lib/browserino/patterns.rb
146
145
  - lib/browserino/unknown.rb
@@ -1,12 +0,0 @@
1
- module Browserino
2
- module MatchExtractor
3
- def self.extract(match, sym, trim = true)
4
- if match && match.names.map(&:to_sym).include?(sym)
5
- match[sym].strip! if trim
6
- match[sym].to_s.downcase
7
- else
8
- Browserino::UNKNOWN
9
- end
10
- end
11
- end
12
- end