user_agent_parser 2.12.0 → 2.13.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 +4 -4
- data/lib/user_agent_parser/parser.rb +27 -22
- data/lib/user_agent_parser.rb +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f014ae2d784eb25f63242a361c9c9186ad108c7199fd1655944da1dcfeaff28
|
4
|
+
data.tar.gz: 36357407d451f17dada0fa4115f5f19e8a69af6932a1c3fc999ecd55abc958a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1dfc2207de8b2345dcf21a0f271122f96259165fe115397ecb290f9fb07a9924e399554a5f23110c27f24976feae5b189a9a482386bb9f60d74ce542625eda61
|
7
|
+
data.tar.gz: 7abd96ee88bcca1d800323d3d9fd2f508b0b36dc20885a79e5bdfb58154a48a00ed60b0f7750e3eb0fd6570bbbebaac48355f5ba250c35f05ace615c41baa5d5
|
@@ -4,6 +4,8 @@ require 'yaml'
|
|
4
4
|
|
5
5
|
module UserAgentParser
|
6
6
|
class Parser
|
7
|
+
extend Gem::Deprecate
|
8
|
+
|
7
9
|
FAMILY_REPLACEMENT_KEYS = %w[
|
8
10
|
family_replacement
|
9
11
|
v1_replacement
|
@@ -22,11 +24,13 @@ module UserAgentParser
|
|
22
24
|
|
23
25
|
private_constant :FAMILY_REPLACEMENT_KEYS, :OS_REPLACEMENT_KEYS
|
24
26
|
|
25
|
-
attr_reader :
|
27
|
+
attr_reader :patterns_paths
|
28
|
+
|
29
|
+
def initialize(patterns_path: nil, patterns_paths: [])
|
30
|
+
@patterns_paths = [patterns_path, *patterns_paths].compact
|
31
|
+
@patterns_paths = [UserAgentParser::DefaultPatternsPath] if @patterns_paths.empty?
|
26
32
|
|
27
|
-
|
28
|
-
@patterns_path = options[:patterns_path] || UserAgentParser::DefaultPatternsPath
|
29
|
-
@ua_patterns, @os_patterns, @device_patterns = load_patterns(patterns_path)
|
33
|
+
@ua_patterns, @os_patterns, @device_patterns = load_patterns(@patterns_paths)
|
30
34
|
end
|
31
35
|
|
32
36
|
def parse(user_agent)
|
@@ -35,9 +39,23 @@ module UserAgentParser
|
|
35
39
|
parse_ua(user_agent, os, device)
|
36
40
|
end
|
37
41
|
|
42
|
+
def patterns_path
|
43
|
+
patterns_paths.first
|
44
|
+
end
|
45
|
+
deprecate :patterns_path, :patterns_paths, 2022, 12
|
46
|
+
|
38
47
|
private
|
39
48
|
|
40
|
-
def load_patterns(
|
49
|
+
def load_patterns(patterns_paths)
|
50
|
+
patterns_paths.each_with_object([[], [], []]) do |path, patterns|
|
51
|
+
ua_patterns, os_patterns, device_patterns = load_patterns_file(path)
|
52
|
+
patterns[0] += ua_patterns
|
53
|
+
patterns[1] += os_patterns
|
54
|
+
patterns[2] += device_patterns
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def load_patterns_file(path)
|
41
59
|
yml = begin
|
42
60
|
YAML.load_file(path, freeze: true)
|
43
61
|
rescue ArgumentError
|
@@ -88,24 +106,11 @@ module UserAgentParser
|
|
88
106
|
end
|
89
107
|
end
|
90
108
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
if pattern[:regex].match?(value)
|
95
|
-
return [pattern, pattern[:regex].match(value)]
|
96
|
-
end
|
97
|
-
end
|
98
|
-
nil
|
99
|
-
end
|
100
|
-
else
|
101
|
-
def first_pattern_match(patterns, value)
|
102
|
-
patterns.each do |pattern|
|
103
|
-
if (match = pattern[:regex].match(value))
|
104
|
-
return [pattern, match]
|
105
|
-
end
|
106
|
-
end
|
107
|
-
nil
|
109
|
+
def first_pattern_match(patterns, value)
|
110
|
+
patterns.each do |pattern|
|
111
|
+
return [pattern, pattern[:regex].match(value)] if pattern[:regex].match?(value)
|
108
112
|
end
|
113
|
+
nil
|
109
114
|
end
|
110
115
|
|
111
116
|
def user_agent_from_pattern_match(pattern, match, os = nil, device = nil)
|
data/lib/user_agent_parser.rb
CHANGED
@@ -10,7 +10,7 @@ module UserAgentParser
|
|
10
10
|
DefaultPatternsPath = File.join(File.dirname(__FILE__), '../vendor/uap-core/regexes.yaml')
|
11
11
|
|
12
12
|
# Parse the given +user_agent_string+, returning a +UserAgent+
|
13
|
-
def self.parse(user_agent_string,
|
14
|
-
Parser.new(
|
13
|
+
def self.parse(user_agent_string, **args)
|
14
|
+
Parser.new(**args).parse(user_agent_string)
|
15
15
|
end
|
16
16
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: user_agent_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Lucas
|
@@ -10,8 +10,9 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2022-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
13
|
+
description: |
|
14
|
+
A simple, comprehensive Ruby gem for parsing user agent strings
|
15
|
+
with the help of BrowserScope's UserAgent database
|
15
16
|
email: t@toolmantim.com
|
16
17
|
executables:
|
17
18
|
- user_agent_parser
|
@@ -50,6 +51,5 @@ requirements: []
|
|
50
51
|
rubygems_version: 3.3.24
|
51
52
|
signing_key:
|
52
53
|
specification_version: 4
|
53
|
-
summary:
|
54
|
-
help of BrowserScope's UA database
|
54
|
+
summary: Parsing user agent strings with the help of BrowserScope's UA database
|
55
55
|
test_files: []
|