browserino 1.4.0 → 1.5.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: 7a557c586ae721cf86bd257419c005819b091627
4
- data.tar.gz: 64a189ecc37fe48ae70c49771cdd6c802c1d7764
3
+ metadata.gz: 0985bfbbaf7922a31610653d71982e3c936ac386
4
+ data.tar.gz: 506e7d3941a34945d0039e8505fcd3708adf64f4
5
5
  SHA512:
6
- metadata.gz: d7d73fb9dcb55af48db3a4da10d180978ea01deba02ba6f95954ad2eb521b1132c168aeef5da7d5801570a7ebb636486281b6ec5ef18164d11233e31d12da40e
7
- data.tar.gz: 36dda426a5a4ac89bce0c423c5578c8c9262bc5102db24d93dc2a6122ecdf8e51111767b9734f5fabd0d95b652546008f4a3393733197f1c0625efe9b238538d
6
+ metadata.gz: 064c7865d9886f3357584b1d9fb71c49c2d0b06fdeb52ae852b82aed33cc22be7a637b2f114011d3f6ade358d571942397776c24377830b3a477e348cb3f77cf
7
+ data.tar.gz: f2c86ebf7dc2df2b7ab77f439f82fa68c9dec06ee15640afbba1b902c6a3cecde291d474a4b3778148017791521478bb39c4a5e39bdd24866355ebe6db30cce6
data/README.md CHANGED
@@ -9,6 +9,13 @@ 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.5.0
13
+
14
+ - Implemented to_s to return a concatenated string of property values
15
+ - Implemented to_a to return an array with arrays containing property name-value pairs
16
+ - Implemented to_h to return a hash containing property name-value pairs
17
+ - Removed unused code
18
+
12
19
  #### 19-12-2015 VERSION 1.4.0
13
20
 
14
21
  - Added not method to invert questions about browser / system
@@ -85,6 +92,27 @@ agent.system_name # => 'macintosh'
85
92
  agent.system_name full: true # => ['macintosh', 'mavericks']
86
93
  agent.system_version # => 6.0
87
94
  agent.system_architecture # => 'x32' or 'x64' or 'unknown'
95
+
96
+ # methods to convert object into a String, Array or hash
97
+ agent.to_s # => 'safari safari7 webkit webkit537 macintosh macintosh10'
98
+ agent.to_a # => [
99
+ # [:browser_name, 'safari'],
100
+ # [:browser_version, '7.0.3'],
101
+ # [:engine_name, 'webkit'],
102
+ # [:engine_version, '537.75.14'],
103
+ # [:system_name, 'macintosh'],
104
+ # [:system_version, '10'],
105
+ # [:system_architecture, nil]
106
+ # ]
107
+ agent.to_h # => {
108
+ # browser_name: 'safari',
109
+ # browser_version: '7.0.3',
110
+ # engine_name: 'webkit',
111
+ # engine_version: '537.75.14',
112
+ # system_name: 'macintosh',
113
+ # system_version: '10',
114
+ # system_architecture: nil
115
+ # }
88
116
  ```
89
117
 
90
118
  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
@@ -1,7 +1,5 @@
1
1
  module Browserino
2
2
  class Agent
3
- attr_accessor :info
4
-
5
3
  def initialize(hash, unknown = Browserino::UNKNOWN)
6
4
  @info = hash
7
5
  @unknown = unknown
@@ -60,17 +58,12 @@ module Browserino
60
58
  end
61
59
  end
62
60
 
63
- def not
64
- @not = true
65
- self
66
- end
67
-
68
61
  def method_missing(method_sym, *args, &block)
69
62
  criteria = method_sym.to_s.gsub('?', '').split(/(?<=[a-zA-Z])(?=\d+)/)
70
63
  name = criteria[0]
71
64
  res = case browser_or_system?(method_sym)
72
- when :system then correct_system?(*criteria)
73
- when :browser then correct_browser?(*criteria)
65
+ when :system then correct_system?(criteria[0], criteria[1])
66
+ when :browser then correct_browser?(criteria[0], criteria[1])
74
67
  else super
75
68
  end
76
69
  if @not
@@ -85,6 +78,38 @@ module Browserino
85
78
  browser_or_system?(method_sym).nil?
86
79
  end
87
80
 
81
+ def not
82
+ @not = true
83
+ self
84
+ end
85
+
86
+ def to_s
87
+ props = @info.map do |k, _v|
88
+ res = send k
89
+ case k
90
+ when :system_version
91
+ system_name + res.to_s.split('.').first.to_s
92
+ when :engine_version
93
+ engine_name + res.to_s.split('.').first.to_s
94
+ when :browser_version
95
+ browser_name + res.to_s.split('.').first.to_s
96
+ else res
97
+ end
98
+ end
99
+ props.compact.join(' ')
100
+ end
101
+
102
+ def to_a
103
+ @info.inject([]) do |memo, arr|
104
+ memo.push [arr.first, send(arr.first)]
105
+ memo
106
+ end
107
+ end
108
+
109
+ def to_h
110
+ to_a.to_h
111
+ end
112
+
88
113
  private
89
114
 
90
115
  def browser_or_system?(method_sym)
@@ -1,9 +1,7 @@
1
1
  module Browserino
2
2
  module MatchExtractor
3
3
  def self.extract(match, sym, trim = true)
4
- if match.nil?
5
- Browserino::UNKNOWN
6
- elsif match.names.map(&:to_sym).include?(sym)
4
+ if match && match.names.map(&:to_sym).include?(sym)
7
5
  match[sym].strip! if trim
8
6
  match[sym].to_s.downcase
9
7
  else
@@ -1,3 +1,3 @@
1
1
  module Browserino
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.0"
3
3
  end
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: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sidney Liebrand