browserino 1.1.2 → 1.2.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: 829974a6744a8e99a66ca28dd8a73298e647bb09
4
- data.tar.gz: f8930fa43ae37894a805e84747b8f3aaf4a89386
3
+ metadata.gz: 04172a00c8555e14df05ea14f1a49bade29c8ed5
4
+ data.tar.gz: 36265c36de92a49f1667413b8617f0dd06098889
5
5
  SHA512:
6
- metadata.gz: 58351ed9e54ffb8e1a5889780a6dfeca4ee8deea880253c26b9a39cc6c4f922d2e4b314f06a78d694b13db4c1efae4437ee8f851b1bb96afdfba5e381ec253fa
7
- data.tar.gz: 897d7f2b7e3d3460b147883919e3f872ccb311256e8811c79e2ce02b11c7111c639e15d1b4ed9ed7213a41321b7a73444f2b541b36bc03fce0210605077b6545
6
+ metadata.gz: c5fed0edd65dc6e5d7aaa01631ae04d9a55e3a424a6e9d0a1ea7f808f6f3142c3ebc664aee50866ebbbe74817ad6c0bd799c2381eea26f38724b56587ff3a503
7
+ data.tar.gz: 17c7df4a9eebd05668932c3702d66335ed5a13855941c403c6146b7a0d0fc90902c12714bd65a92e3e9c7008657a649a2ab081e7cb188340b52e16482e4b663e
data/README.md CHANGED
@@ -6,12 +6,23 @@
6
6
 
7
7
  This gem aims to provide information about the browser that your visitor is using, it's main goal is not to let you exclude any browser from partying on your website (e.g. sniffing) but to provide you with more flexibility towards designing maybe a browser-themed website or knowledge of what your visitors are using to check out your website!
8
8
 
9
- ## About the developer
9
+ ## Changelog
10
+ _dates are in dd-mm-yyyy format_
10
11
 
11
- Hey there everone, my name is Sidney Liebrand and I aim to become a contributor to various open source projects as I gain experience in working with the community.
12
- For now All I'm going to say is that I'm not that experienced with git yet or how things go so bear with me should I make any mistake.
12
+ #### 16-12-2015 VERSION 1.2.0
13
13
 
14
- If anyone ofcourse desires to manage this project with me feel free to add me on skype: *sidney.liebrand*
14
+ - 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?`
22
+
23
+ #### 15-12-2015 VERSION 1.1.2
24
+
25
+ - User definable 'unknown' return value
15
26
 
16
27
  ## Installation
17
28
 
@@ -38,11 +49,20 @@ require 'browserino'
38
49
  ```
39
50
 
40
51
  Afterwards you can simply call
52
+
41
53
  ```ruby
42
54
  Browserino::parse('<user agent>')
43
55
  ```
56
+ Optionally if you're using a version _>=_ than _1.1.2_ you can set a return value in place of `nil` when running `::parse(...)`.
57
+ If you want any unknown properties to return the string `unknown` you could do so like this:
58
+
59
+ ```ruby
60
+ Browserino::parse('<user agent>', 'unknown')
61
+ ```
62
+
63
+ Without specifying the second argument the value for unknown properties will always be `nil`
44
64
 
45
- Which will return a `Browserino::Agent` object containing all the information parsed out of the supplied user agent.
65
+ `Browserino::parse()` will return a `Browserino::Agent` object containing all the information parsed out of the supplied user agent.
46
66
  On this object there are a few method calls you can do to retrieve information.
47
67
 
48
68
  ```ruby
data/bin/console CHANGED
@@ -3,28 +3,31 @@
3
3
  require "bundler/setup"
4
4
  require "browserino"
5
5
  require "pry"
6
- ua = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25'
6
+ # ua = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25'
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'
7
8
  @agent = Browserino::parse(ua)
8
9
 
9
- puts "parsed #{ua} with results:"
10
- puts '------------------'
11
- puts '| browser |'
12
- puts '------------------'
13
- puts @agent.browser_name
14
- puts @agent.browser_version
15
- puts '------------------'
16
- puts '| engine |'
17
- puts '------------------'
18
- puts @agent.engine_name
19
- puts @agent.engine_version
20
- puts '------------------'
21
- puts '| system |'
22
- puts '------------------'
23
- puts @agent.system_name
24
- puts @agent.system_name(full: true)[1]
25
- puts @agent.system_version
26
- puts @agent.system_architecture
27
- puts '================='
28
- puts 'the @agent variable will be available at your disposal'
10
+ puts @agent.windows10?
29
11
 
12
+ # puts "parsed #{ua} with results:"
13
+ # puts '------------------'
14
+ # puts '| browser |'
15
+ # puts '------------------'
16
+ # puts @agent.browser_name
17
+ # puts @agent.browser_version
18
+ # puts '------------------'
19
+ # puts '| engine |'
20
+ # puts '------------------'
21
+ # puts @agent.engine_name
22
+ # puts @agent.engine_version
23
+ # puts '------------------'
24
+ # puts '| system |'
25
+ # puts '------------------'
26
+ # puts @agent.system_name
27
+ # puts @agent.system_name(full: true)[1]
28
+ # puts @agent.system_version
29
+ # puts @agent.system_architecture
30
+ # puts '================='
31
+ # puts 'the @agent variable will be available at your disposal'
32
+ #
30
33
  Pry.start
@@ -25,7 +25,7 @@ module Browserino
25
25
  end
26
26
 
27
27
  def system_name(opts = {})
28
- opts = {full: true}.merge(opts)
28
+ opts = {full: false}.merge(opts)
29
29
  name = with_valid(@info[:system_name]) { |v| v.to_s.downcase }
30
30
  if opts[:full]
31
31
  [name, fetch_system_version_name(name)]
@@ -42,6 +42,28 @@ module Browserino
42
42
  with_valid(@info[:system_architecture]) { |v| v.to_s.downcase }
43
43
  end
44
44
 
45
+ def method_missing(method_sym, *args, &block)
46
+ criteria = method_sym.to_s.gsub('?', '').split(/(?<=[a-zA-Z])(?=\d+)/)
47
+ 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
59
+ end
60
+ end
61
+
62
+ 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)
65
+ end
66
+
45
67
  private
46
68
 
47
69
  def with_valid(val)
@@ -58,11 +80,13 @@ module Browserino
58
80
  return @unknown if name.nil? || name == '' || !name
59
81
  const = name.upcase
60
82
  name.downcase!
61
- if name.match(/mac|ios/i)
62
- version = system_version.split('.').first(2).join.to_i
63
- elsif name.match(/win|android/i)
64
- version = system_version.gsub('.', '').to_i
65
- end
83
+ version = if system_version == @unknown
84
+ nil
85
+ elsif name.match(/mac|ios/i)
86
+ system_version.split('.').first(2).join.to_i
87
+ elsif name.match(/win|android/i)
88
+ system_version.gsub('.', '').to_i
89
+ end
66
90
  if version && defined? const
67
91
  Browserino::Mapping.const_get(const).select { |name, versions| true if versions.include?(version) }.keys.first
68
92
  else
@@ -18,7 +18,7 @@ module Browserino
18
18
  end
19
19
 
20
20
  def strip_fake_opera_version!
21
- @ua = @ua.gsub(/ope?ra?(\/|\s)?9\.80/i, '')
21
+ @ua = @ua.gsub(/9\.80/i, '')
22
22
  end
23
23
 
24
24
  def ua
@@ -15,7 +15,8 @@ module Browserino
15
15
  Browserino::UNKNOWN => ['unknown', :unknown, '', nil]
16
16
  },
17
17
  system_name: {
18
- Browserino::UNKNOWN => ['unknown', :unknown, '', nil]
18
+ Browserino::UNKNOWN => ['unknown', :unknown, '', nil],
19
+ 'linux' => ['ubuntu']
19
20
  },
20
21
  system_version: {
21
22
  Browserino::UNKNOWN => ['unknown', :unknown, '', nil]
@@ -38,7 +38,7 @@ module Browserino
38
38
  },
39
39
 
40
40
  operating_system: {
41
- name: /(?<name>windows|macintosh|android|ios|linux)/i,
41
+ name: /(?<name>windows|macintosh|android|ios|linux|ubuntu)/i,
42
42
  version: /(?:nt|mac\sos\sx|android|(cpu\s|i)os)\s(?<version>[\d\._]+)/i,
43
43
  architecture: /(?<architecture>(x?(86_)?64)|i(3|6)86)/i
44
44
  }
@@ -1,3 +1,3 @@
1
1
  module Browserino
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0"
3
3
  end
data/lib/browserino.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "browserino/maps/osx"
2
2
  require "browserino/maps/ios"
3
+ require "browserino/maps/linux"
3
4
  require "browserino/maps/android"
4
5
  require "browserino/maps/windows"
5
6
 
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.1.2
4
+ version: 1.2.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-15 00:00:00.000000000 Z
11
+ date: 2015-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler