browserino 1.0.1 → 1.0.2

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: 0f08ae3900de04e818da158b3f213e35d7ea8559
4
- data.tar.gz: d9a2ae06194faf027c91de73569e2d9054e8e970
3
+ metadata.gz: 09967128c9c89bc6bb97b7cd455ddf0a91f8947e
4
+ data.tar.gz: 57fff14bb77564131996b23d066764746692f8bf
5
5
  SHA512:
6
- metadata.gz: bac6047a73c354f69e1a3b6d95747381e61d8fa69e3773c231432d0b7f8b2adfa3db760bdbcb61d6bcc20f8a104235caf895c642fb9876be603a8f5776afbd6d
7
- data.tar.gz: 654765d84f9e822dd886ceb393bd7e4ba12831aaece76851689a27ffd4e7d320516769dac020ff4756b9a3759ce620102e249617585e7a816e05611fea42b5ec
6
+ metadata.gz: d55c9c93837fcfce61caf28ac2c845313b05c8aa6378b25ca0217fab37c919754a5d23972dfa947ade7b4a3b6fac71f5906b5bd77a805157883319b452c60ade
7
+ data.tar.gz: 0756df1c2c34208293f74aba43e670312e4a6ced67f03eb4bab2b78479e6096315736365a3f803617d7717c2856c1eefb240b2690dc3a861c29eb22a7174ffb7
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Browserino
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/browserino.svg)](http://badge.fury.io/rb/browserino)
3
4
  [![Build Status](https://travis-ci.org/SidOfc/browserino.svg?branch=master)](https://travis-ci.org/SidOfc/browserino)
4
5
  [![Coverage Status](https://coveralls.io/repos/SidOfc/browserino/badge.svg?branch=master&service=github)](https://coveralls.io/github/SidOfc/browserino?branch=master)
5
6
 
@@ -30,19 +31,6 @@ Or install it yourself as:
30
31
 
31
32
  ## Usage
32
33
 
33
- *Currently this gem has only functionality - On my list of tasks so far:*
34
-
35
- - Extract browser
36
- * name __- done__
37
- * version __- done__
38
- - Extract engine
39
- * name __- done__
40
- * version __- done__
41
- - Extract operating system
42
- * name __- done__
43
- * version __- done__
44
- * architecture
45
-
46
34
  After installing the gem globally or in your application you'll have to `require` the gem before being able to use it.
47
35
 
48
36
  ```ruby
@@ -57,26 +45,95 @@ Browserino::parse('<user agent>')
57
45
  Which will return a `Browserino::Agent` object containing all the information parsed out of the supplied user agent.
58
46
  On this object there are a few method calls you can do to retrieve information.
59
47
 
60
- ### general
61
48
  ```ruby
62
49
  require 'browserino'
63
50
 
64
- agent = Browserino::parse('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')
51
+ agent = Browserino::parse('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A')
65
52
 
66
- agent.browser_name # => safari
67
- agent.browser_version # => 6.0
53
+ agent.browser_name # => 'safari'
54
+ agent.browser_version # => 7.0.3
68
55
 
69
- agent.engine_name # => webkit
70
- agent.engine_version # => 536.26
56
+ agent.engine_name # => 'webkit'
57
+ agent.engine_version # => 537.75.14
71
58
 
72
- agent.system_name # => ios
59
+ agent.system_name # => 'macintosh'
60
+ # or optionally, the full name (guessed from OS version)
61
+ agent.system_name full: true # => ['macintosh', 'mavericks']
73
62
  agent.system_version # => 6.0
74
- agent.system_architecture # => unknown (though it will make an attempt)
63
+ agent.system_architecture # => 'x32' or 'x64' or 'unknown'
75
64
  ```
76
65
 
77
66
  ## Development
78
67
 
79
- *Should you want to contribute to the project the instructions for it will be here when version 1 releases (PENDING)*
68
+ 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.
69
+ 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.
70
+
71
+ The tests are dynamically produced and quite easy to write.
72
+
73
+ The __/spec/user_agents.rb__ actually contains the testcases, here you can see how they are setup and all you simply have to do is read the UA yourself and fill in the correct information for the test to run.
74
+ tests will convert all input to a string and downcase it for easier comparison (since the checks need to filter words and numbers, not types).
75
+
76
+ If I wanted to add a test case for a different browser for instance (just picking a random FF on windows that is already in the tests)
77
+
78
+ ```ruby
79
+ module UserAgents
80
+ FIREFOX = {
81
+ mac: {},
82
+ win: {
83
+ 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1' => {
84
+ browser_name: 'Firefox',
85
+ browser_version: '40.1',
86
+ engine_name: 'Gecko',
87
+ engine_version: '40.0',
88
+ system_name: ['windows', '7'],
89
+ system_version: '6.1',
90
+ system_architecture: 'x64'
91
+ },
92
+ },
93
+ linux: {}
94
+ }
95
+ end
96
+ ```
97
+
98
+ Valid browser names are defined by __/lib/browserino/patterns.rb__ (the keys are the browser names)
99
+
100
+ #### browser_name examples
101
+ ```ruby
102
+ 'unknown'
103
+ 'ie'
104
+ 'firefox'
105
+ 'chrome'
106
+ 'opera'
107
+ 'maxthon'
108
+ ```
109
+
110
+ #### engine_name examples
111
+ ```ruby
112
+ 'unknown'
113
+ 'gecko'
114
+ 'webkit'
115
+ 'trident'
116
+ ```
117
+
118
+ #### system_name examples
119
+
120
+ _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!)_
121
+
122
+ ```ruby
123
+ ['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)
124
+ ['macintosh', 'yosemite'] # same as above but OSX has different names ofcourse.
125
+ ['android', 'lollipop'] # etcetera...
126
+ ['unknown', 'unknown'] # in case it isn't known or in case of Linux
127
+ ```
128
+
129
+ #### system_architecture examples
130
+ ```ruby
131
+ 'unknown'
132
+ 'x32'
133
+ 'x64'
134
+ ```
135
+
136
+ __The value of unknown is a default error value that will always be available to test against. If it ain't known it's unknown__
80
137
 
81
138
  ## Contributing
82
139
 
@@ -7,19 +7,19 @@ module Browserino
7
7
  end
8
8
 
9
9
  def browser_name
10
- @info[:browser_name].downcase
10
+ @info[:browser_name].downcase || Browserino::UNKNOWN
11
11
  end
12
12
 
13
13
  def browser_version
14
- @info[:browser_version].gsub('_', '.').downcase
14
+ @info[:browser_version].gsub('_', '.').downcase || Browserino::UNKNOWN
15
15
  end
16
16
 
17
17
  def engine_name
18
- @info[:engine_name].downcase
18
+ @info[:engine_name].downcase || Browserino::UNKNOWN
19
19
  end
20
20
 
21
21
  def engine_version
22
- @info[:engine_version].gsub('_', '.').downcase
22
+ @info[:engine_version].gsub('_', '.').downcase || Browserino::UNKNOWN
23
23
  end
24
24
 
25
25
  def system_name(opts = {})
@@ -28,16 +28,16 @@ module Browserino
28
28
  if opts[:full]
29
29
  [name, fetch_system_version_name(name).downcase]
30
30
  else
31
- name
31
+ name || Browserino::UNKNOWN
32
32
  end
33
33
  end
34
34
 
35
35
  def system_version
36
- @info[:system_version].gsub('_', '.').downcase
36
+ @info[:system_version].gsub('_', '.').downcase || Browserino::UNKNOWN
37
37
  end
38
38
 
39
39
  def system_architecture
40
- @info[:system_architecture].downcase
40
+ @info[:system_architecture].downcase || Browserino::UNKNOWN
41
41
  end
42
42
 
43
43
  private
@@ -53,7 +53,7 @@ module Browserino
53
53
  if version && defined? const
54
54
  Browserino::Mapping.const_get(const).select { |name, versions| true if versions.include?(version) }.keys.first
55
55
  else
56
- 'unknown'
56
+ Browserino::UNKNOWN
57
57
  end
58
58
  end
59
59
  end
@@ -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)?[\d\.]+/i, '')
21
+ @ua = @ua.gsub(/ope?ra?(\/|\s)?9\.80/i, '')
22
22
  end
23
23
 
24
24
  def ua
@@ -2,28 +2,28 @@ module Browserino
2
2
  ALIAS = {
3
3
  browser_name: {
4
4
  'ie' => ['msie'],
5
- 'unknown' => ['unknown', :unknown, '']
5
+ Browserino::UNKNOWN => ['unknown', :unknown, '', nil]
6
6
  },
7
7
  browser_version: {
8
- 'unknown' => ['unknown', :unknown, '']
8
+ Browserino::UNKNOWN => ['unknown', :unknown, '', nil]
9
9
  },
10
10
  engine_name: {
11
11
  'webkit' => ['applewebkit'],
12
- 'unknown' => ['unknown', :unknown, '']
12
+ Browserino::UNKNOWN => ['unknown', :unknown, '', nil]
13
13
  },
14
14
  engine_version: {
15
- 'unknown' => ['unknown', :unknown, '']
15
+ Browserino::UNKNOWN => ['unknown', :unknown, '', nil]
16
16
  },
17
17
  system_name: {
18
- 'unknown' => ['unknown', :unknown, '']
18
+ Browserino::UNKNOWN => ['unknown', :unknown, '', nil]
19
19
  },
20
20
  system_version: {
21
- 'unknown' => ['unknown', :unknown, '']
21
+ Browserino::UNKNOWN => ['unknown', :unknown, '', nil]
22
22
  },
23
23
  system_architecture: {
24
24
  'x64' => ['64', 'x86_64'],
25
- 'x32' => ['32', 'i686', 'i383'],
26
- 'unknown' => ['unknown', :unknown, '', nil]
25
+ 'x32' => ['32', 'i686', 'i383', 'x86_32'],
26
+ Browserino::UNKNOWN => ['unknown', :unknown, '', nil]
27
27
  }
28
28
  }
29
29
  end
@@ -2,7 +2,7 @@ module Browserino
2
2
  module Browser
3
3
  def self.version(ua, patterns)
4
4
  out = MatchExtractor::extract(ua.match(patterns[:version]), :version).to_s.downcase unless patterns.nil?
5
- out ||= ''
5
+ out ||= Browserino::UNKNOWN
6
6
  end
7
7
  end
8
8
  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
4
+ MatchExtractor::extract(ua.match(Browserino::PATTERNS[:engine][:name]), :name).to_s.downcase || 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
8
+ MatchExtractor::extract(ua.match(Browserino::PATTERNS[:engine][:version]), :version).to_s.downcase || Browserino::UNKNOWN
9
9
  end
10
10
  end
11
11
  end
@@ -2,12 +2,12 @@ module Browserino
2
2
  module MatchExtractor
3
3
  def self.extract(match, sym, trim = true)
4
4
  if match.nil?
5
- :unknown
5
+ Browserino::UNKNOWN
6
6
  elsif match.names.map(&:to_sym).include?(sym)
7
7
  match[sym].strip! if trim
8
8
  match[sym]
9
9
  else
10
- :unknown
10
+ Browserino::UNKNOWN
11
11
  end
12
12
  end
13
13
  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
4
+ MatchExtractor::extract(ua.match(Browserino::PATTERNS[:operating_system][:name]), :name).to_s.downcase || 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
8
+ MatchExtractor::extract(ua.match(Browserino::PATTERNS[:operating_system][:version]), :version).to_s.downcase || 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
12
+ MatchExtractor::extract(ua.match(Browserino::PATTERNS[:operating_system][:architecture]), :architecture).to_s.downcase || Browserino::UNKNOWN
13
13
  end
14
14
  end
15
15
  end
@@ -0,0 +1,3 @@
1
+ module Browserino
2
+ UNKNOWN = 'unknown'
3
+ end
@@ -1,3 +1,3 @@
1
1
  module Browserino
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
data/lib/browserino.rb CHANGED
@@ -3,9 +3,11 @@ require "browserino/maps/ios"
3
3
  require "browserino/maps/android"
4
4
  require "browserino/maps/windows"
5
5
 
6
+ require "browserino/unknown"
7
+ require "browserino/agent"
8
+
6
9
  require "browserino/alias"
7
10
  require "browserino/agent_manipulator"
8
- require "browserino/agent"
9
11
  require "browserino/version"
10
12
  require "browserino/match_extractor"
11
13
  require "browserino/patterns"
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.0.1
4
+ version: 1.0.2
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-09-21 00:00:00.000000000 Z
11
+ date: 2015-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -142,6 +142,7 @@ files:
142
142
  - lib/browserino/match_extractor.rb
143
143
  - lib/browserino/operating_system.rb
144
144
  - lib/browserino/patterns.rb
145
+ - lib/browserino/unknown.rb
145
146
  - lib/browserino/version.rb
146
147
  homepage: https://github.com/SidOfc/browserino
147
148
  licenses: