browserino 1.3.0 → 1.4.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: b0c1778165ad285635aa2a94d77f330e3fd8ab13
4
- data.tar.gz: 47074688ffecb4510e46ac8267924611c5762f7a
3
+ metadata.gz: 7a557c586ae721cf86bd257419c005819b091627
4
+ data.tar.gz: 64a189ecc37fe48ae70c49771cdd6c802c1d7764
5
5
  SHA512:
6
- metadata.gz: ce7e65ae46fb6e4234576537d1b9a3f3d9133fbd3e0b1cc8099f6e94eba304f9b72503f682361687321eb1ab8ac39e681698cd9ec6dc3a377931a63ca87646e8
7
- data.tar.gz: f5d83f13710bbd03e0e1a02134bb288f36e47129ce6d35aa3f9d5f65b5988a9f71f3d806aea2e1fbd60c6d54ff39094d9bdbb65aa55ac185b948062239bb896d
6
+ metadata.gz: d7d73fb9dcb55af48db3a4da10d180978ea01deba02ba6f95954ad2eb521b1132c168aeef5da7d5801570a7ebb636486281b6ec5ef18164d11233e31d12da40e
7
+ data.tar.gz: 36dda426a5a4ac89bce0c423c5578c8c9262bc5102db24d93dc2a6122ecdf8e51111767b9734f5fabd0d95b652546008f4a3393733197f1c0625efe9b238538d
data/README.md CHANGED
@@ -9,6 +9,11 @@ This gem aims to provide information about the browser that your visitor is usin
9
9
  ## Changelog
10
10
  _dates are in dd-mm-yyyy format_
11
11
 
12
+ #### 19-12-2015 VERSION 1.4.0
13
+
14
+ - Added not method to invert questions about browser / system
15
+ - Added random test cases to verify that all inverted answers are correct
16
+
12
17
  #### 17-12-2015 VERSION 1.3.0
13
18
 
14
19
  - Added Edge detection
@@ -95,9 +100,18 @@ agent.macintosh?
95
100
  agent.linux?
96
101
  ```
97
102
 
98
- **note** Windows versions use their respective *NT* versioning so `agent.windows6?` equals `Vista` - I have yet to make changes to fix that. Browser versions use their actual version which always matches up with their real version, the same goes for the other systems.
103
+ You could also invert these questions by using the `.not` method
104
+
105
+
106
+ ```ruby
107
+ agent.not.android?
108
+ agent.not.ios?
109
+ agent.not.windows?
110
+ agent.not.macintosh?
111
+ agent.not.linux?
112
+ ```
99
113
 
100
- Supported browsers
114
+ Supported browsers
101
115
 
102
116
  ```ruby
103
117
  agent.opera?
@@ -107,6 +121,14 @@ agent.ie?
107
121
  agent.firefox?
108
122
  agent.chrome?
109
123
  agent.safari?
124
+
125
+ # or with the .not method
126
+
127
+ agent.not.opera?
128
+ agent.not.maxthon?
129
+
130
+ # etc etc...
131
+
110
132
  ```
111
133
 
112
134
  Since linux doesn't have any supported versions all you can pretty much do is check if `agent.linux?` is true if you want to check for linux systems. The others do have versions so if you wanted to check for windows 10 you could do:
@@ -115,6 +137,8 @@ Since linux doesn't have any supported versions all you can pretty much do is ch
115
137
  agent.windows10?
116
138
  ```
117
139
 
140
+ **note** Windows versions use their respective *NT* versioning so `agent.windows6?` equals `Vista` - I have yet to make changes to fix that. Browser versions use their actual version which always matches up with their real version, the same goes for the other systems.
141
+
118
142
  ## Development
119
143
 
120
144
  The tests are dynamically produced and quite easy to write.
@@ -5,6 +5,7 @@ module Browserino
5
5
  def initialize(hash, unknown = Browserino::UNKNOWN)
6
6
  @info = hash
7
7
  @unknown = unknown
8
+ @not = false
8
9
  end
9
10
 
10
11
  def browser_name
@@ -17,7 +18,6 @@ module Browserino
17
18
 
18
19
  def engine_name
19
20
  with_valid(@info[:engine_name]) { |v| v.to_s.downcase }
20
-
21
21
  end
22
22
 
23
23
  def engine_version
@@ -60,14 +60,25 @@ module Browserino
60
60
  end
61
61
  end
62
62
 
63
+ def not
64
+ @not = true
65
+ self
66
+ end
67
+
63
68
  def method_missing(method_sym, *args, &block)
64
69
  criteria = method_sym.to_s.gsub('?', '').split(/(?<=[a-zA-Z])(?=\d+)/)
65
70
  name = criteria[0]
66
- case browser_or_system?(method_sym)
71
+ res = case browser_or_system?(method_sym)
67
72
  when :system then correct_system?(*criteria)
68
73
  when :browser then correct_browser?(*criteria)
69
74
  else super
70
75
  end
76
+ if @not
77
+ @not = false
78
+ !res
79
+ else
80
+ res
81
+ end
71
82
  end
72
83
 
73
84
  def respond_to?(method_sym)
@@ -111,7 +122,10 @@ module Browserino
111
122
  system_version.gsub('.', '').to_i
112
123
  end
113
124
  if version && defined? const
114
- Browserino::Mapping.const_get(const).select { |name, versions| true if versions.include?(version) }.keys.first
125
+ version_names = Browserino::Mapping.const_get(const).select do |_, versions|
126
+ true if versions.include?(version)
127
+ end
128
+ version_names.keys.first
115
129
  else
116
130
  @unknown
117
131
  end
@@ -1,8 +1,11 @@
1
1
  module Browserino
2
2
  module Browser
3
3
  def self.version(ua, patterns)
4
- out = MatchExtractor::extract(ua.match(patterns[:version]), :version).to_s.downcase unless patterns.nil?
5
- out ||= Browserino::UNKNOWN
4
+ if patterns
5
+ MatchExtractor::extract(ua.match(patterns[:version]), :version)
6
+ else
7
+ Browserino::UNKNOWN
8
+ end
6
9
  end
7
10
  end
8
11
  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).to_s.downcase || Browserino::UNKNOWN
4
+ MatchExtractor::extract(ua.match(Browserino::PATTERNS[:engine][:name]), :name) || Browserino::UNKNOWN
5
5
  end
6
6
 
7
7
  def self.version(ua)
8
- MatchExtractor::extract(ua.match(Browserino::PATTERNS[:engine][:version]), :version).to_s.downcase || Browserino::UNKNOWN
8
+ MatchExtractor::extract(ua.match(Browserino::PATTERNS[:engine][:version]), :version) || Browserino::UNKNOWN
9
9
  end
10
10
  end
11
11
  end
@@ -5,7 +5,7 @@ module Browserino
5
5
  Browserino::UNKNOWN
6
6
  elsif match.names.map(&:to_sym).include?(sym)
7
7
  match[sym].strip! if trim
8
- match[sym]
8
+ match[sym].to_s.downcase
9
9
  else
10
10
  Browserino::UNKNOWN
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).to_s.downcase || Browserino::UNKNOWN
4
+ MatchExtractor::extract(ua.match(Browserino::PATTERNS[:operating_system][:name]), :name) || Browserino::UNKNOWN
5
5
  end
6
6
 
7
7
  def self.version(ua)
8
- MatchExtractor::extract(ua.match(Browserino::PATTERNS[:operating_system][:version]), :version).to_s.downcase || Browserino::UNKNOWN
8
+ MatchExtractor::extract(ua.match(Browserino::PATTERNS[:operating_system][:version]), :version) || Browserino::UNKNOWN
9
9
  end
10
10
 
11
11
  def self.architecture(ua)
12
- MatchExtractor::extract(ua.match(Browserino::PATTERNS[:operating_system][:architecture]), :architecture).to_s.downcase || Browserino::UNKNOWN
12
+ MatchExtractor::extract(ua.match(Browserino::PATTERNS[:operating_system][:architecture]), :architecture) || Browserino::UNKNOWN
13
13
  end
14
14
  end
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module Browserino
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
data/lib/browserino.rb CHANGED
@@ -16,6 +16,8 @@ require "browserino/browser"
16
16
  require "browserino/engine"
17
17
  require "browserino/operating_system"
18
18
 
19
+ # require_relative "../spec/user_agents.rb"
20
+
19
21
  module Browserino
20
22
  def self.parse(ua, unknown_alt = Browserino::UNKNOWN)
21
23
  ua = AgentManipulator.new(ua).ua
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: 1.3.0
4
+ version: 1.4.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: 2015-12-17 00:00:00.000000000 Z
11
+ date: 2015-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -169,3 +169,4 @@ signing_key:
169
169
  specification_version: 4
170
170
  summary: A browser identification gem
171
171
  test_files: []
172
+ has_rdoc: