brauser 3.3.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/.travis-gemfile +4 -5
  4. data/.travis.yml +2 -2
  5. data/CHANGELOG.md +4 -0
  6. data/Gemfile +7 -8
  7. data/README.md +31 -95
  8. data/Rakefile +0 -1
  9. data/brauser.gemspec +4 -4
  10. data/default_definitions/browsers.rb +50 -0
  11. data/default_definitions/languages.rb +118 -0
  12. data/default_definitions/platforms.rb +24 -0
  13. data/doc/Brauser.html +6 -6
  14. data/doc/Brauser/Browser.html +3867 -580
  15. data/doc/Brauser/Definitions.html +537 -0
  16. data/doc/Brauser/Definitions/Base.html +342 -0
  17. data/doc/Brauser/Definitions/Browser.html +1047 -0
  18. data/doc/Brauser/Definitions/Language.html +496 -0
  19. data/doc/Brauser/Definitions/Platform.html +686 -0
  20. data/doc/Brauser/Hooks.html +2 -2
  21. data/doc/Brauser/Hooks/RubyOnRails.html +9 -9
  22. data/doc/Brauser/Parser.html +513 -0
  23. data/doc/Brauser/Value.html +601 -0
  24. data/doc/Brauser/Version.html +5 -5
  25. data/doc/_index.html +25 -108
  26. data/doc/class_list.html +1 -1
  27. data/doc/file.README.html +33 -97
  28. data/doc/index.html +33 -97
  29. data/doc/method_list.html +72 -120
  30. data/doc/top-level-namespace.html +2 -2
  31. data/lib/brauser.rb +13 -15
  32. data/lib/brauser/browser.rb +195 -66
  33. data/lib/brauser/definitions/base.rb +71 -0
  34. data/lib/brauser/definitions/browser.rb +80 -0
  35. data/lib/brauser/definitions/language.rb +29 -0
  36. data/lib/brauser/definitions/platform.rb +42 -0
  37. data/lib/brauser/hooks.rb +1 -2
  38. data/lib/brauser/parser.rb +47 -0
  39. data/lib/brauser/value.rb +39 -0
  40. data/lib/brauser/version.rb +3 -4
  41. data/spec/brauser/browser_spec.rb +73 -564
  42. data/spec/brauser/default_definitions_spec.rb +129 -0
  43. data/spec/brauser/definitions/base_spec.rb +48 -0
  44. data/spec/brauser/definitions/browser_spec.rb +47 -0
  45. data/spec/brauser/definitions/language_spec.rb +18 -0
  46. data/spec/brauser/definitions/platform_spec.rb +36 -0
  47. data/spec/brauser/hooks_spec.rb +5 -6
  48. data/spec/brauser/parser_spec.rb +31 -0
  49. data/spec/brauser/value_spec.rb +34 -0
  50. data/spec/coverage_helper.rb +0 -1
  51. data/spec/spec_helper.rb +0 -1
  52. metadata +50 -23
  53. data/lib/brauser/browseable/attributes.rb +0 -95
  54. data/lib/brauser/browseable/general.rb +0 -104
  55. data/lib/brauser/browseable/parsing.rb +0 -127
  56. data/lib/brauser/browseable/partial_querying.rb +0 -116
  57. data/lib/brauser/browseable/querying.rb +0 -63
  58. data/lib/brauser/browseable/register.rb +0 -73
  59. data/lib/brauser/definition.rb +0 -80
  60. data/lib/brauser/definitions/browsers.rb +0 -68
  61. data/lib/brauser/definitions/languages.rb +0 -130
  62. data/lib/brauser/definitions/platforms.rb +0 -30
  63. data/lib/brauser/query.rb +0 -36
  64. data/lib/brauser/queryable/chainers.rb +0 -56
  65. data/lib/brauser/queryable/queries.rb +0 -60
  66. data/spec/brauser/definition_spec.rb +0 -39
  67. data/spec/brauser/query_spec.rb +0 -111
@@ -1,60 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
- # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
- #
6
-
7
- module Brauser
8
- # The interface of brauser queries.
9
- module Queryable
10
- # Methods to make queries.
11
- module Queries
12
- # Checks if the browser is a specific name and optionally of a specific version and platform.
13
- #
14
- # This version returns a boolean and it is equal to append a call to `#result` to the method `#is`.
15
- #
16
- # @see #v?
17
- # @see #on?
18
- #
19
- # @param names [Symbol|Array] A list of specific names to match. Also, this meta-names are supported: `:capable` and `:tablet`.
20
- # @param versions [Hash] An hash with specific version to match against. Need to be in any form that `#v` understands.
21
- # @param platforms [Symbol|Array] A list of specific platform to match. Valid values are all those possible for the platform attribute.
22
- # @return [Boolean] `true` if current browser matches, `false` otherwise.
23
- def is?(names = [], versions = {}, platforms = [])
24
- @result ? @target.is?(names, versions, platforms) : @result
25
- end
26
-
27
- # Checks if the browser is a specific version.
28
- #
29
- # This version returns a boolean and it is equal to append a call to `#result` to the method `#v`.
30
- #
31
- # @param versions [String|Hash] A string in the form `operator version && ...` (example: `>= 7 && < 4`) or an hash with specific version to match against,
32
- # in form `{:operator => version}`, where operator is one of `:lt, :lte, :eq, :gt, :gte`.
33
- # @return [Boolean] `true` if current browser matches, `false` otherwise.
34
- def version?(versions = {})
35
- @result ? @target.version?(versions) : @result
36
- end
37
- alias_method :v?, :version?
38
-
39
- # Check if the browser is on a specific platform.
40
- #
41
- # This version returns a boolean and it is equal to append a call to `#result` to the method `#on.
42
- #
43
- # @param platforms [Symbol|Array] A list of specific platform to match.
44
- # @return [Boolean] `true` if current browser matches, `false` otherwise.
45
- def on?(platforms = [])
46
- @result ? @target.on?(platforms) : @result
47
- end
48
-
49
- # Check if the browser accepts the specified languages.
50
- #
51
- # This version returns a boolean and it is equal to append a call to `#result` to the method `#accepts.
52
- #
53
- # @param langs [String|Array] A list of languages to match against.
54
- # @return [Boolean] `true` if current browser matches, `false` otherwise.
55
- def accepts?(langs = [])
56
- @result ? @target.accepts?(langs) : @result
57
- end
58
- end
59
- end
60
- end
@@ -1,39 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
- # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
- #
6
-
7
- require "spec_helper"
8
-
9
- describe Brauser::Definition do
10
- let(:definition) { ::Brauser::Definition.new(:tag, "Label", "ABC", /(abc)+/) }
11
-
12
- describe "#initialize" do
13
- it "should assign attributes" do
14
- other = ::Brauser::Definition.new("A", "B", "C", "D")
15
- expect(other.tag).to eq("A")
16
- expect(other.label).to eq("B")
17
- expect(other.primary).to eq("C")
18
- expect(other.secondary).to eq("D")
19
- end
20
- end
21
-
22
- describe "#match" do
23
- it "should apply the correct matcher and return the correct value" do
24
- expect(definition.match(:primary, nil, "ABC")).to eq("ABC")
25
- expect(definition.match(:primary, nil, "CDE")).to be_nil
26
- expect(definition.match(:secondary, nil, "abcabc")).to be_a(MatchData)
27
- expect(definition.match(:secondary, nil, "abx")).to be_nil
28
- end
29
-
30
- it "should support a block matcher" do
31
- definition.primary = Proc.new { |definition, a, b, c| a + b + c }
32
- expect(definition.match(:primary, nil, 1, 2, 3)).to eq(6)
33
- end
34
-
35
- it "should return nil when the matcher is not valid" do
36
- expect(definition.match(:tertiary)).to be_nil
37
- end
38
- end
39
- end
@@ -1,111 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
- # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
- #
6
-
7
- require "spec_helper"
8
-
9
- describe Brauser::Query do
10
- let(:browser){ ::Brauser::Browser.new("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", "it;q=0.7, en;q=0.3") }
11
- let(:query) { ::Brauser::Query.new(browser, true) }
12
-
13
- describe "#is" do
14
- it "should call the final corresponding method and then return self" do
15
- expect(query).to receive(:is?).and_call_original
16
- expect(query.is(:msie)).to be(query)
17
- end
18
- end
19
-
20
- describe "#is?" do
21
- it "should call the browser's corresponding method and update the result" do
22
- expect(browser).to receive(:is?).with(:msie, {}, []).and_call_original
23
- expect(query.is?(:msie)).to be_false
24
- end
25
- end
26
-
27
- describe "#version" do
28
- it "should call the final corresponding method and then return self" do
29
- expect(query).to receive(:version?).and_call_original
30
- expect(query.version(">= 9")).to be(query)
31
- end
32
- end
33
-
34
- describe "#version?" do
35
- it "should call the browser's corresponding method and update the result" do
36
- expect(browser).to receive(:version?).with(">= 9").and_call_original
37
- expect(browser).to receive(:version?).with(">= 10").and_call_original
38
- expect(query.version?(">= 9")).to be_true
39
- expect(query.v?(">= 10")).to be_true
40
- end
41
- end
42
-
43
- describe "#on" do
44
- it "should call the final corresponding method and then return self" do
45
- expect(query).to receive(:on?).and_call_original
46
- expect(query.on(:osx)).to be(query)
47
- end
48
- end
49
-
50
- describe "#on?" do
51
- it "should call the browser's corresponding method and update the result" do
52
- expect(browser).to receive(:on?).with(:osx).and_call_original
53
- expect(query.on?(:osx)).to be_true
54
- end
55
-
56
- end
57
-
58
- describe "#accepts" do
59
- it "should call the final corresponding method and then return self" do
60
- expect(query).to receive(:accepts?).and_call_original
61
- expect(query.accepts("it")).to be(query)
62
- end
63
- end
64
-
65
- describe "#accepts?" do
66
- it "should call the browser's corresponding method and update the result" do
67
- expect(browser).to receive(:accepts?).with("es").and_call_original
68
- expect(query.accepts?("es")).to be_false
69
- end
70
- end
71
-
72
- describe "concatenation" do
73
- before(:each) do
74
- browser.name = :chrome
75
- browser.version = "7.1.2"
76
- browser.platform = :windows
77
- end
78
-
79
- it "should call requested methods on the browser and return a query" do
80
- expect(browser).to receive(:is).and_call_original
81
- expect(browser).to receive(:version?).and_call_original
82
- expect(browser).to receive(:on?).and_call_original
83
-
84
- expect(browser.is(:chrome).version(">= 7").on(:osx)).to be_a(::Brauser::Query)
85
- end
86
-
87
- it "should call methods while result is true" do
88
- expect(browser).to receive(:is).and_call_original
89
- expect(browser).to receive(:version?).and_call_original
90
- expect(browser).not_to receive(:on?)
91
-
92
- expect(browser.is(:chrome).version(">= 9").on(:osx)).to be_a(::Brauser::Query)
93
- end
94
-
95
- it "when the last method is the question mark, it should return the evaluation to boolean" do
96
- expect(browser).to receive(:is).and_call_original
97
- expect(browser).to receive(:version?).and_call_original
98
- expect(browser).to receive(:on?).and_call_original
99
-
100
- expect(browser.is(:chrome).version(">= 7").on?(:osx)).to be_false
101
- end
102
-
103
- it "should return the result when ending the query with #result" do
104
- expect(browser).to receive(:is).and_call_original
105
- expect(browser).to receive(:version?).and_call_original
106
- expect(browser).not_to receive(:on?)
107
-
108
- expect(browser.is(:chrome).v(">= 9").on(:osx).result).to be_false
109
- end
110
- end
111
- end