browserino 1.2.0 → 1.3.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: 04172a00c8555e14df05ea14f1a49bade29c8ed5
4
- data.tar.gz: 36265c36de92a49f1667413b8617f0dd06098889
3
+ metadata.gz: b0c1778165ad285635aa2a94d77f330e3fd8ab13
4
+ data.tar.gz: 47074688ffecb4510e46ac8267924611c5762f7a
5
5
  SHA512:
6
- metadata.gz: c5fed0edd65dc6e5d7aaa01631ae04d9a55e3a424a6e9d0a1ea7f808f6f3142c3ebc664aee50866ebbbe74817ad6c0bd799c2381eea26f38724b56587ff3a503
7
- data.tar.gz: 17c7df4a9eebd05668932c3702d66335ed5a13855941c403c6146b7a0d0fc90902c12714bd65a92e3e9c7008657a649a2ab081e7cb188340b52e16482e4b663e
6
+ metadata.gz: ce7e65ae46fb6e4234576537d1b9a3f3d9133fbd3e0b1cc8099f6e94eba304f9b72503f682361687321eb1ab8ac39e681698cd9ec6dc3a377931a63ca87646e8
7
+ data.tar.gz: f5d83f13710bbd03e0e1a02134bb288f36e47129ce6d35aa3f9d5f65b5988a9f71f3d806aea2e1fbd60c6d54ff39094d9bdbb65aa55ac185b948062239bb896d
data/README.md CHANGED
@@ -9,16 +9,15 @@ 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
+ #### 17-12-2015 VERSION 1.3.0
13
+
14
+ - Added Edge detection
15
+ - For supported browsers, it is now possible to check name and version through `method_missing?`
16
+
12
17
  #### 16-12-2015 VERSION 1.2.0
13
18
 
14
19
  - Opera tests didn't run before
15
- - For supported systems, it is possible to check OS and version. This is true for `android`, `macintosh`, `ios`, `windows` and `linux` *(any version number can optionally be included)*
16
-
17
- - `agent.windows?`
18
- - `agent.windows10?`
19
- - `agent.macintosh?`
20
- - `agent.macintosh10?`
21
- - `agent.linux?`
20
+ - For supported systems, it is possible to check OS and version through `method_missing?`
22
21
 
23
22
  #### 15-12-2015 VERSION 1.1.2
24
23
 
@@ -83,10 +82,40 @@ agent.system_version # => 6.0
83
82
  agent.system_architecture # => 'x32' or 'x64' or 'unknown'
84
83
  ```
85
84
 
86
- ## Development
85
+ 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
86
+ 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.
87
+
88
+ Supported systems
89
+
90
+ ```ruby
91
+ agent.android?
92
+ agent.ios?
93
+ agent.windows?
94
+ agent.macintosh?
95
+ agent.linux?
96
+ ```
97
+
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.
87
99
 
88
- Currently things are actually going quite well besides the fact that I am trying to learn multiple techniques at the same time thus causing code to sometimes... well be messy at best.
89
- What I would not want you all to do is dive in there and try to understand it (tho if you do and want in, let me know!) but I would greatly appriciate help regarding the testing of this sniffer.
100
+ Supported browsers
101
+
102
+ ```ruby
103
+ agent.opera?
104
+ agent.maxthon?
105
+ agent.edge?
106
+ agent.ie?
107
+ agent.firefox?
108
+ agent.chrome?
109
+ agent.safari?
110
+ ```
111
+
112
+ 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:
113
+
114
+ ```ruby
115
+ agent.windows10?
116
+ ```
117
+
118
+ ## Development
90
119
 
91
120
  The tests are dynamically produced and quite easy to write.
92
121
 
@@ -137,7 +166,7 @@ Valid browser names are defined by __/lib/browserino/patterns.rb__ (the keys are
137
166
 
138
167
  #### system_name examples
139
168
 
140
- _The main reason for not having Linux distro's / versions yet is because of the fact that there are MANY different distro's with no real structured release system (going to work on that whenever there's free time!)_
169
+ _The main reason for not having Linux distro's / versions <strike>yet</strike> is because of the fact that there are MANY different distro's with no real structured release system. <strike>(going to work on that whenever there's free time!)</strike>_
141
170
 
142
171
  ```ruby
143
172
  ['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)
data/bin/console CHANGED
@@ -7,7 +7,10 @@ require "pry"
7
7
  ua = 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10136'
8
8
  @agent = Browserino::parse(ua)
9
9
 
10
- puts @agent.windows10?
10
+ puts ua
11
+ puts "@agent.windows10? #=> #{@agent.windows10?}"
12
+ puts "@agent.edge? #=> #{@agent.edge?}"
13
+ puts "@agent.edge12? #=> #{@agent.edge12?}"
11
14
 
12
15
  # puts "parsed #{ua} with results:"
13
16
  # puts '------------------'
@@ -42,30 +42,53 @@ module Browserino
42
42
  with_valid(@info[:system_architecture]) { |v| v.to_s.downcase }
43
43
  end
44
44
 
45
+ def correct_system?(name, version = nil)
46
+ os_equal = (name == system_name)
47
+ if version
48
+ os_equal && version == system_version.to_s[0..(version.size - 1)]
49
+ else
50
+ os_equal
51
+ end
52
+ end
53
+
54
+ def correct_browser?(name, version = nil)
55
+ browser_equal = (name == browser_name)
56
+ if version
57
+ browser_equal && version == browser_version.to_s[0..(version.size - 1)]
58
+ else
59
+ browser_equal
60
+ end
61
+ end
62
+
45
63
  def method_missing(method_sym, *args, &block)
46
64
  criteria = method_sym.to_s.gsub('?', '').split(/(?<=[a-zA-Z])(?=\d+)/)
47
65
  name = criteria[0]
48
- if respond_to? name
49
- os_equal = (name == system_name)
50
- return os_equal unless criteria.size > 1
51
- if criteria.size > 1
52
- version = criteria[1]
53
- os_equal && version == system_version.to_s[0..(version.size - 1)]
54
- else
55
- os_equal
56
- end
57
- else
58
- super
66
+ case browser_or_system?(method_sym)
67
+ when :system then correct_system?(*criteria)
68
+ when :browser then correct_browser?(*criteria)
69
+ else super
59
70
  end
60
71
  end
61
72
 
62
73
  def respond_to?(method_sym)
63
- name = method_sym.to_s.gsub('?', '').split(/(?<=[a-zA-Z])(?=\d+)/).first
64
- Browserino::Mapping.constants(true).include?(name.upcase.to_sym)
74
+ browser_or_system?(method_sym).nil?
65
75
  end
66
76
 
67
77
  private
68
78
 
79
+ def browser_or_system?(method_sym)
80
+ name = method_sym.to_s.gsub('?', '').split(/(?<=[a-zA-Z])(?=\d+)/).first
81
+ sys = Browserino::Mapping.constants(true).include?(name.upcase.to_sym)
82
+ browser = Browserino::PATTERNS[:browser].keys.include?(name.to_sym)
83
+ if sys
84
+ :system
85
+ elsif browser
86
+ :browser
87
+ else
88
+ nil
89
+ end
90
+ end
91
+
69
92
  def with_valid(val)
70
93
  if val && (val != '' || val != false) && block_given?
71
94
  res = yield(val)
@@ -11,6 +11,11 @@ module Browserino
11
11
  version: /maxthon(?:\s|\/)(?<version>[\d\.]+)/i
12
12
  },
13
13
 
14
+ edge: {
15
+ name: /(?<name>edge)/i,
16
+ version: /(?:edge\/)(?<version>[\d\.b]+)/i
17
+ },
18
+
14
19
  ie: {
15
20
  name: /(?<name>msie|trident)/i,
16
21
  version: /(?:(?:ms)?ie\s|rv\:)(?<version>[\d\.b]+)/i
@@ -1,3 +1,3 @@
1
1
  module Browserino
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  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: 1.2.0
4
+ version: 1.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: 2015-12-16 00:00:00.000000000 Z
11
+ date: 2015-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler