can_i_use 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitmodules +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +86 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +9 -0
- data/can_i_use.gemspec +29 -0
- data/lib/can_i_use.rb +24 -0
- data/lib/can_i_use/browser.rb +49 -0
- data/lib/can_i_use/browser_version.rb +71 -0
- data/lib/can_i_use/feature.rb +30 -0
- data/lib/can_i_use/user_agent.rb +30 -0
- data/lib/can_i_use/version.rb +3 -0
- data/test/can_i_use/browser_test.rb +115 -0
- data/test/can_i_use/browser_version_test.rb +47 -0
- data/test/can_i_use/feature_test.rb +25 -0
- data/test/can_i_use/user_agent_test.rb +24 -0
- data/test/can_i_use_test.rb +11 -0
- data/test/test_helper.rb +11 -0
- metadata +157 -0
data/.gitmodules
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
can_i_use (0.0.1)
|
5
|
+
user_agent_parser
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
celluloid (0.16.0)
|
11
|
+
timers (~> 4.0.0)
|
12
|
+
coderay (1.1.0)
|
13
|
+
coveralls (0.7.11)
|
14
|
+
multi_json (~> 1.10)
|
15
|
+
rest-client (>= 1.6.8, < 2)
|
16
|
+
simplecov (~> 0.9.1)
|
17
|
+
term-ansicolor (~> 1.3)
|
18
|
+
thor (~> 0.19.1)
|
19
|
+
docile (1.1.5)
|
20
|
+
ffi (1.9.6)
|
21
|
+
formatador (0.2.5)
|
22
|
+
guard (2.12.4)
|
23
|
+
formatador (>= 0.2.4)
|
24
|
+
listen (~> 2.7)
|
25
|
+
lumberjack (~> 1.0)
|
26
|
+
nenv (~> 0.1)
|
27
|
+
notiffany (~> 0.0)
|
28
|
+
pry (>= 0.9.12)
|
29
|
+
shellany (~> 0.0)
|
30
|
+
thor (>= 0.18.1)
|
31
|
+
guard-compat (1.2.1)
|
32
|
+
guard-minitest (2.4.4)
|
33
|
+
guard-compat (~> 1.2)
|
34
|
+
minitest (>= 3.0)
|
35
|
+
hitimes (1.2.2)
|
36
|
+
listen (2.8.5)
|
37
|
+
celluloid (>= 0.15.2)
|
38
|
+
rb-fsevent (>= 0.9.3)
|
39
|
+
rb-inotify (>= 0.9)
|
40
|
+
lumberjack (1.0.9)
|
41
|
+
method_source (0.8.2)
|
42
|
+
mime-types (2.4.3)
|
43
|
+
minitest (5.5.1)
|
44
|
+
multi_json (1.11.0)
|
45
|
+
nenv (0.2.0)
|
46
|
+
netrc (0.10.3)
|
47
|
+
notiffany (0.0.6)
|
48
|
+
nenv (~> 0.1)
|
49
|
+
shellany (~> 0.0)
|
50
|
+
pry (0.10.1)
|
51
|
+
coderay (~> 1.1.0)
|
52
|
+
method_source (~> 0.8.1)
|
53
|
+
slop (~> 3.4)
|
54
|
+
rake (10.4.2)
|
55
|
+
rb-fsevent (0.9.4)
|
56
|
+
rb-inotify (0.9.5)
|
57
|
+
ffi (>= 0.5.0)
|
58
|
+
rest-client (1.7.3)
|
59
|
+
mime-types (>= 1.16, < 3.0)
|
60
|
+
netrc (~> 0.7)
|
61
|
+
shellany (0.0.1)
|
62
|
+
simplecov (0.9.2)
|
63
|
+
docile (~> 1.1.0)
|
64
|
+
multi_json (~> 1.0)
|
65
|
+
simplecov-html (~> 0.9.0)
|
66
|
+
simplecov-html (0.9.0)
|
67
|
+
slop (3.6.0)
|
68
|
+
term-ansicolor (1.3.0)
|
69
|
+
tins (~> 1.0)
|
70
|
+
thor (0.19.1)
|
71
|
+
timers (4.0.1)
|
72
|
+
hitimes
|
73
|
+
tins (1.3.5)
|
74
|
+
user_agent_parser (2.2.0)
|
75
|
+
|
76
|
+
PLATFORMS
|
77
|
+
ruby
|
78
|
+
|
79
|
+
DEPENDENCIES
|
80
|
+
bundler (~> 1.6)
|
81
|
+
can_i_use!
|
82
|
+
coveralls
|
83
|
+
guard
|
84
|
+
guard-minitest
|
85
|
+
minitest
|
86
|
+
rake
|
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Tomas Celizna
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# CanIUse
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/tomasc/can_i_use.svg)](https://travis-ci.org/tomasc/can_i_use) [![Gem Version](https://badge.fury.io/rb/can_i_use.svg)](http://badge.fury.io/rb/can_i_use) [![Coverage Status](https://img.shields.io/coveralls/tomasc/can_i_use.svg)](https://coveralls.io/r/tomasc/can_i_use)
|
4
|
+
|
5
|
+
Very light Ruby wrapper on [caniuse](http://www.caniuse.com) data.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'can_i_use'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```
|
24
|
+
$ gem install can_i_use
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Test user agent for support of a feature. Optionally specify minimal required type of support (`:almost`, `:polyfill`, `:prefix` or `:disabled`).
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
CanIUse::UserAgent.new(user_agent_string).supports?('canvas') # => true
|
33
|
+
CanIUse::UserAgent.new(user_agent_string).supports?('canvas', :polyfill) # => true
|
34
|
+
```
|
35
|
+
|
36
|
+
The [caniuse](http://www.caniuse.com) data are included as a submodule from the [official GitHub repo](https://github.com/fyrd/caniuse). This means this gem needs to be regularly updated in order to reflect the latest features and their implementation in browsers. Pull requests are welcome.
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
CanIUse.updated_at # => 2015-03-01 05:59:31 UTC
|
40
|
+
```
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it ( https://github.com/tomasc/can_i_use/fork )
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/can_i_use.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'can_i_use/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "can_i_use"
|
8
|
+
spec.version = CanIUse::VERSION
|
9
|
+
spec.authors = ["Tomas Celizna"]
|
10
|
+
spec.email = ["tomas.celizna@gmail.com"]
|
11
|
+
spec.summary = %q{Very light Ruby wrapper on caniuse data.}
|
12
|
+
spec.description = %q{Very light Ruby wrapper on caniuse data.}
|
13
|
+
spec.homepage = "https://github.com/tomasc/can_i_use"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'user_agent_parser'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "coveralls"
|
25
|
+
spec.add_development_dependency "guard"
|
26
|
+
spec.add_development_dependency "guard-minitest"
|
27
|
+
spec.add_development_dependency "minitest"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
end
|
data/lib/can_i_use.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "can_i_use/version"
|
2
|
+
|
3
|
+
require 'can_i_use/browser'
|
4
|
+
require 'can_i_use/browser_version'
|
5
|
+
require 'can_i_use/feature'
|
6
|
+
require 'can_i_use/user_agent'
|
7
|
+
|
8
|
+
class CanIUse
|
9
|
+
|
10
|
+
CANIUSE_DATA = JSON.parse(
|
11
|
+
File.read(
|
12
|
+
File.join(
|
13
|
+
[ File.dirname(__FILE__), '..', 'vendor/caniuse/data.json' ]
|
14
|
+
)
|
15
|
+
)
|
16
|
+
)
|
17
|
+
|
18
|
+
# =====================================================================
|
19
|
+
|
20
|
+
def self.updated_at
|
21
|
+
Time.at(CANIUSE_DATA['updated'].to_i).utc
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative 'version'
|
2
|
+
|
3
|
+
class CanIUse
|
4
|
+
class Browser
|
5
|
+
|
6
|
+
attr_accessor :name
|
7
|
+
attr_accessor :versions_hash
|
8
|
+
|
9
|
+
# =====================================================================
|
10
|
+
|
11
|
+
def initialize name, versions_hash
|
12
|
+
@name = name
|
13
|
+
@versions_hash = versions_hash
|
14
|
+
end
|
15
|
+
|
16
|
+
# ---------------------------------------------------------------------
|
17
|
+
|
18
|
+
def versions
|
19
|
+
@versions_hash.select{ |k, v| k =~ /[\d\.]/ }.inject([]) do |res, h|
|
20
|
+
res << BrowserVersion.new(*h)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def version version_number
|
25
|
+
versions.detect{ |v| v.to_s == version_number }
|
26
|
+
end
|
27
|
+
|
28
|
+
def supported_from_version support_type=:yes
|
29
|
+
versions.detect{ |v| v.support_type == support_type }
|
30
|
+
end
|
31
|
+
|
32
|
+
# ---------------------------------------------------------------------
|
33
|
+
|
34
|
+
def is? str
|
35
|
+
!!case name
|
36
|
+
when 'ios_saf' then str =~ /mobile/i && str =~ /safari/i
|
37
|
+
when 'op_mini' then str =~ /opera/i && str =~ /mini/i
|
38
|
+
when 'bb' then str =~ /BlackBerry/i
|
39
|
+
when 'op_mob' then str =~ /Opera/i && str =~ /Mobi/i
|
40
|
+
when 'and_chr' then str =~ /Android/i && str =~ /Chrome/i
|
41
|
+
when 'and_ff' then str =~ /Android/i && str =~ /Firefox/i
|
42
|
+
when 'ie_mob' then str =~ /IE/i && str =~ /Mobile/i
|
43
|
+
when 'and_uc' then str =~ /(Android)?UC\s?(Browser)?/i
|
44
|
+
else str =~ /#{name}/i
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class CanIUse
|
2
|
+
class BrowserVersion
|
3
|
+
|
4
|
+
attr_accessor :version_string
|
5
|
+
attr_accessor :support_string
|
6
|
+
|
7
|
+
# =====================================================================
|
8
|
+
|
9
|
+
def initialize version_string, support_string
|
10
|
+
@version_string = version_string
|
11
|
+
@support_string = support_string
|
12
|
+
end
|
13
|
+
|
14
|
+
# ---------------------------------------------------------------------
|
15
|
+
|
16
|
+
def <=> other
|
17
|
+
Gem::Version.new(to_s.dup) <=> Gem::Version.new(other.to_s.dup)
|
18
|
+
end
|
19
|
+
|
20
|
+
def > other
|
21
|
+
Gem::Version.new(to_s.dup) > Gem::Version.new(other.to_s.dup)
|
22
|
+
end
|
23
|
+
|
24
|
+
def >= other
|
25
|
+
Gem::Version.new(to_s.dup) >= Gem::Version.new(other.to_s.dup)
|
26
|
+
end
|
27
|
+
|
28
|
+
def < other
|
29
|
+
Gem::Version.new(to_s.dup) < Gem::Version.new(other.to_s.dup)
|
30
|
+
end
|
31
|
+
|
32
|
+
def <= other
|
33
|
+
Gem::Version.new(to_s.dup) <= Gem::Version.new(other.to_s.dup)
|
34
|
+
end
|
35
|
+
|
36
|
+
def == other
|
37
|
+
Gem::Version.new(to_s.dup) == Gem::Version.new(other.to_s.dup)
|
38
|
+
end
|
39
|
+
|
40
|
+
# ---------------------------------------------------------------------
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
@version_string
|
44
|
+
end
|
45
|
+
|
46
|
+
# ---------------------------------------------------------------------
|
47
|
+
|
48
|
+
# y - (Y)es, supported by default
|
49
|
+
# a - (A)lmost supported (aka Partial support)
|
50
|
+
# n - (N)o support, or disabled by default
|
51
|
+
# p - No support, but has (P)olyfill
|
52
|
+
# u - Support (u)nknown
|
53
|
+
# x - Requires prefi(x) to work
|
54
|
+
# d - (D)isabled by default (need to enable flag or something)
|
55
|
+
# #n - Where n is a number, starting with 1, corresponds to the notes_by_num note. For example: "42":"y #1" means version 42 is supported by default and see note 1.
|
56
|
+
|
57
|
+
# TODO: append note
|
58
|
+
def support_type
|
59
|
+
case
|
60
|
+
when support_string =~ /y/i then :yes
|
61
|
+
when support_string =~ /a/i then :almost
|
62
|
+
when support_string =~ /n/i then :no
|
63
|
+
when support_string =~ /p/i then :polyfill
|
64
|
+
when support_string =~ /u/i then :unknown
|
65
|
+
when support_string =~ /x/i then :prefix
|
66
|
+
when support_string =~ /d/i then :disabled
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
require_relative 'browser'
|
4
|
+
|
5
|
+
class CanIUse
|
6
|
+
class Feature
|
7
|
+
|
8
|
+
def initialize name
|
9
|
+
@name = name
|
10
|
+
end
|
11
|
+
|
12
|
+
# ---------------------------------------------------------------------
|
13
|
+
|
14
|
+
def browsers
|
15
|
+
return [] unless feature_data
|
16
|
+
feature_data.fetch('stats', {}).inject([]) { |res, h| res << Browser.new(*h) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def for_browser name
|
20
|
+
browsers.detect{ |b| b.is?(name) }
|
21
|
+
end
|
22
|
+
|
23
|
+
private # =============================================================
|
24
|
+
|
25
|
+
def feature_data
|
26
|
+
@feature_data ||= CANIUSE_DATA['data'][@name]
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'user_agent_parser'
|
2
|
+
|
3
|
+
class CanIUse
|
4
|
+
class UserAgent
|
5
|
+
|
6
|
+
attr_accessor :user_agent_string
|
7
|
+
|
8
|
+
# =====================================================================
|
9
|
+
|
10
|
+
def initialize user_agent_string
|
11
|
+
@user_agent_string = user_agent_string
|
12
|
+
end
|
13
|
+
|
14
|
+
# ---------------------------------------------------------------------
|
15
|
+
|
16
|
+
def supports? feature_name, support_type=:yes
|
17
|
+
feature = Feature.new(feature_name)
|
18
|
+
browser = feature.for_browser(user_agent.family)
|
19
|
+
supported_from_version = browser.supported_from_version(support_type)
|
20
|
+
Gem::Version.new(user_agent.version.to_s.dup) >= Gem::Version.new(supported_from_version.to_s.dup)
|
21
|
+
end
|
22
|
+
|
23
|
+
private # =============================================================
|
24
|
+
|
25
|
+
def user_agent
|
26
|
+
UserAgentParser.parse(@user_agent_string)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CanIUse
|
4
|
+
describe Browser do
|
5
|
+
|
6
|
+
subject { CanIUse::Browser.new("ie", { "5.5"=>"n", "6"=>"p", "7"=>"p", "8"=>"p", "9"=>"y", "10"=>"y", "11"=>"y", "TP"=>"y" }) }
|
7
|
+
|
8
|
+
describe '#versions' do
|
9
|
+
it 'returns an array of versions' do
|
10
|
+
subject.versions.must_be_kind_of Array
|
11
|
+
subject.versions.map(&:class).uniq.first.must_equal CanIUse::BrowserVersion
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#version' do
|
16
|
+
it 'returns CanIUse::BrowserVersion' do
|
17
|
+
subject.version('6').must_be_kind_of CanIUse::BrowserVersion
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#supported_from_version' do
|
22
|
+
it 'returns supported version' do
|
23
|
+
subject.supported_from_version.must_be_kind_of CanIUse::BrowserVersion
|
24
|
+
subject.supported_from_version.to_s.must_equal '9'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns supported version with support type' do
|
28
|
+
subject.supported_from_version.must_be_kind_of CanIUse::BrowserVersion
|
29
|
+
subject.supported_from_version(:polyfill).to_s.must_equal '6'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# ---------------------------------------------------------------------
|
34
|
+
|
35
|
+
describe '#is?' do
|
36
|
+
describe 'chrome' do
|
37
|
+
let(:browser) { CanIUse::Browser.new("chrome", {}) }
|
38
|
+
it { browser.is?('Chrome').must_equal true }
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'ie' do
|
42
|
+
let(:browser) { CanIUse::Browser.new("ie", {}) }
|
43
|
+
it { browser.is?('IE').must_equal true }
|
44
|
+
it { browser.is?('MSIE').must_equal true }
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'safari' do
|
48
|
+
let(:browser) { CanIUse::Browser.new("safari", {}) }
|
49
|
+
it { browser.is?('Safari').must_equal true }
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'ios_saf' do
|
53
|
+
let(:browser) { CanIUse::Browser.new("ios_saf", {}) }
|
54
|
+
it { browser.is?('Safari Mobile').must_equal true }
|
55
|
+
it { browser.is?('Mobile Safari').must_equal true }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'firefox' do
|
59
|
+
let(:browser) { CanIUse::Browser.new("firefox", {}) }
|
60
|
+
it { browser.is?('Firefox').must_equal true }
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'opera' do
|
64
|
+
let(:browser) { CanIUse::Browser.new("opera", {}) }
|
65
|
+
it { browser.is?('Opera').must_equal true }
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'op_mini' do
|
69
|
+
let(:browser) { CanIUse::Browser.new("op_mini", {}) }
|
70
|
+
it { browser.is?('Opera Mini').must_equal true }
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'android' do
|
74
|
+
let(:browser) { CanIUse::Browser.new("android", {}) }
|
75
|
+
it { browser.is?('Android').must_equal true }
|
76
|
+
end
|
77
|
+
|
78
|
+
describe 'bb' do
|
79
|
+
let(:browser) { CanIUse::Browser.new("bb", {}) }
|
80
|
+
it { browser.is?('BlackBerry').must_equal true }
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'op_mob' do
|
84
|
+
let(:browser) { CanIUse::Browser.new("op_mob", {}) }
|
85
|
+
it { browser.is?('Opera Mobi').must_equal true }
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'and_chr' do
|
89
|
+
let(:browser) { CanIUse::Browser.new("and_chr", {}) }
|
90
|
+
it { browser.is?('Android Chrome').must_equal true }
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'and_ff' do
|
94
|
+
let(:browser) { CanIUse::Browser.new("and_ff", {}) }
|
95
|
+
it { browser.is?('Android Firefox').must_equal true }
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'ie_mob' do
|
99
|
+
let(:browser) { CanIUse::Browser.new("ie_mob", {}) }
|
100
|
+
it { browser.is?('IEMobile').must_equal true }
|
101
|
+
it { browser.is?('MSIE Mobile').must_equal true }
|
102
|
+
it { browser.is?('IE Mobile').must_equal true }
|
103
|
+
end
|
104
|
+
|
105
|
+
describe 'and_uc' do
|
106
|
+
let(:browser) { CanIUse::Browser.new("and_uc", {}) }
|
107
|
+
it { browser.is?('UCBrowser').must_equal true }
|
108
|
+
it { browser.is?('Android UC').must_equal true }
|
109
|
+
it { browser.is?('UC Browser').must_equal true }
|
110
|
+
it { browser.is?('Android UC Browser').must_equal true }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CanIUse
|
4
|
+
describe BrowserVersion do
|
5
|
+
|
6
|
+
describe 'support' do
|
7
|
+
it { CanIUse::BrowserVersion.new('0', 'y').support_type.must_equal :yes }
|
8
|
+
it { CanIUse::BrowserVersion.new('0', 'a').support_type.must_equal :almost }
|
9
|
+
it { CanIUse::BrowserVersion.new('0', 'n').support_type.must_equal :no }
|
10
|
+
it { CanIUse::BrowserVersion.new('0', 'p').support_type.must_equal :polyfill }
|
11
|
+
it { CanIUse::BrowserVersion.new('0', 'u').support_type.must_equal :unknown }
|
12
|
+
it { CanIUse::BrowserVersion.new('0', 'x').support_type.must_equal :prefix }
|
13
|
+
it { CanIUse::BrowserVersion.new('0', 'd').support_type.must_equal :disabled }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'sorting' do
|
17
|
+
let(:versions) {
|
18
|
+
[
|
19
|
+
CanIUse::BrowserVersion.new('1', 'n'),
|
20
|
+
CanIUse::BrowserVersion.new('1.1', 'n'),
|
21
|
+
CanIUse::BrowserVersion.new('1.0.5', 'n'),
|
22
|
+
CanIUse::BrowserVersion.new('1.10', 'n'),
|
23
|
+
CanIUse::BrowserVersion.new('10', 'n'),
|
24
|
+
CanIUse::BrowserVersion.new('6.5.4', 'n'),
|
25
|
+
CanIUse::BrowserVersion.new('3.1', 'n')
|
26
|
+
]
|
27
|
+
}
|
28
|
+
it 'sorts the versions' do
|
29
|
+
versions.sort.map(&:to_s).must_equal %w(1 1.0.5 1.1 1.10 3.1 6.5.4 10)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'comparison' do
|
34
|
+
let(:v1) { CanIUse::BrowserVersion.new('1.10', 'n') }
|
35
|
+
let(:v2) { CanIUse::BrowserVersion.new('5.0.4', 'n') }
|
36
|
+
|
37
|
+
it 'compares them' do
|
38
|
+
(v1 > v2).must_equal false
|
39
|
+
(v1 >= v2).must_equal false
|
40
|
+
(v1 < v2).must_equal true
|
41
|
+
(v1 <= v2).must_equal true
|
42
|
+
(v1 == v2).must_equal false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CanIUse
|
4
|
+
describe Feature do
|
5
|
+
|
6
|
+
describe 'WOFF' do
|
7
|
+
let(:feature) { CanIUse::Feature.new('woff') }
|
8
|
+
|
9
|
+
describe 'browser' do
|
10
|
+
it 'returns Hash of browsers' do
|
11
|
+
feature.browsers.must_be_kind_of Array
|
12
|
+
feature.browsers.map(&:class).uniq.first.must_equal CanIUse::Browser
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#for_browser' do
|
17
|
+
it 'return CanIUse::Browser' do
|
18
|
+
feature.for_browser('ie').must_be_kind_of CanIUse::Browser
|
19
|
+
feature.for_browser('ie').name.must_equal 'ie'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CanIUse
|
4
|
+
describe UserAgent do
|
5
|
+
|
6
|
+
let(:safari_8_user_agent_string) { 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/600.5.6 (KHTML, like Gecko) Version/8.0.5 Safari/600.5.6' }
|
7
|
+
let(:ie_6_user_agent_string) { 'Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)' }
|
8
|
+
|
9
|
+
# ---------------------------------------------------------------------
|
10
|
+
|
11
|
+
describe 'Safari 8' do
|
12
|
+
it 'supports "canvas"' do
|
13
|
+
CanIUse::UserAgent.new(safari_8_user_agent_string).supports?('canvas').must_equal true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'IE 6' do
|
18
|
+
it 'does not support "canvas"' do
|
19
|
+
CanIUse::UserAgent.new(ie_6_user_agent_string).supports?('canvas').must_equal false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: can_i_use
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tomas Celizna
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-03-07 00:00:00.000000000 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: user_agent_parser
|
17
|
+
requirement: &1 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *1
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: bundler
|
28
|
+
requirement: &2 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: coveralls
|
39
|
+
requirement: &3 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *3
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: guard
|
50
|
+
requirement: &4 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *4
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: guard-minitest
|
61
|
+
requirement: &5 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *5
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: minitest
|
72
|
+
requirement: &6 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *6
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rake
|
83
|
+
requirement: &7 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *7
|
92
|
+
description: Very light Ruby wrapper on caniuse data.
|
93
|
+
email:
|
94
|
+
- tomas.celizna@gmail.com
|
95
|
+
executables: []
|
96
|
+
extensions: []
|
97
|
+
extra_rdoc_files: []
|
98
|
+
files:
|
99
|
+
- ".gitmodules"
|
100
|
+
- Gemfile
|
101
|
+
- Gemfile.lock
|
102
|
+
- Guardfile
|
103
|
+
- LICENSE.txt
|
104
|
+
- README.md
|
105
|
+
- Rakefile
|
106
|
+
- can_i_use.gemspec
|
107
|
+
- lib/can_i_use.rb
|
108
|
+
- lib/can_i_use/browser.rb
|
109
|
+
- lib/can_i_use/browser_version.rb
|
110
|
+
- lib/can_i_use/feature.rb
|
111
|
+
- lib/can_i_use/user_agent.rb
|
112
|
+
- lib/can_i_use/version.rb
|
113
|
+
- test/can_i_use/browser_test.rb
|
114
|
+
- test/can_i_use/browser_version_test.rb
|
115
|
+
- test/can_i_use/feature_test.rb
|
116
|
+
- test/can_i_use/user_agent_test.rb
|
117
|
+
- test/can_i_use_test.rb
|
118
|
+
- test/test_helper.rb
|
119
|
+
has_rdoc: true
|
120
|
+
homepage: https://github.com/tomasc/can_i_use
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
hash: 2855716620795771990
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
hash: 2855716620795771990
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 1.3.9.5
|
148
|
+
signing_key:
|
149
|
+
specification_version: 3
|
150
|
+
summary: Very light Ruby wrapper on caniuse data.
|
151
|
+
test_files:
|
152
|
+
- test/can_i_use/browser_test.rb
|
153
|
+
- test/can_i_use/browser_version_test.rb
|
154
|
+
- test/can_i_use/feature_test.rb
|
155
|
+
- test/can_i_use/user_agent_test.rb
|
156
|
+
- test/can_i_use_test.rb
|
157
|
+
- test/test_helper.rb
|