wurfl-lite 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/wurfl-lite.rb +22 -13
- data/lib/wurfl-lite/version.rb +1 -1
- metadata +4 -4
data/lib/wurfl-lite.rb
CHANGED
@@ -11,19 +11,21 @@ class WURFL
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def clear!
|
15
|
+
@devices = Hash.new
|
16
|
+
@devices_by_id = {}
|
17
|
+
end
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
def process_xml!( filename )
|
20
|
+
data = open( filename ).read
|
21
|
+
begin # Try decompress it, in case it's a compressed file
|
22
|
+
# XXX Yes, this does seem ugly, but is there another way?
|
23
|
+
data = Zlib::GzipReader.new(StringIO.new(data.to_s)).read
|
24
|
+
rescue Zlib::GzipFile::Error
|
25
|
+
end
|
23
26
|
doc = Hpricot( data )
|
24
27
|
|
25
|
-
|
26
|
-
devices_by_id = {}
|
28
|
+
keys_added = []
|
27
29
|
|
28
30
|
(doc/'devices'/'device').each do |device_element|
|
29
31
|
device = Hash.new
|
@@ -42,16 +44,23 @@ class WURFL
|
|
42
44
|
device[ name ] = value
|
43
45
|
end
|
44
46
|
|
47
|
+
keys_added << device[ :user_agent ]
|
45
48
|
@devices[ device[ :user_agent ] ] = device
|
46
|
-
devices_by_id[ device[ :id ] ] = device
|
49
|
+
@devices_by_id[ device[ :id ] ] = device
|
47
50
|
end
|
48
51
|
|
49
|
-
|
50
|
-
@devices[ key ][ :fall_back ] = devices_by_id[ @devices[ key ][ :fall_back ] ]
|
52
|
+
keys_added.each do |key|
|
53
|
+
@devices[ key ][ :fall_back ] = @devices_by_id[ @devices[ key ][ :fall_back ] ]
|
51
54
|
end
|
52
55
|
|
53
56
|
end
|
54
57
|
|
58
|
+
def initialize( filename = 'http://downloads.sourceforge.net/project/wurfl/WURFL/latest/wurfl-latest.xml.gz' )
|
59
|
+
clear!
|
60
|
+
process_xml!( filename )
|
61
|
+
process_xml!( 'http://wurfl.sourceforge.net/web_browsers_patch.xml' )
|
62
|
+
end
|
63
|
+
|
55
64
|
def []( user_agent )
|
56
65
|
device = @devices[ user_agent ]
|
57
66
|
return device if device
|
data/lib/wurfl-lite/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 2
|
9
|
+
version: 1.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Clive Crous
|
@@ -114,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
hash:
|
117
|
+
hash: 602051377
|
118
118
|
segments:
|
119
119
|
- 0
|
120
120
|
version: "0"
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
requirements:
|
124
124
|
- - ">="
|
125
125
|
- !ruby/object:Gem::Version
|
126
|
-
hash:
|
126
|
+
hash: 602051377
|
127
127
|
segments:
|
128
128
|
- 0
|
129
129
|
version: "0"
|