browserino 4.1.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,13 +23,13 @@ module Browserino
23
23
  end
24
24
 
25
25
  def ===(other)
26
- return false if properties[:name].nil?
26
+ return false unless (name = properties[:name])
27
27
 
28
28
  case other
29
- when Regexp then other =~ properties[:name]
30
- when String then other.to_sym == properties[:name]
31
- when Symbol then other == properties[:name]
32
- when Matcher then other.properties[:name] == properties[:name]
29
+ when Regexp then other =~ name
30
+ when String then other.to_sym == name
31
+ when Symbol then other == name
32
+ when Matcher then other.name == name
33
33
  else false
34
34
  end
35
35
  end
@@ -4,20 +4,19 @@ module Browserino
4
4
  def self.analyze(ua, matcher = nil)
5
5
  @defaults ||= config.global_matchers.map(&:properties).reduce(&:merge)
6
6
 
7
- props = @defaults.merge(matcher && matcher.properties || {})
8
- like = props.delete :like
9
- props = collect props, ua
10
- props = collect_with_smart_watchers props, ua
11
- props = with_labels props
12
- like = Client.new props.merge(like_attrs(props, like, ua)) if like
7
+ props = @defaults.merge(matcher && matcher.properties || {})
8
+ like = props.delete :like
9
+ props = mass_collect props, ua
10
+ like = Client.new props.merge(like_attrs(props, like, ua)) if like
13
11
 
14
12
  Client.new props, like
15
13
  end
16
14
 
17
15
  def self.like_attrs(props, like, user_agent)
18
- lattrs = config.matchers.select { |m| m == like }.first.properties
16
+ version = config.matchers.select { |m| m == like }
17
+ .first.properties[:version]
19
18
  fattrs = { name: like }
20
- fattrs[:version] = lattrs[:version] if lattrs[:version].is_a? Regexp
19
+ fattrs[:version] = version if version.is_a? Regexp
21
20
  fattrs[:version] ||= smart_matchers(fattrs)[:version]
22
21
 
23
22
  props.dup.merge collect(fattrs, user_agent)
@@ -69,13 +68,19 @@ module Browserino
69
68
 
70
69
  def self.parse_detector(detect, properties)
71
70
  pat = properties.each_with_object(detect[:with].dup) do |(key, val), str|
72
- replacement = val.to_s.strip
71
+ replacement = val.to_s.strip.gsub '_', '[_\s-]'
73
72
  str.gsub! ":#{key}", replacement unless replacement.empty?
74
73
  end
75
74
 
76
75
  Regexp.new pat, get_flags(*detect[:flags].to_a)
77
76
  end
78
77
 
78
+ def self.mass_collect(props, ua)
79
+ props = collect props, ua
80
+ props = collect_with_smart_watchers props, ua
81
+ with_labels props
82
+ end
83
+
79
84
  def self.collect(properties, ua)
80
85
  properties.each_with_object({}) do |(n, v), r|
81
86
  r[n] = convert (v.is_a?(Regexp) ? v.match(ua).to_a[1] : v), format: n
@@ -92,16 +97,12 @@ module Browserino
92
97
  end
93
98
 
94
99
  def self.get_flags(*flags)
95
- val = 0
96
-
97
- flags.each do |flag|
100
+ flags.reduce(0) do |val, flag|
98
101
  case flag.to_sym
99
- when :m then val |= Regexp::MULTILINE
100
- when :i then val |= Regexp::IGNORECASE
101
- when :x then val |= Regexp::EXTENDED
102
+ when :m then val | Regexp::MULTILINE
103
+ when :i then val | Regexp::IGNORECASE
104
+ when :x then val | Regexp::EXTENDED
102
105
  end
103
106
  end
104
-
105
- val
106
107
  end
107
108
  end
@@ -24,6 +24,10 @@ module Browserino
24
24
  @options
25
25
  end
26
26
 
27
+ def to_h
28
+ @options
29
+ end
30
+
27
31
  def to_a
28
32
  @options.to_a
29
33
  end
@@ -32,6 +36,10 @@ module Browserino
32
36
  @options.to_s
33
37
  end
34
38
 
39
+ def to_str
40
+ to_s
41
+ end
42
+
35
43
  private
36
44
 
37
45
  def opt(sym)
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Browserino
4
- VERSION = '4.1.0'.freeze
5
-
6
- def self.version
7
- @version ||= Version.new VERSION.dup
4
+ def self.version(current = '4.2.0')
5
+ @version ||= Version.new current
8
6
  end
9
7
 
10
8
  # This class makes versions easily comparable using logical operators
@@ -77,6 +75,8 @@ module Browserino
77
75
  other = Version.new other unless other.is_a? Version
78
76
  subsize = [size, other.size].min
79
77
 
78
+ return if subsize.zero? && size > 0
79
+
80
80
  (self[0...subsize] <=> other[0...subsize]).send op, 0
81
81
  end
82
82
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browserino
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sidney Liebrand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-30 00:00:00.000000000 Z
11
+ date: 2017-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.14'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.14'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '12.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '12.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: codeclimate-test-reporter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description:
98
112
  email:
99
113
  - sidneyliebrand@gmail.com
@@ -102,6 +116,7 @@ executables:
102
116
  extensions: []
103
117
  extra_rdoc_files: []
104
118
  files:
119
+ - ".codeclimate.yml"
105
120
  - ".coveralls.yml"
106
121
  - ".gitignore"
107
122
  - ".rspec"
@@ -123,6 +138,14 @@ files:
123
138
  - lib/browserino/definitions/filters.rb
124
139
  - lib/browserino/definitions/labels.rb
125
140
  - lib/browserino/definitions/matchers.rb
141
+ - lib/browserino/definitions/matchers/bots.rb
142
+ - lib/browserino/definitions/matchers/browsers.rb
143
+ - lib/browserino/definitions/matchers/emails.rb
144
+ - lib/browserino/definitions/matchers/global.rb
145
+ - lib/browserino/definitions/matchers/libraries.rb
146
+ - lib/browserino/definitions/matchers/mediaplayers.rb
147
+ - lib/browserino/definitions/matchers/rss.rb
148
+ - lib/browserino/definitions/matchers/validators.rb
126
149
  - lib/browserino/integrate/action_controller.rb
127
150
  - lib/browserino/integrate/rails.rb
128
151
  - lib/browserino/matcher.rb
@@ -149,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
172
  version: '0'
150
173
  requirements: []
151
174
  rubyforge_project:
152
- rubygems_version: 2.6.8
175
+ rubygems_version: 2.6.12
153
176
  signing_key:
154
177
  specification_version: 4
155
178
  summary: A browser identification gem with command line and Rails (>= 3.2.0) integration