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
@@ -0,0 +1,129 @@
1
+ #
2
+ # This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
3
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
+ #
5
+
6
+ require "spec_helper"
7
+
8
+ describe Brauser do
9
+ describe "should recognize common browsers" do
10
+ def recognize(agent = nil)
11
+ browser = ::Brauser::Browser.new(agent)
12
+ [browser.name, browser.version, browser.platform]
13
+ end
14
+
15
+ it "should return false for unknown names" do
16
+ expect(recognize("UNKNOWN")).to eq([:unknown, "0.0", :unknown])
17
+ end
18
+
19
+ it "by detecting the correct name, version and platform" do
20
+ # Google Chrome
21
+ expect(recognize("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")).to eq([:chrome, "21.0.1180.82", :osx])
22
+ expect(recognize("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.9 Safari/536.5")).to eq([:chrome, "19.0.1084.9", :linux])
23
+ expect(recognize("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.215 Safari/535.1")).to eq([:chrome, "13.0.782.215", :windows])
24
+
25
+ # Mozilla Firefox
26
+ expect(recognize("Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2")).to eq([:firefox, "15.0a2", :windows])
27
+ expect(recognize("Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:14.0) Gecko/20100101 Firefox/14.0.1")).to eq([:firefox, "14.0.1", :linux])
28
+ expect(recognize("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0b8) Gecko/20100101 Firefox/4.0b8")).to eq([:firefox, "4.0b8", :osx])
29
+
30
+ # Apple Safari
31
+ expect(recognize("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10")).to eq([:safari, "5.1.3", :osx])
32
+ expect(recognize("Mozilla/5.0 (Windows; U; Windows NT 5.0; en-en) AppleWebKit/533.16 (KHTML, like Gecko) Version/4.1 Safari/533.16")).to eq([:safari, "4.1", :windows])
33
+
34
+ # Opera Mobile
35
+ expect(recognize("Opera/9.80 (Android 2.3.3; Linux; Opera Mobi/ADR-1111101157; U; es-ES) Presto/2.9.201 Version/11.50")).to eq([:opera_mobile, "11.50", :android])
36
+ expect(recognize("Mozilla/5.0 (S60; SymbOS; Opera Mobi/SYB-1103211396; U; es-LA; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 Opera 11.00")).to eq([:opera_mobile, "11.00", :symbian])
37
+
38
+ # Opera
39
+ expect(recognize("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36 OPR/16.0.1196.73")).to eq([:opera, "16.0.1196.73", :windows])
40
+ expect(recognize("Opera/9.80 (Windows NT 6.1; U; es-ES) Presto/2.9.181 Version/12.00")).to eq([:opera, "12.00", :windows])
41
+ expect(recognize("Mozilla/5.0 (Windows NT 5.1; U; en; rv:1.8.1) Gecko/20061208 Firefox/5.0 Opera 11.11")).to eq([:opera, "11.11", :windows])
42
+ expect(recognize("Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52")).to eq([:opera, "11.52", :osx])
43
+ expect(recognize("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera 11.51")).to eq([:opera, "11.51", :windows])
44
+
45
+ # Microsoft Internet Explorer in compatibility view
46
+ expect(recognize("Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/6.0)")).to eq([:msie_compatibility, "10.0", :windows])
47
+ expect(recognize("Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET CLR 1.1.4322; .NET4.0C; Tablet PC 2.0)")).to eq([:msie_compatibility, "9.0", :windows])
48
+ expect(recognize("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Zune 3.0)")).to eq([:msie_compatibility, "8.0", :windows])
49
+
50
+ # Microsoft Internet Explorer
51
+ expect(recognize("Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko")).to eq([:msie, "11.0", :windows])
52
+ expect(recognize("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64;0)")).to eq([:msie, "10.0", :windows])
53
+ expect(recognize("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET CLR 1.1.4322; .NET4.0C; Tablet PC 2.0)")).to eq([:msie, "9.0", :windows])
54
+ expect(recognize("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Zune 3.0)")).to eq([:msie, "8.0", :windows])
55
+ expect(recognize("Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.0; fr-FR)")).to eq([:msie, "7.0", :windows])
56
+ expect(recognize("Mozilla/4.01 (compatible; MSIE 6.0; Windows NT 5.1)")).to eq([:msie, "6.0", :windows])
57
+
58
+ # Netscape
59
+ expect(recognize("Mozilla/5.0 (Windows; U; Win 9x 4.90; SG; rv:1.9.2.4) Gecko/20101104 Netscape/9.1.0285")).to eq([:netscape, "9.1.0285", :windows])
60
+ expect(recognize("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.8pre) Gecko/20071001 Firefox/2.0.0.7 Navigator/9.0RC1")).to eq([:netscape, "9.0RC1", :osx])
61
+
62
+ # Chrome IOS
63
+ expect(recognize("Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en-gb) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3")).to eq([:chrome_ios, "19.0.1084.60", :ios])
64
+ expect(recognize("Mozilla/5.0 (iPad; U; CPU iPhone OS 5_1_1 like Mac OS X; en-gb) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/21.0.1180.82 Safari/536.5")).to eq([:chrome_ios, "21.0.1180.82", :ios])
65
+
66
+ # Apple iPhone
67
+ expect(recognize("Mozilla/5.0 (iPhone; U; fr; CPU iPhone OS 4_2_1 like Mac OS X; fr) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5")).to eq([:iphone, "5.0.2", :ios])
68
+ expect(recognize("Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B5097d Safari/6531.22.7")).to eq([:iphone, "4.0.5", :ios])
69
+
70
+ # Apple iPad
71
+ expect(recognize("Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko ) Version/5.1 Mobile/9B176 Safari/7534.48.3")).to eq([:ipad, "5.1", :ios])
72
+ expect(recognize("Mozilla/5.0 (iPad; U; CPU OS 4_3 like Mac OS X; nl-nl) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F190 Safari/6533.18.5")).to eq([:ipad, "5.0.2", :ios])
73
+
74
+ # Apple iPod Touch
75
+ expect(recognize("Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; ja-jp) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5")).to eq([:ipod, "5.0.2", :ios])
76
+ expect(recognize("Mozilla/5.0 (iPod; U; CPU iPhone OS 3_0 like Mac OS X; ja-jp) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16")).to eq([:ipod, "4.0", :ios])
77
+
78
+ # Android
79
+ expect(recognize("Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30")).to eq([:android, "4.0.3", :android])
80
+ expect(recognize("Mozilla/5.0 (Linux; U; Android 2.3.3; en-us; HTC_DesireS_S510e Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1")).to eq([:android, "2.3.3", :android])
81
+
82
+ # RIM Blackberry
83
+ expect(recognize("Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+")).to eq([:blackberry, "7.1.0.346", :blackberry])
84
+ expect(recognize("Mozilla/5.0 (BlackBerry; U; BlackBerry 9700; pt) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.0.0.546 Mobile Safari/534.8+")).to eq([:blackberry, "6.0.0.546", :blackberry])
85
+
86
+ # Windows Phone
87
+ expect(recognize("Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG; SGH-i917)")).to eq([:windows_phone, "9.0", :windows_phone])
88
+ expect(recognize("Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; DELL; Venue Pro")).to eq([:windows_phone, "7.0", :windows_phone])
89
+
90
+ # Symbian
91
+ expect(recognize("Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaC6-00/20.0.042; Profile/MIDP-2.1 Configuration/CLDC-1.1; zh-hk) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.2.6.9 3gpp-gba")).to eq([:mobile, "7.2.6.9", :symbian])
92
+
93
+ # Amazon Kindle
94
+ expect(recognize("Mozilla/4.0 (compatible; Linux 2.6.22) NetFront/3.4 Kindle/2.0 (screen 600x800)")).to eq([:kindle, "2.0", :kindle])
95
+ expect(recognize("Mozilla/4.0 (compatible; Linux 2.6.10) NetFront/3.3 Kindle/1.0 (screen 600x800)")).to eq([:kindle, "1.0", :kindle])
96
+
97
+ # Sony Playstation Portable
98
+ expect(recognize("PSP (PlayStation Portable); 2.00")).to eq([:psp, "2.00", :psp])
99
+ expect(recognize("Mozilla/4.0 (PSP (PlayStation Portable); 2.00)")).to eq([:psp, "2.00", :psp])
100
+
101
+ # Sony Playstation 3
102
+ expect(recognize("Mozilla/5.0 (PLAYSTATION 3; 3.55)")).to eq([:ps3, "3.55", :ps3])
103
+ expect(recognize("Mozilla/5.0 (PLAYSTATION 3; 1.70)")).to eq([:ps3, "1.70", :ps3])
104
+
105
+ # Nintendo Wii
106
+ expect(recognize("Opera/9.30 (Nintendo Wii; U; ; 2071; Wii Shop Channel/1.0; en)")).to eq([:opera, "2071", :wii])
107
+ expect(recognize("Opera/9.30 (Nintendo Wii; U; ; 2047-7;pt-br)")).to eq([:opera, "2047", :wii])
108
+
109
+ # Mobile browsers
110
+ expect(recognize("Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; Sprint;PPC-i830; PPC; 240x320)")).to eq([:mobile, "4.0", :windows])
111
+
112
+ # Generic Webkit
113
+ expect(recognize("Midori/0.2.0 (X11; Linux i686; U; de-de) WebKit/531.2+")).to eq([:webkit, "531.2", :linux])
114
+ expect(recognize("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; de-de) AppleWebKit/531.21.8 (KHTML, like Gecko) NetNewsWire/3.2.3")).to eq([:webkit, "531.21.8", :osx])
115
+
116
+ # Generic Gecko
117
+ expect(recognize("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9a3.pre) Gecko/20070330")).to eq([:gecko, "1.9a3.pre", :linux])
118
+ expect(recognize("Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9.2a1pre) Gecko")).to eq([:gecko, "1.9.2a1pre", :windows])
119
+
120
+ # QuickTime
121
+ expect(recognize("QuickTime/7.6.2 (qtver=7.6.2;os=Windows NT 5.1Service Pack 3)")).to eq([:quicktime, "7.6.2", :windows])
122
+ expect(recognize("QuickTime/7.6 (qtver=7.6;cpu=IA32;os=Mac 10,5,7)")).to eq([:quicktime, "7.6", :osx])
123
+
124
+ # CoreMedia
125
+ expect(recognize("Apple iPhone v1.1.1 CoreMedia v1.0.0.3A110a")).to eq([:coremedia, "1.0.0.3A110a", :ios])
126
+ expect(recognize("Apple Mac OS X v10.6.6 CoreMedia v1.0.0.10J567")).to eq([:coremedia, "1.0.0.10J567", :osx])
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,48 @@
1
+ #
2
+ # This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
3
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
+ #
5
+
6
+ require "spec_helper"
7
+
8
+ describe ::Brauser::Definitions do
9
+ describe ".register" do
10
+ it "should register a new definition" do
11
+ dummy = ::OpenStruct.new(id: :definition)
12
+ expect(::Brauser::Definitions::Browser).to receive(:new).with("A", "B", "C", a: 1, b: 2, c:3).and_return(dummy)
13
+ ::Brauser::Definitions.register(:browser, "A", "B", "C", a: 1, b: 2, c:3)
14
+ expect(::Brauser::Definitions.browsers[:definition]).to be(dummy)
15
+ ::Brauser::Definitions.browsers.delete(:definition)
16
+ end
17
+
18
+ it "should raise an error for invalid types" do
19
+ expect { ::Brauser::Definitions.register(:none, "A", "B", "C", a: 1, b: 2, c:3) }.to raise_error(::ArgumentError)
20
+ end
21
+ end
22
+
23
+ describe ".browsers" do
24
+ it "should return the list of browsers" do
25
+ expect(::Brauser::Definitions.browsers).to include(:chrome)
26
+ end
27
+ end
28
+
29
+ describe ".platforms" do
30
+ it "should return the list of platforms" do
31
+ expect(::Brauser::Definitions.platforms).to include(:osx)
32
+ end
33
+ end
34
+
35
+ describe ".languages" do
36
+ it "should return the list of languages" do
37
+ expect(::Brauser::Definitions.languages).to include(:it)
38
+ end
39
+ end
40
+ end
41
+
42
+ describe ::Brauser::Definitions::Base do
43
+ describe "#match" do
44
+ it "should raise an error" do
45
+ expect { ::Brauser::Definitions::Base.new.match(:unused) }.to raise_error(::RuntimeError)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,47 @@
1
+ #
2
+ # This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
3
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
+ #
5
+
6
+ require "spec_helper"
7
+
8
+ describe Brauser::Definitions::Browser do
9
+ subject { ::Brauser::Definitions.browsers[:opera] }
10
+
11
+ describe "#initialize" do
12
+ it "should save the id, the name and the pattern" do
13
+ subject = ::Brauser::Definitions::Browser.new(:browser, "BROWSER", /engine/, /version/)
14
+ expect(subject.id).to eq(:browser)
15
+ expect(subject.name).to eq("BROWSER")
16
+ expect(subject.engine_matcher).to eq(/engine/)
17
+ expect(subject.version_matcher).to eq(/version/)
18
+ end
19
+ end
20
+
21
+ describe "#match" do
22
+ it "should run against the engine pattern and the version pattern" do
23
+ result = subject.match("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera 11.51")
24
+ expect(result.first).to eq(:opera)
25
+ end
26
+
27
+ it "should also fetch the version" do
28
+ result = subject.match("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera 11.51")
29
+ expect(result[1]).to eq(::Versionomy.parse("11.51"))
30
+
31
+ result = subject.match("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera")
32
+ expect(result[1]).to eq(::Versionomy.parse("0.0"))
33
+
34
+ subject.instance_variable_set(:@version_matcher, ->(_) { "123" })
35
+ result = subject.match("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera")
36
+ expect(result[1]).to eq("123")
37
+ end
38
+
39
+ it "should also fetch the platform" do
40
+ result = subject.match("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera 11.51")
41
+ expect(result[2]).to eq(:windows)
42
+
43
+ result = subject.match("Mozilla/5.0 (compatible; MSIE 9.0; FOO 6.1; de) Opera 11.51")
44
+ expect(result[2]).to eq(nil)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,18 @@
1
+ #
2
+ # This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
3
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
+ #
5
+
6
+ require "spec_helper"
7
+
8
+ describe Brauser::Definitions::Language do
9
+ subject { ::Brauser::Definitions::Language.new("it_CH", "Italian/ Switzerland") }
10
+
11
+ describe "#initialize" do
12
+ it "should save the code as id and code, and also save the name" do
13
+ expect(subject.id).to eq(:"it-ch")
14
+ expect(subject.code).to eq("it-ch")
15
+ expect(subject.name).to eq("Italian/ Switzerland")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,36 @@
1
+ #
2
+ # This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
3
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
+ #
5
+
6
+ require "spec_helper"
7
+
8
+ describe Brauser::Definitions::Platform do
9
+ subject { ::Brauser::Definitions::Platform.new(:platform, "PLATFORM", /platform/) }
10
+
11
+ describe "#initialize" do
12
+ it "should save the id, the name and the pattern" do
13
+ expect(subject.id).to eq(:platform)
14
+ expect(subject.name).to eq("PLATFORM")
15
+ expect(subject.matcher).to eq(/platform/)
16
+ end
17
+ end
18
+
19
+ describe "#match" do
20
+ it "should run against the pattern and return its result" do
21
+ result = subject.match("This is the platform", "ENGINE")
22
+ expect(result).to be_a(::MatchData)
23
+
24
+ result = subject.match("This is invalid", "ENGINE")
25
+ expect(result).to be_nil
26
+ end
27
+
28
+ it "should run against the given block" do
29
+ result = ::Brauser::Definitions::Platform.new(:platform, "PLATFORM", ->(header, engine) { "#{header}-#{engine}" }).match("HEADER", "ENGINE")
30
+ expect(result).to eq("HEADER-ENGINE")
31
+
32
+ result = (::Brauser::Definitions::Platform.new(:platform, "PLATFORM"){ |header| header.reverse }).match("HEADER", "ENGINE")
33
+ expect(result).to eq("REDAEH")
34
+ end
35
+ end
36
+ end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  #
3
2
  # This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
3
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
@@ -8,16 +7,16 @@ require "spec_helper"
8
7
 
9
8
  describe Brauser::Hooks::RubyOnRails do
10
9
  before(:each) do
11
- stub_const("ActionController::Base", Class.new)
12
- allow(ActionController::Base).to receive(:helper_method)
13
- allow_any_instance_of(ActionController::Base).to receive(:request).and_return(OpenStruct.new(headers: {}))
14
- ActionController::Base.send(:include, Brauser::Hooks::RubyOnRails)
10
+ stub_const("ActionController::Base", ::Class.new)
11
+ allow(::ActionController::Base).to receive(:helper_method)
12
+ allow_any_instance_of(::ActionController::Base).to receive(:request).and_return(::OpenStruct.new(headers: {}))
13
+ ::ActionController::Base.send(:include, ::Brauser::Hooks::RubyOnRails)
15
14
  end
16
15
 
17
16
  let(:controller){::ActionController::Base.new}
18
17
 
19
18
  it "should append to ActionController::Base" do
20
- expect(controller.respond_to?(:browser)).to be_true
19
+ expect(controller.respond_to?(:browser)).to be_truthy
21
20
  end
22
21
 
23
22
  it "should memoize browser" do
@@ -0,0 +1,31 @@
1
+ #
2
+ # This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
3
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
+ #
5
+
6
+ require "spec_helper"
7
+
8
+ describe Brauser::Parser do
9
+ subject { ::Brauser::Parser.new }
10
+
11
+ describe ".disambiguate" do
12
+ it "should check if a string matches a pattern and NOT another one" do
13
+ expect(::Brauser::Parser.disambiguate("test", /es/, /az/)).to be_truthy
14
+ expect(::Brauser::Parser.disambiguate("test", /es/, /st/)).to be_falsey
15
+ end
16
+ end
17
+
18
+ describe "#parse_agent" do
19
+ it "should parse Agent header and return a id, version and platform" do
20
+ expect(subject.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")).to eq([:chrome, Versionomy.parse("21.0.1180.82"), :osx])
21
+ expect(subject.parse_agent("Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2")).to eq([:firefox, Versionomy.parse("15.0a2"), :windows])
22
+ expect(subject.parse_agent("UNKNOWN")).to be_nil
23
+ end
24
+ end
25
+
26
+ describe "#parse_accept_language" do
27
+ it "should parse Accept-Language and return an hash of languages with their priorities" do
28
+ expect(subject.parse_accept_language("IT;q=0.7, EN;q=0.3")).to eq({it: 0.7, en: 0.3})
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,34 @@
1
+ #
2
+ # This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
3
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
+ #
5
+
6
+ require "spec_helper"
7
+
8
+ describe Brauser::Value do
9
+ subject { ::Brauser::Value.new(1) }
10
+
11
+ describe "#initialize" do
12
+ it "should save the value" do
13
+ expect(subject.value).to eq(1)
14
+ end
15
+ end
16
+
17
+ describe "#==" do
18
+ it "should compare against a value or an array of value" do
19
+ expect(subject).to eq(1)
20
+ expect(subject).not_to eq(2)
21
+ expect(subject).to eq([1, 2])
22
+ end
23
+ end
24
+
25
+ describe "it should delegate the rest to the value" do
26
+ it "- #to_s" do
27
+ expect(subject.to_s).to eq("1")
28
+ end
29
+
30
+ it "- #method_missing" do
31
+ expect(subject.odd?).to be_truthy
32
+ end
33
+ end
34
+ end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  #
3
2
  # This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
3
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  #
3
2
  # This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
3
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
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.3.2
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shogun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-22 00:00:00.000000000 Z
11
+ date: 2014-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lazier
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.5.5
19
+ version: '4.0'
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.5.5
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: versionomy
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.4'
27
41
  description: A framework agnostic browser detection and querying helper.
28
42
  email:
29
43
  - shogun@cowtech.it
@@ -41,6 +55,9 @@ files:
41
55
  - README.md
42
56
  - Rakefile
43
57
  - brauser.gemspec
58
+ - default_definitions/browsers.rb
59
+ - default_definitions/languages.rb
60
+ - default_definitions/platforms.rb
44
61
  - doc/Brauser.html
45
62
  - doc/Brauser/Browseable.html
46
63
  - doc/Brauser/Browseable/Attributes.html
@@ -54,12 +71,19 @@ files:
54
71
  - doc/Brauser/Browseable/Register/ClassMethods.html
55
72
  - doc/Brauser/Browser.html
56
73
  - doc/Brauser/Definition.html
74
+ - doc/Brauser/Definitions.html
75
+ - doc/Brauser/Definitions/Base.html
76
+ - doc/Brauser/Definitions/Browser.html
77
+ - doc/Brauser/Definitions/Language.html
78
+ - doc/Brauser/Definitions/Platform.html
57
79
  - doc/Brauser/Hooks.html
58
80
  - doc/Brauser/Hooks/RubyOnRails.html
81
+ - doc/Brauser/Parser.html
59
82
  - doc/Brauser/Query.html
60
83
  - doc/Brauser/Queryable.html
61
84
  - doc/Brauser/Queryable/Chainers.html
62
85
  - doc/Brauser/Queryable/Queries.html
86
+ - doc/Brauser/Value.html
63
87
  - doc/Brauser/Version.html
64
88
  - doc/_index.html
65
89
  - doc/class_list.html
@@ -76,30 +100,28 @@ files:
76
100
  - doc/method_list.html
77
101
  - doc/top-level-namespace.html
78
102
  - lib/brauser.rb
79
- - lib/brauser/browseable/attributes.rb
80
- - lib/brauser/browseable/general.rb
81
- - lib/brauser/browseable/parsing.rb
82
- - lib/brauser/browseable/partial_querying.rb
83
- - lib/brauser/browseable/querying.rb
84
- - lib/brauser/browseable/register.rb
85
103
  - lib/brauser/browser.rb
86
- - lib/brauser/definition.rb
87
- - lib/brauser/definitions/browsers.rb
88
- - lib/brauser/definitions/languages.rb
89
- - lib/brauser/definitions/platforms.rb
104
+ - lib/brauser/definitions/base.rb
105
+ - lib/brauser/definitions/browser.rb
106
+ - lib/brauser/definitions/language.rb
107
+ - lib/brauser/definitions/platform.rb
90
108
  - lib/brauser/hooks.rb
91
- - lib/brauser/query.rb
92
- - lib/brauser/queryable/chainers.rb
93
- - lib/brauser/queryable/queries.rb
109
+ - lib/brauser/parser.rb
110
+ - lib/brauser/value.rb
94
111
  - lib/brauser/version.rb
95
112
  - spec/brauser/browser_spec.rb
96
- - spec/brauser/definition_spec.rb
113
+ - spec/brauser/default_definitions_spec.rb
114
+ - spec/brauser/definitions/base_spec.rb
115
+ - spec/brauser/definitions/browser_spec.rb
116
+ - spec/brauser/definitions/language_spec.rb
117
+ - spec/brauser/definitions/platform_spec.rb
97
118
  - spec/brauser/hooks_spec.rb
98
- - spec/brauser/query_spec.rb
119
+ - spec/brauser/parser_spec.rb
120
+ - spec/brauser/value_spec.rb
99
121
  - spec/coverage_helper.rb
100
122
  - spec/spec_helper.rb
101
123
  - spec/supported.yml
102
- homepage: http://sw.cow.tc/brauser
124
+ homepage: http://sw.cowtech.it/brauser
103
125
  licenses:
104
126
  - MIT
105
127
  metadata: {}
@@ -111,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
133
  requirements:
112
134
  - - ">="
113
135
  - !ruby/object:Gem::Version
114
- version: 1.9.3
136
+ version: 2.1.0
115
137
  required_rubygems_version: !ruby/object:Gem::Requirement
116
138
  requirements:
117
139
  - - ">="
@@ -125,9 +147,14 @@ specification_version: 4
125
147
  summary: A framework agnostic browser detection and querying helper.
126
148
  test_files:
127
149
  - spec/brauser/browser_spec.rb
128
- - spec/brauser/definition_spec.rb
150
+ - spec/brauser/default_definitions_spec.rb
151
+ - spec/brauser/definitions/base_spec.rb
152
+ - spec/brauser/definitions/browser_spec.rb
153
+ - spec/brauser/definitions/language_spec.rb
154
+ - spec/brauser/definitions/platform_spec.rb
129
155
  - spec/brauser/hooks_spec.rb
130
- - spec/brauser/query_spec.rb
156
+ - spec/brauser/parser_spec.rb
157
+ - spec/brauser/value_spec.rb
131
158
  - spec/coverage_helper.rb
132
159
  - spec/spec_helper.rb
133
160
  - spec/supported.yml