browserino 2.2.0 → 2.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ffc66c9e3aa3d291234c23f01ccffaae0384be2
4
- data.tar.gz: 92c2d7b5580f8ff7dc6923d65f79b5a563bb8fb2
3
+ metadata.gz: 73da860bb3eb32ad2dc1eb37512027bb88d7e543
4
+ data.tar.gz: 0a96818c4f592bb6e08271cf782d6b8c9446acc7
5
5
  SHA512:
6
- metadata.gz: 0250cbb22fc938da833a6785158789354f68f409ae03148ecf926c8ae9a30a71ea365e5c5a40e415b7fd1328943c2a66c750e605e2b48f10994c4152f75c4f64
7
- data.tar.gz: 9c19e483f50275de5dd1f6c972a3c40bc2187b57d88b173c17ae49dc47920ca858d061b0b3a4417cec1d74081022cc0abae7990c612cd8877f4ea73cf3cb8000
6
+ metadata.gz: 2a981d94ecdd13a05fd56c13040daead3bc787d038d513bc32d2e1b0dcf64d9d15a7a129420ae6cbf2d2381d23f9f52b3512b4b0df6777fdc0212aeed2e7a727
7
+ data.tar.gz: 72837977011f86c73ff3431fd7c42b02311fcba52d1e293b8a286d8883855deacc8c1d9e9822fd139a4a68487600b0affa8dd8e0514f7cd12e28ec199f012a97
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  ## CHANGELOG
2
2
  _dates are in dd-mm-yyyy format_
3
3
 
4
+ #### 03-01-2016 VERSION 2.0.0
5
+
6
+ - **IMPORTANT** Changed behaviour of all dynamic methods to include version as an argument rather than in the method name.
7
+ - **IMPORTANT** Changed the behaviour of version checking to be more strict
8
+ - Changed tests to reflect new behaviour
9
+ - Added convenience methods `#win?`, `#osx?` and `#bb?`
10
+
4
11
  #### 03-01-2016 VERSION 1.6.0
5
12
 
6
13
  - Added more tests
data/README.md CHANGED
@@ -10,6 +10,13 @@ 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
+ #### 06-01-2016 VERSION 2.3.0
14
+
15
+ - Added `#compat?` method to test if IE is in compatibility mode
16
+ - Extended `#browser_version` to now also take an argument
17
+ - Added `#locale` method
18
+ - Empty UA's are identified as bots through `#bot?`
19
+
13
20
  #### 04-01-2016 VERSION 2.2.0
14
21
 
15
22
  - Added more bots
@@ -23,13 +30,6 @@ _older changes can be found in the [CHANGELOG.md](https://github.com/SidOfc/brow
23
30
  - Added dynamic method support for bots
24
31
  - Added support for the seamonkey browser
25
32
 
26
- #### 03-01-2016 VERSION 2.0.0
27
-
28
- - **IMPORTANT** Changed behaviour of all dynamic methods to include version as an argument rather than in the method name.
29
- - **IMPORTANT** Changed the behaviour of version checking to be more strict
30
- - Changed tests to reflect new behaviour
31
- - Added convenience methods `#win?`, `#osx?` and `#bb?`
32
-
33
33
  ## Installation
34
34
 
35
35
  *supports ruby 1.9.3+*
@@ -75,55 +75,107 @@ On this object there are a few method calls you can do to retrieve information.
75
75
  ```ruby
76
76
  require 'browserino'
77
77
 
78
- agent = Browserino::parse('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A')
78
+ agent = Browserino::parse('user-agent')
79
+
80
+ agent.browser_name
81
+ # => 'safari'
79
82
 
80
- agent.browser_name # => 'safari'
81
- agent.browser_version # => 7.0.3
83
+ # always returns the real version (also with IE in compat)
84
+ agent.browser_version
85
+ # => '7.0.3'
82
86
 
83
- agent.engine_name # => 'webkit'
84
- agent.engine_version # => 537.75.14
87
+ # if a user is running IE in compat mode this will return the compat version
88
+ agent.browser_version compat: true
89
+ # => '7.0'
90
+
91
+ agent.engine_name
92
+ # => 'webkit'
93
+
94
+ agent.engine_version
95
+ # => '537.75.14'
96
+
97
+ agent.system_name
98
+ # => 'macintosh'
85
99
 
86
- agent.system_name # => 'macintosh'
87
100
  # or optionally, the full name (guessed from OS version)
88
- agent.system_name full: true # => ['macintosh', 'mavericks']
89
- agent.system_version # => 10.9.3
90
- agent.system_architecture # => 'x32' or 'x64' if known
101
+ agent.system_name full: true
102
+ # => ['macintosh', 'mavericks']
103
+
104
+ agent.system_version
105
+ # => '10.9.3'
106
+
107
+ agent.system_architecture
108
+ # => 'x32'
109
+
91
110
  # or through convenience methods:
92
- agent.x32? # => true for 32bit UA's
93
- agent.x64? # => true for 64bit UA's
111
+ agent.x32?
112
+ # => true
113
+
114
+ agent.x64?
115
+ # => false
116
+
117
+ # get the locale, either 'aa' or 'aa-bb' format
118
+ agent.locale
119
+ # => 'en'
120
+ # or if the UA supplies the information
121
+ # => 'en-us'
122
+
123
+
124
+ # name of bot if the UA was identified as bot
125
+ agent.bot_name
126
+ # => 'googlebot'
94
127
 
95
- agent.bot_name # => name of bot if the UA was identified as 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
128
+ # returns true if the agent is a bot
129
+ agent.bot?
130
+ # => true
98
131
 
99
- agent.known? # => true if browser_name or bot_name present
100
- agent.mobile? # => true if agent is a mobile device
132
+ # returns true if the agent is the specified bot
133
+ agent.bot? :googlebot
134
+ # => true
135
+
136
+ # check IE compatibility mode
137
+ agent.compat?
138
+ # => true
139
+
140
+ # true if browser_name or bot_name present
141
+ agent.known?
142
+ # => true
143
+
144
+ # true if agent is a mobile device
145
+ agent.mobile?
146
+ # => true
101
147
 
102
148
  # methods to convert object into a String, Array or hash
103
- agent.to_s # => 'safari safari7 webkit webkit537 macintosh macintosh10'
149
+ agent.to_s
150
+ # => 'safari safari7 webkit webkit537 macintosh macintosh10 en-us'
151
+
104
152
  # to_s can split version numbers from words if a seperator is supplied
105
- agent.to_s '-' # => 'safari safari-7 webkit webkit-537 macintosh macintosh-10'
106
-
107
- agent.to_a # => [
108
- # [:browser_name, 'safari'],
109
- # [:browser_version, '7.0.3'],
110
- # [:engine_name, 'webkit'],
111
- # [:engine_version, '537.75.14'],
112
- # [:system_name, 'macintosh'],
113
- # [:system_version, '10'],
114
- # [:system_architecture, nil],
115
- # [:bot_name, nil]
116
- # ]
117
- agent.to_h # => {
118
- # browser_name: 'safari',
119
- # browser_version: '7.0.3',
120
- # engine_name: 'webkit',
121
- # engine_version: '537.75.14',
122
- # system_name: 'macintosh',
123
- # system_version: '10',
124
- # system_architecture: nil,
125
- # bot_name: nil
126
- # }
153
+ agent.to_s '-'
154
+ # => 'safari safari-7 webkit webkit-537 macintosh macintosh-10 en-us'
155
+
156
+ agent.to_a
157
+ # => [
158
+ # [:browser_name, 'safari'],
159
+ # [:browser_version, '7.0.3'],
160
+ # [:engine_name, 'webkit'],
161
+ # [:engine_version, '537.75.14'],
162
+ # [:system_name, 'macintosh'],
163
+ # [:system_version, '10'],
164
+ # [:system_architecture, nil],
165
+ # [:bot_name, nil]
166
+ # ]
167
+
168
+ agent.to_h
169
+ # => {
170
+ # browser_name: 'safari',
171
+ # browser_version: '7.0.3',
172
+ # engine_name: 'webkit',
173
+ # engine_version: '537.75.14',
174
+ # system_name: 'macintosh',
175
+ # system_version: '10',
176
+ # system_architecture: nil,
177
+ # bot_name: nil
178
+ # }
127
179
  ```
128
180
 
129
181
  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
data/bin/console CHANGED
@@ -3,7 +3,7 @@
3
3
  require "bundler/setup"
4
4
  require "browserino"
5
5
  require "pry"
6
- ua = 'msnbot/2.1'
6
+ ua = 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en-US) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.0.0.450 Mobile Safari/534.8+'
7
7
  @agent = Browserino::parse(ua)
8
8
 
9
9
  puts "> @agent variable available parsed with: '#{ua}'\n\n"
@@ -15,6 +15,7 @@ module Browserino
15
15
  system_name: OperatingSystem::name(cleansed_ua),
16
16
  system_version: OperatingSystem::version(cleansed_ua),
17
17
  system_architecture: OperatingSystem::architecture(cleansed_ua),
18
+ locale: OperatingSystem::locale(cleansed_ua),
18
19
  bot_name: nil
19
20
  }
20
21
 
@@ -31,9 +32,13 @@ module Browserino
31
32
  end
32
33
  end
33
34
 
34
- def browser_version
35
- with_valid(@info[:browser_version]) do |v|
36
- v.to_s.downcase.gsub('_', '.')
35
+ def browser_version(opts = {})
36
+ if ie? && engine_version && !opts[:compat]
37
+ (engine_version.to_f + 4.0).to_s
38
+ else
39
+ with_valid(@info[:browser_version]) do |v|
40
+ v.to_s.downcase.gsub('_', '.')
41
+ end
37
42
  end
38
43
  end
39
44
 
@@ -73,6 +78,10 @@ module Browserino
73
78
  end
74
79
  end
75
80
 
81
+ def locale
82
+ with_valid(@info[:locale]) { |v| v.to_s.downcase }
83
+ end
84
+
76
85
  def bot_name
77
86
  with_valid(@info[:bot_name]) do |v|
78
87
  v.to_s.downcase.gsub(/_/, ' ')
@@ -83,6 +92,10 @@ module Browserino
83
92
  @ua
84
93
  end
85
94
 
95
+ def compat?
96
+ allow_inverted_return (ie? && browser_version != browser_version(compat: true))
97
+ end
98
+
86
99
  def known?
87
100
  allow_inverted_return (browser_name != @unknown || bot_name != @unknown)
88
101
  end
@@ -112,9 +125,9 @@ module Browserino
112
125
  end
113
126
 
114
127
  def bot?(name = nil)
115
- is_bot = (bot_name.nil? ? false : true)
128
+ is_bot = ((bot_name.nil? ? false : true) ? true : ua.strip.empty?)
116
129
  is_name = (name.nil? ? true : (name.to_s.downcase.gsub(/_/, ' ') == bot_name))
117
- allow_inverted_return(is_bot && is_name)
130
+ allow_inverted_return (is_bot && is_name)
118
131
  end
119
132
 
120
133
  def method_missing(method_sym, *args, &block)
@@ -16,6 +16,7 @@ module Browserino
16
16
  'x64' => ['64', 'x86_64', 'amd64', 'wow64'],
17
17
  'x32' => ['32', 'i686', 'i383', 'x86_32']
18
18
  },
19
- bot_name: {}
19
+ bot_name: {},
20
+ locale: {}
20
21
  }
21
22
  end
@@ -11,5 +11,9 @@ module Browserino
11
11
  def self.architecture(ua)
12
12
  Browserino::extract_match(ua.match(PATTERNS[:operating_system][:architecture]), :architecture) || UNKNOWN
13
13
  end
14
+
15
+ def self.locale(ua)
16
+ Browserino::extract_match(ua.match(PATTERNS[:operating_system][:locale]), :locale) || UNKNOWN
17
+ end
14
18
  end
15
19
  end
@@ -28,12 +28,12 @@ module Browserino
28
28
 
29
29
  edge: {
30
30
  name: /(?<name>edge)/i,
31
- version: /(?:edge\/)(?<version>[\d\.b]+)/i
31
+ version: /(?:edge\/)(?<version>[\d\.]+)/i
32
32
  },
33
33
 
34
34
  ie: {
35
35
  name: /(?<name>msie|trident)/i,
36
- version: /(?:(?:ms)?ie\s|rv\:)(?<version>[\d\.b]+)/i
36
+ version: /(?:(?:ms)?ie\s|rv\:)(?<version>[\d\.]+)/i
37
37
  },
38
38
 
39
39
  seamonkey: {
@@ -66,7 +66,11 @@ module Browserino
66
66
  yandexbot: { name: /(?<name>yandexbot)/i },
67
67
  sosospider: { name: /(?<name>sosospider)/i },
68
68
  exabot: { name: /(?<name>exabot)/i },
69
- sogou_spider: { name: /(?<name>sogou\s?spider)/i }
69
+ sogou_spider: { name: /(?<name>sogou\s?spider)/i },
70
+ nutch: { name: /(?<name>nutch)/i },
71
+ scrapy: { name: /(?<name>scrapy)/i },
72
+ dataparksearch: { name: /(?<name>dataparksearch)/i },
73
+ beslistbot: { name: /(?<name>beslistbot)/i }
70
74
  },
71
75
 
72
76
  engine: {
@@ -78,7 +82,8 @@ module Browserino
78
82
  name: /(?<name>windows|macintosh|android|ios|blackberry|linux|ubuntu|x11)/i,
79
83
  version: /(?:nt|mac\sos\sx|android|(cpu\s|i)os|blackberry)\s?(?<version>[\d\._]+)/i,
80
84
  architecture: /(?<architecture>((?:x|x86_|amd|wow)64)|i(3|6)86)/i,
81
- mobile: /bolt|nokia|samsung|mobi(?:le)?|android|ip(?:[ao]d|hone)|bb\d+|blackberry|iemobile|fennec|bada|meego|vodafone|t\-mobile|opera\sm(?:ob|in)i/i
85
+ mobile: /bolt|nokia|samsung|mobi(?:le)?|android|ip(?:[ao]d|hone)|bb\d+|blackberry|iemobile|fennec|bada|meego|vodafone|t\-mobile|opera\sm(?:ob|in)i/i,
86
+ locale: /\s(?<locale>\w{2}(?:\-\w{2})?)[;\)]/
82
87
  }
83
88
  }
84
89
  end
@@ -1,3 +1,3 @@
1
1
  module Browserino
2
- VERSION = "2.2.0"
2
+ VERSION = "2.3.0"
3
3
  end
data/lib/browserino.rb CHANGED
@@ -20,7 +20,7 @@ require "browserino/operating_system"
20
20
  # require_relative "../spec/user_agents_browsers"
21
21
 
22
22
  module Browserino
23
- def self.parse(ua, unknown_alt = Browserino::UNKNOWN)
23
+ def self.parse(ua, unknown_alt = UNKNOWN)
24
24
  Agent.new(ua, unknown_alt)
25
25
  end
26
26
 
@@ -29,12 +29,10 @@ module Browserino
29
29
  def self.cleanse(ua)
30
30
  #make iphone / ipad / ipod consistent
31
31
  ua = ua.gsub(/ip((a|o)d|hone)/i, 'ios')
32
- #strip legacy mozilla version
33
32
  ua = ua.gsub(/(Mozilla\/[\d\.]+)/i, '')
34
- #strip fake opera version
35
33
  ua = ua.gsub(/9\.80/i, '')
36
- #strip webkit if presto engine is used
37
34
  ua = ua.gsub(/(?:apple)?webkit\/[\d\.]+/i, '') if /presto/i =~ ua
35
+ ua = ua.gsub(/(?:ms)?ie/i, '') if /rv\:/i =~ ua
38
36
  ua = ua.gsub(/linux/i, '') if /android/i =~ ua
39
37
  ua
40
38
  end
@@ -55,15 +53,15 @@ module Browserino
55
53
  tmp = browsers.shift
56
54
  name = tmp if (ua.match(patterns[tmp][:name]))
57
55
  end
58
- name ||= Browserino::UNKNOWN
56
+ name ||= UNKNOWN
59
57
  end
60
58
 
61
59
  def self.extract_match(match, sym, trim = true)
62
- if match && match.names.map(&:to_sym).include?(sym)
60
+ if match && match.names.include?(sym.to_s)
63
61
  match[sym].strip! if trim
64
62
  match[sym].to_s.downcase
65
63
  else
66
- Browserino::UNKNOWN
64
+ UNKNOWN
67
65
  end
68
66
  end
69
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browserino
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sidney Liebrand
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-04 00:00:00.000000000 Z
11
+ date: 2016-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler