browscapper 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/browscapper.rb +42 -1
- data/lib/browscapper/reader/ini_reader.rb +8 -1
- data/lib/browscapper/version.rb +1 -1
- data/test/browscapper_tests.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39b549bee437718dcededa7f863cc7402d5cf841
|
4
|
+
data.tar.gz: a724111c15b2a18169fc034bfc56f70a153a97bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e15dd9162487600cd2af82cbd0f22ff73c597d61f20dd61a7270a744fc5590be5954410de07597c75f176c1ee370454b69e183bb6ff9c81ec1b69a11294f21ef
|
7
|
+
data.tar.gz: a80a6b3770b244f18dd301f3ce2b6b74f0868a99cd3ac1972bf26225087586aa22f53b693695d3c142c22165a27c3aa1d0f6ed6f2f08a98d77a76ef0ddc70c5b
|
data/lib/browscapper.rb
CHANGED
@@ -10,6 +10,15 @@ module Browscapper
|
|
10
10
|
autoload :INIReader, 'browscapper/reader/ini_reader'
|
11
11
|
autoload :MarshalReader, 'browscapper/reader/marshal_reader'
|
12
12
|
|
13
|
+
class Error < RuntimeError
|
14
|
+
end
|
15
|
+
|
16
|
+
class NotLoadedError < Error
|
17
|
+
def initialize
|
18
|
+
super("Browscap file not loaded")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
13
22
|
class << self
|
14
23
|
attr_reader :entries, :file
|
15
24
|
MATCH_CACHE = Hash.new
|
@@ -49,7 +58,7 @@ module Browscapper
|
|
49
58
|
ua_len = ua_str.length
|
50
59
|
|
51
60
|
MATCH_CACHE[ua] ||= @entries.select { |k, v|
|
52
|
-
v[:pattern] =~ ua_str if v
|
61
|
+
v[:pattern] =~ ua_str if v && v[:pattern]
|
53
62
|
}.sort_by { |(k, v)|
|
54
63
|
ua_len - v[:user_agent].gsub(/[?*]/, '').length
|
55
64
|
}.collect { |(k, v)|
|
@@ -69,6 +78,38 @@ module Browscapper
|
|
69
78
|
end
|
70
79
|
alias :query :match
|
71
80
|
|
81
|
+
def browscap_version
|
82
|
+
raise Browscapper::NotLoadedError.new if entries.nil?
|
83
|
+
|
84
|
+
if entries[:browscap_version] && entries[:browscap_version][:version]
|
85
|
+
entries[:browscap_version][:version]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def browscap_released
|
90
|
+
raise Browscapper::NotLoadedError.new if entries.nil?
|
91
|
+
|
92
|
+
if entries[:browscap_version] && entries[:browscap_version][:released]
|
93
|
+
Date.parse(entries[:browscap_version][:released])
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def browscap_format
|
98
|
+
raise Browscapper::NotLoadedError.new if entries.nil?
|
99
|
+
|
100
|
+
if entries[:browscap_version] && entries[:browscap_version][:format]
|
101
|
+
entries[:browscap_version][:format]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def browscap_type
|
106
|
+
raise Browscapper::NotLoadedError.new if entries.nil?
|
107
|
+
|
108
|
+
if entries[:browscap_version] && entries[:browscap_version][:type]
|
109
|
+
entries[:browscap_version][:type]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
72
113
|
private
|
73
114
|
def ua_empty?(ua)
|
74
115
|
return true if ua.nil?
|
@@ -9,6 +9,13 @@ module Browscapper
|
|
9
9
|
|
10
10
|
def load(file)
|
11
11
|
ini = IniFile.load(file, :encoding => 'BINARY')
|
12
|
+
|
13
|
+
entries = {
|
14
|
+
browscap_version: ini['GJK_Browscap_Version'].each_with_object({}) { |(k, v), memo|
|
15
|
+
memo[k.downcase.to_sym] = v
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
12
19
|
ini.delete_section('GJK_Browscap_Version')
|
13
20
|
|
14
21
|
injector = proc { |memo, section|
|
@@ -40,7 +47,7 @@ module Browscapper
|
|
40
47
|
memo
|
41
48
|
}
|
42
49
|
|
43
|
-
ini.sections.inject(
|
50
|
+
ini.sections.inject(entries, &injector)
|
44
51
|
end
|
45
52
|
end
|
46
53
|
end
|
data/lib/browscapper/version.rb
CHANGED
data/test/browscapper_tests.rb
CHANGED
@@ -75,4 +75,20 @@ class BrowscapperTest < MiniTest::Unit::TestCase
|
|
75
75
|
|
76
76
|
assert_equal(FIREFOX_ON_OSX, Browscapper.match(value))
|
77
77
|
end
|
78
|
+
|
79
|
+
def test_browscap_version
|
80
|
+
assert_equal(5036, Browscapper.browscap_version)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_browscap_released
|
84
|
+
assert_equal(Date.parse("Wed, 19 Nov 2014 21:12:38 +0000"), Browscapper.browscap_released)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_browscap_format
|
88
|
+
assert_equal("php", Browscapper.browscap_format)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_browscap_type
|
92
|
+
assert_equal("FULL", Browscapper.browscap_type)
|
93
|
+
end
|
78
94
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: browscapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- J Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inifile
|