useragent 0.16.6 → 0.16.7

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: 2bbbd675e80901dfed7674e9a04561b3bcec4527
4
- data.tar.gz: fed38ba57c850d1a20779fa534f9d0fd0c05933c
3
+ metadata.gz: 29ec5687df8a0fadd9e1ddc9257131aa1193e7b6
4
+ data.tar.gz: a6431baf15ed2cf458c4b69d9b8ad946aaa155dd
5
5
  SHA512:
6
- metadata.gz: d305a8d8cde309eb2b7072728b844ea10737b2cc96501e9fad8b55c1c031d709fcef24cdc3bb18d36f3711d3a47d0dc0f2d574c7fc5ba77065c421e2b33783d3
7
- data.tar.gz: 720838b4801bf39f4dd838289a7687cf7710c27c70d875621d26937f1d1b9798ced57d419b52fae34c0ceca09bfe0c6c4b7162f798be0c484d8f862935cdbbcb
6
+ metadata.gz: 76df2579cec51deb068e072ed2333ff2a2646c9238a8f1d9104b18231d52f6b27151eab69dd45de5402b308d12b302e0c9909a9cbfe87beab6c886c222e5b8e9
7
+ data.tar.gz: ba7a59272edf01fa33acc3b8aff2fbb2f61b8b7a165e526216fe5eee39b2f79875e282f094928aec15931adba35a96b8b545ad0dcc242dc2c003bf88122b0293
@@ -51,6 +51,10 @@ class UserAgent
51
51
 
52
52
  include Comparable
53
53
 
54
+ def detect_comment(&block)
55
+ comment && comment.detect(&block)
56
+ end
57
+
54
58
  # Any comparison between two user agents with different products will
55
59
  # always return false.
56
60
  def <=>(other)
@@ -57,8 +57,7 @@ class UserAgent
57
57
  true
58
58
  elsif os =~ /Android/
59
59
  true
60
- elsif application && application.comment &&
61
- application.comment.detect { |k, v| k =~ /^IEMobile/ }
60
+ elsif application && application.detect_comment { |c| c =~ /^IEMobile/ }
62
61
  true
63
62
  else
64
63
  false
@@ -119,7 +118,13 @@ class UserAgent
119
118
  end
120
119
 
121
120
  def detect_comment(comment)
122
- detect { |useragent| useragent.comment && useragent.comment.include?(comment) }
121
+ detect { |useragent| useragent.detect_comment { |c| c == comment } }
122
+ end
123
+
124
+ def detect_comment_match(regexp)
125
+ comment_match = nil
126
+ detect { |useragent| useragent.detect_comment { |c| comment_match = c.match(regexp) } }
127
+ comment_match
123
128
  end
124
129
  end
125
130
  end
@@ -26,14 +26,10 @@ class UserAgent
26
26
  private
27
27
 
28
28
  def os_comment
29
- if os_agent = detect { |useragent| comment_os_match(useragent) }
30
- comment_os_match(os_agent).to_s
29
+ if comment_match = detect_comment_match(OS_REGEXP)
30
+ comment_match.to_s
31
31
  end
32
32
  end
33
-
34
- def comment_os_match(useragent)
35
- useragent.comment && useragent.comment.join("; ").match(OS_REGEXP)
36
- end
37
33
  end
38
34
  end
39
35
  end
@@ -1,8 +1,11 @@
1
1
  class UserAgent
2
2
  module Browsers
3
3
  class Webkit < Base
4
+ WEBKIT_PRODUCT_REGEXP = /\AAppleWebKit\z/i
5
+ WEBKIT_VERSION_REGEXP = /\A(?<webkit>AppleWebKit)\/(?<version>[\d\.]+)/i
6
+
4
7
  def self.extend?(agent)
5
- agent.detect { |useragent| useragent.product =~ /\AAppleWebKit\z/i }
8
+ agent.detect { |useragent| useragent.product =~ WEBKIT_PRODUCT_REGEXP || useragent.detect_comment { |c| c =~ WEBKIT_VERSION_REGEXP } }
6
9
  end
7
10
 
8
11
  def browser
@@ -84,7 +87,11 @@ class UserAgent
84
87
  end
85
88
 
86
89
  def webkit
87
- detect { |useragent| useragent.product =~ /\AAppleWebKit\z/i }
90
+ if product_match = detect { |useragent| useragent.product =~ WEBKIT_PRODUCT_REGEXP }
91
+ product_match
92
+ elsif comment_match = detect_comment_match(WEBKIT_VERSION_REGEXP)
93
+ UserAgent.new(comment_match[:webkit], comment_match[:version])
94
+ end
88
95
  end
89
96
 
90
97
  def security
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: useragent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.6
4
+ version: 0.16.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Peek