browserino 0.3.2 → 1.0.0

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: ad35d09a1a6278e60f23ce734ea23ecc5625656b
4
- data.tar.gz: 3a422fd663f391581b0189d2ca792c72611deb74
3
+ metadata.gz: 903638619bac70152006ad3f7f4f81f42ff912a2
4
+ data.tar.gz: e44bda5c85019d19eee5565c3fc3a984638b8a94
5
5
  SHA512:
6
- metadata.gz: 0a39500512bebd5272265e678252498ad8a514ec7883dbedf8a7cd200774a354cee423970b6715418847a8c2753f272f4fb39034ce7963c0ab03988b43c9ce75
7
- data.tar.gz: b7c75865e23b990c115fc93376bd5089599e00185701b84b2794ca6244a7d72362e509fc7eba646cfa2c8a22294255141657271b62657b55342432663b288b6a
6
+ metadata.gz: 3812f76cdca55381905d31f99b203cbf77f1e90e56ab1d88bbab87796afdc0d9e8c38a42cc810ba59d0e20589849e73ebbd332139a5d4f268da0e48c11da4188
7
+ data.tar.gz: 63eb1ce3ff47b142ad6bf04479445eb9c0b9f941b5fe2ae718d4cf613a2775b01c5df66eef394caeb6737de34e9e9decfcd23c48da46161579fc4197dbbe4258
data/.travis.yml CHANGED
@@ -3,9 +3,5 @@ rvm:
3
3
  - 2.2.1
4
4
  before_install: gem install bundler -v 1.10.5
5
5
 
6
- branches:
7
- only:
8
- - development
9
-
10
6
  cache: bundler
11
7
  script: 'bundle exec rspec spec'
data/README.md CHANGED
@@ -30,19 +30,50 @@ Or install it yourself as:
30
30
 
31
31
  ## Usage
32
32
 
33
- *Currently this gem has no functionality - On my list of tasks are:*
33
+ *Currently this gem has only functionality - On my list of tasks so far:*
34
34
 
35
35
  - Extract browser
36
- * name
37
- * version
36
+ * name __- done__
37
+ * version __- done__
38
38
  - Extract engine
39
- * name
40
- * version
39
+ * name __- done__
40
+ * version __- done__
41
41
  - Extract operating system
42
- * name
43
- * version
42
+ * name __- done__
43
+ * version __- done__
44
44
  * architecture
45
45
 
46
+ After installing the gem globally or in your application you'll have to `require` the gem before being able to use it.
47
+
48
+ ```ruby
49
+ require 'browserino'
50
+ ```
51
+
52
+ Afterwards you can simply call
53
+ ```ruby
54
+ Browserino::parse('<user agent>')
55
+ ```
56
+
57
+ Which will return a `Browserino::Agent` object containing all the information parsed out of the supplied user agent.
58
+ On this object there are a few method calls you can do to retrieve information.
59
+
60
+ ### general
61
+ ```ruby
62
+ require 'browserino'
63
+
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')
65
+
66
+ agent.browser_name # => safari
67
+ agent.browser_version # => 6.0
68
+
69
+ agent.engine_name # => applewebkit
70
+ agent.engine_version # => 536.26
71
+
72
+ agent.system_name # => ios
73
+ agent.system_version # => 6.0
74
+ agent.system_architecture # => unknown (though it will make an attempt)
75
+ ```
76
+
46
77
  ## Development
47
78
 
48
79
  *Should you want to contribute to the project the instructions for it will be here when version 1 releases*
data/bin/console CHANGED
@@ -3,9 +3,27 @@
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'
7
+ @agent = Browserino::parse(ua)
6
8
 
7
- @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')
8
-
9
- puts @agent
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_version
25
+ puts @agent.system_architecture
26
+ puts '================='
27
+ puts 'the @agent variable will be available at your disposal'
10
28
 
11
29
  Pry.start
@@ -0,0 +1,7 @@
1
+ module Browserino
2
+ ALIAS = {
3
+ 'webkit' => ['applewebkit'],
4
+ 'ie' => ['msie'],
5
+ 'unknown' => ['unknown', :unknown, '']
6
+ }
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Browserino
2
- VERSION = "0.3.2"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/browserino.rb CHANGED
@@ -3,6 +3,7 @@ require "browserino/maps/ios"
3
3
  require "browserino/maps/android"
4
4
  require "browserino/maps/windows"
5
5
 
6
+ require "browserino/alias"
6
7
  require "browserino/agent_manipulator"
7
8
  require "browserino/agent"
8
9
  require "browserino/version"
@@ -16,7 +17,7 @@ module Browserino
16
17
  def self.parse ua
17
18
  ua = AgentManipulator.new(ua).ua
18
19
  name = find_browser_name(ua)
19
- Agent.new({
20
+ Agent.new(check_for_aliases({
20
21
  browser_name: name,
21
22
  browser_version: Browser::version(ua, PATTERNS[:browser][name]),
22
23
  engine_name: Engine::name(ua),
@@ -24,12 +25,20 @@ module Browserino
24
25
  system_name: OperatingSystem::name(ua),
25
26
  system_version: OperatingSystem::version(ua),
26
27
  system_architecture: OperatingSystem::architecture(ua)
27
- })
28
+ }))
28
29
  end
29
30
 
30
31
  private
31
32
 
32
- def self.find_browser_name ua
33
+ def self.check_for_aliases(hash)
34
+ h = {}
35
+ hash.each do |prop, val|
36
+ h[prop] = ALIAS.select { |key, matches| true if matches.include?(val) }.keys.first || val
37
+ end
38
+ h
39
+ end
40
+
41
+ def self.find_browser_name(ua)
33
42
  name = nil
34
43
  browsers = PATTERNS[:browser].keys
35
44
  until browsers.empty? || !name.nil?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browserino
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sidney Liebrand
@@ -131,6 +131,7 @@ files:
131
131
  - lib/browserino.rb
132
132
  - lib/browserino/agent.rb
133
133
  - lib/browserino/agent_manipulator.rb
134
+ - lib/browserino/alias.rb
134
135
  - lib/browserino/browser.rb
135
136
  - lib/browserino/engine.rb
136
137
  - lib/browserino/maps/android.rb