brauser 3.2.2 → 3.2.3

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.
@@ -39,13 +39,14 @@ module Brauser
39
39
  # @return [Object|NilClass] A match if matcher succeeded, `nil` otherwise.
40
40
  def match(type, *args)
41
41
  matcher = self.send(type || :primary) rescue nil
42
+ target = args[1]
42
43
 
43
44
  if matcher.is_a?(::Regexp) then
44
- matcher.match(args[1])
45
+ matcher.match(target)
45
46
  elsif matcher.respond_to?(:call) then
46
47
  matcher.call(*args)
47
- elsif matcher
48
- args[1] == matcher ? args[1] : nil
48
+ elsif target == matcher
49
+ target
49
50
  else
50
51
  nil
51
52
  end
data/lib/brauser/query.rb CHANGED
@@ -24,7 +24,8 @@ module Brauser
24
24
 
25
25
  # Checks if the browser is a specific version.
26
26
  #
27
- # @param versions [String|Hash] A string in the form `operator version && ...` (example: `>= 7 && < 4`) or an hash with specific version to match against, in form `{:operator => version}`, where operator is one of `:lt, :lte, :eq, :gt, :gte`.
27
+ # @param versions [String|Hash] A string in the form `operator version && ...` (example: `>= 7 && < 4`) or an hash with specific version to match against,
28
+ # in form `{:operator => version}`, where operator is one of `:lt, :lte, :eq, :gt, :gte`.
28
29
  # @return [Query] The query itself.
29
30
  def v(versions = {})
30
31
  @result = v?(versions)
@@ -71,7 +72,8 @@ module Brauser
71
72
  #
72
73
  # This version returns a boolean and it is equal to append a call to `#result` to the method `#v`.
73
74
  #
74
- # @param versions [String|Hash] A string in the form `operator version && ...` (example: `>= 7 && < 4`) or an hash with specific version to match against, in form `{:operator => version}`, where operator is one of `:lt, :lte, :eq, :gt, :gte`.
75
+ # @param versions [String|Hash] A string in the form `operator version && ...` (example: `>= 7 && < 4`) or an hash with specific version to match against,
76
+ # in form `{:operator => version}`, where operator is one of `:lt, :lte, :eq, :gt, :gte`.
75
77
  # @return [Boolean] `true` if current browser matches, `false` otherwise.
76
78
  def v?(versions = {})
77
79
  @result ? @target.v?(versions) : @result
@@ -16,7 +16,7 @@ module Brauser
16
16
  MINOR = 2
17
17
 
18
18
  # The patch version.
19
- PATCH = 2
19
+ PATCH = 3
20
20
 
21
21
  # The current version of brauser.
22
22
  STRING = [MAJOR, MINOR, PATCH].compact.join(".")
@@ -500,6 +500,22 @@ describe Brauser::Browser do
500
500
  end
501
501
  end
502
502
 
503
+ describe "#supported?" do
504
+ it "should check if the browser is supported starting from a definition map" do
505
+ browser.parse_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.82 Safari/537.1")
506
+ expect(browser.supported?(chrome: 21)).to be_true
507
+ expect(browser.supported?(chrome: 31)).to be_false
508
+ expect(browser.supported?(chrome: "21.2")).to be_false
509
+ expect(browser.supported?(firefox: 11)).to be_false
510
+ end
511
+
512
+ it "should load definition files from a YAML file" do
513
+ path = File.dirname(__FILE__) + "/../supported.yml"
514
+ browser.parse_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.82 Safari/537.1")
515
+ expect(browser.supported?(path)).to be_true
516
+ end
517
+ end
518
+
503
519
  describe "#initalize" do
504
520
  it "initialized definitions" do
505
521
  expect(::Brauser::Browser).to receive(:add_default_browsers)
@@ -0,0 +1,3 @@
1
+ ---
2
+ chrome: 21
3
+ firefox: 31
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brauser
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.2
4
+ version: 3.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shogun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-18 00:00:00.000000000 Z
11
+ date: 2013-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lazier
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 3.3.1
19
+ version: 3.3.9
20
20
  type: :runtime
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: 3.3.1
26
+ version: 3.3.9
27
27
  description: A framework agnostic browser detection and querying helper.
28
28
  email:
29
29
  - shogun@cowtech.it
@@ -35,6 +35,7 @@ files:
35
35
  - .travis-gemfile
36
36
  - .travis.yml
37
37
  - .yardopts
38
+ - CHANGELOG.md
38
39
  - Gemfile
39
40
  - README.md
40
41
  - Rakefile
@@ -83,8 +84,10 @@ files:
83
84
  - spec/brauser/query_spec.rb
84
85
  - spec/coverage_helper.rb
85
86
  - spec/spec_helper.rb
87
+ - spec/supported.yml
86
88
  homepage: http://sw.cow.tc/brauser
87
- licenses: []
89
+ licenses:
90
+ - MIT
88
91
  metadata: {}
89
92
  post_install_message:
90
93
  rdoc_options: []
@@ -113,4 +116,5 @@ test_files:
113
116
  - spec/brauser/query_spec.rb
114
117
  - spec/coverage_helper.rb
115
118
  - spec/spec_helper.rb
119
+ - spec/supported.yml
116
120
  has_rdoc: