wurfl_device 0.1.10 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,12 +7,20 @@ require 'daemons'
7
7
  require 'wurfl_device'
8
8
  require 'msgpack/rpc'
9
9
 
10
+ $rpc_socket = File.join(ENV['HOME'], 'var', 'run', 'wurfldevice_rpc_server.sock')
11
+ $socket_only = false
10
12
  $rpc_host = '0.0.0.0'
11
13
  $rpc_port = 8090
12
- $state_dir = File.join(ENV['HOME'], '/var/run')
13
- $log_dir = File.join(ENV['HOME'], '/log')
14
+ $state_dir = File.join(ENV['HOME'], 'var', 'run')
15
+ $log_dir = File.join(ENV['HOME'], 'log')
14
16
 
15
17
  args = OptionParser.new do |opts|
18
+ opts.on("-s", "--socket=PATH", "set socket file to to PATH (default: #{$rpc_socket})") do |t|
19
+ $rpc_socket = t
20
+ end
21
+ opts.on("-t", "--socket-only", "listen using socket only (default: #{$socket_only})") do |t|
22
+ $socket_only = t
23
+ end
16
24
  opts.on("-o", "--host=HOST", "listen on HOST (default: #{$rpc_host})") do |t|
17
25
  $rpc_host = t
18
26
  end
@@ -1,16 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require 'wurfl_device/version'
3
-
4
- class Object
5
- def to_actual_value
6
- return self unless self.kind_of?(String)
7
- return false if self =~ /^false/i
8
- return true if self =~ /^true/i
9
- return self.to_i if (self == self.to_i.to_s)
10
- return self.to_f if (self == self.to_f.to_s)
11
- self
12
- end
13
- end
3
+ require 'msgpack'
14
4
 
15
5
  module WurflDevice
16
6
  autoload :UI, 'wurfl_device/ui'
@@ -45,21 +35,6 @@ module WurflDevice
45
35
  capabilities
46
36
  end
47
37
 
48
- def capability_from_user_agent(capability, user_agent)
49
- capability_key = capability
50
- if Settings::CAPABILITY_GROUPS.include?(capability)
51
- group_keys = Array.new
52
- Settings::CAPABILITY_TO_GROUP.select { |k, v| v == capability }.each_pair { |k, v| group_keys << "#{v}:#{k}" }
53
- group_vals = Cache.storage.hmget(Cache::UserAgents.build_cache_id(user_agent), *group_keys)
54
- return Cache.parse_actual_capabilities(Hash[*group_keys.zip(group_vals).flatten])[capability] if (group_vals.select { |v| v.nil? }.empty?)
55
- elsif Settings::CAPABILITY_TO_GROUP.key?(capability)
56
- capability_key = "#{Settings::CAPABILITY_TO_GROUP[capability]}:#{capability}"
57
- end
58
- actual_capability = WurflDevice::Cache::UserAgents.get(user_agent, capability_key)
59
- return actual_capability.to_actual_value unless actual_capability.nil?
60
- return nil
61
- end
62
-
63
38
  def capabilities_from_user_agent(user_agent)
64
39
  matcher = UserAgentMatcher.new
65
40
  matcher.match(user_agent)
@@ -9,19 +9,31 @@ module WurflDevice
9
9
  entries.each { |key| Cache.storage.del(build_cache_id(key)) }
10
10
  end
11
11
 
12
- def set(id, key, value)
12
+ def set(id, value)
13
+ Cache.storage.set(build_cache_id(id), value)
14
+ end
15
+
16
+ def get(id)
17
+ Cache.storage.get(build_cache_id(id))
18
+ end
19
+
20
+ def del(id)
21
+ Cache.storage.del(build_cache_id(id))
22
+ end
23
+
24
+ def hset(id, key, value)
13
25
  Cache.storage.hset(build_cache_id(id), key, value)
14
26
  end
15
27
 
16
- def get(id, key)
28
+ def hget(id, key)
17
29
  Cache.storage.hget(build_cache_id(id), key)
18
30
  end
19
31
 
20
- def keys(id)
32
+ def hkeys(id)
21
33
  Cache.storage.hkeys(build_cache_id(id))
22
34
  end
23
35
 
24
- def keys_values(id)
36
+ def hgetall(id)
25
37
  Cache.storage.hgetall(build_cache_id(id))
26
38
  end
27
39
 
@@ -33,14 +45,6 @@ module WurflDevice
33
45
  entry_ids
34
46
  end
35
47
 
36
- def get_value(id)
37
- Cache.storage.get(build_cache_id(id))
38
- end
39
-
40
- def set_value(id, value)
41
- Cache.storage.set(build_cache_id(id), value)
42
- end
43
-
44
48
  def build_cache_id(id)
45
49
  "#{self.name}:#{id}"
46
50
  end
@@ -49,15 +53,28 @@ module WurflDevice
49
53
 
50
54
  class Devices < Entries; end
51
55
  class UserAgents < Entries; end
56
+ class UserAgentsMatched < Entries; end
52
57
  class UserAgentsManufacturers < Entries; end
53
58
 
54
59
  class Status < Entries
60
+ def self.last_updated
61
+ get('last_updated') || ''
62
+ end
63
+
55
64
  def self.version
56
- keys 'version' || ''
65
+ hkeys 'version'
57
66
  end
58
67
 
59
- def self.last_updated
60
- get_value('last_updated') || ''
68
+ def self.initialized?
69
+ get 'initialized'
70
+ end
71
+
72
+ def self.initialize!
73
+ set 'initialized', 1
74
+ end
75
+
76
+ def self.uninitialize!
77
+ del 'initialized'
61
78
  end
62
79
  end
63
80
 
@@ -76,106 +93,80 @@ module WurflDevice
76
93
  end
77
94
 
78
95
  def initialized?
79
- Status.get_value('initialized').to_actual_value
96
+ Status.initialized?
80
97
  end
81
98
 
82
99
  def initialize_cache(xml_file)
83
100
  version_list = Array.new
84
101
 
102
+ Status.uninitialize!
85
103
  XmlLoader.load_xml_file(xml_file) do |capabilities|
86
104
  version = capabilities.delete(:version)
87
105
  version_list << version unless version.nil?
88
106
 
89
- device_id = capabilities.delete('id')
107
+ device_id = capabilities['id']
90
108
  next if device_id.nil? || device_id.empty?
91
109
 
92
- user_agent = capabilities.delete('user_agent')
110
+ user_agent = capabilities['user_agent']
93
111
  user_agent = Settings::GENERIC if user_agent.nil? || user_agent.empty?
94
112
  user_agent.strip!
95
113
 
96
- fall_back = capabilities.delete('fall_back')
114
+ fall_back = capabilities['fall_back']
97
115
  fall_back = '' if fall_back.nil?
98
116
  fall_back.strip!
99
117
 
100
- Devices.set device_id, 'id', device_id
101
- Devices.set device_id, 'user_agent', user_agent
102
- Devices.set device_id, 'fall_back', fall_back
103
-
104
118
  user_agent = UserAgent.new user_agent
105
- UserAgents.set user_agent, 'id', device_id
119
+ UserAgents.set user_agent, device_id
106
120
  unless user_agent =~ /^DO_NOT_MATCH/i
107
- UserAgentsManufacturers.set user_agent.manufacturer, user_agent, device_id
121
+ UserAgentsManufacturers.hset user_agent.manufacturer, user_agent, device_id
108
122
  end
109
123
 
110
- capabilities.each_pair do |key, value|
111
- if value.is_a?(Hash)
112
- value.each_pair do |k, v|
113
- Devices.set device_id, "#{key.to_s}:#{k.to_s}", v
114
- end
115
- else
116
- Devices.set device_id, key.to_s, value
117
- end
118
- end
124
+ Devices.set device_id, capabilities.to_msgpack
119
125
  end
120
126
 
121
127
  version_list.each do |ver|
122
- Status.set 'version', ver, Time.now
128
+ Status.hset 'version', ver, 1
123
129
  end
124
- Status.set_value 'last_updated', Time.now
125
- Status.set_value 'initialized', true
130
+ Status.set 'last_updated', Time.now
131
+
132
+ Status.initialize!
126
133
  end
127
134
 
128
135
  def rebuild_user_agents
129
136
  UserAgents.clear
130
137
  UserAgentsManufacturers.clear
131
138
  Devices.entries.each do |device_id|
132
- device = Devices.keys_values device_id
139
+ device = MessagePack.unpack(Devices.get(device_id))
133
140
  user_agent = UserAgent.new device['user_agent']
134
- UserAgents.set user_agent, 'id', device_id
141
+ UserAgents.set user_agent, device_id
135
142
  unless user_agent =~ /^DO_NOT_MATCH/i
136
- UserAgentsManufacturers.set user_agent.manufacturer, user_agent, device_id
143
+ UserAgentsManufacturers.hset user_agent.manufacturer, user_agent, device_id
137
144
  end
138
145
  end
139
- Status.set_value 'last_updated', Time.now
146
+ Status.set 'last_updated', Time.now
140
147
  end
141
148
 
142
149
  def update_actual_capabilities(user_agent, capabilities)
143
150
  capabilities.each_pair do |key, value|
144
151
  if value.kind_of?(Hash)
145
152
  value.each_pair do |k, v|
146
- UserAgents.set user_agent, "#{key}:#{k}", v
147
- end
148
- elsif value.is_a?(Array)
149
- value.each_with_index do |v, i|
150
- UserAgents.set user_agent, "#{key}:#{i}", v
153
+ UserAgents.set user_agent, "#{key}:#{k}", MessagePack.pack(v)
151
154
  end
152
155
  else
153
- UserAgents.set user_agent, key, value
156
+ if ['user_agent', 'fall_back', 'id'].include?(key)
157
+ UserAgents.set user_agent, key, value
158
+ else
159
+ UserAgents.set user_agent, key, MessagePack.pack(value)
160
+ end
154
161
  end
155
162
  end
156
163
  end
157
164
 
158
- def parse_actual_capabilities(actual_capabilities)
165
+ def build_capabilities(device_id)
159
166
  capabilities = Capability.new
160
167
 
161
- actual_capabilities.each_pair do |key, value|
162
- if key =~ /^(.+)\:(\d+)$/i
163
- capabilities[$1] ||= Array.new
164
- capabilities[$1][$2.to_i] = value.to_actual_value
165
- elsif key =~ /^(.+)\:(.+)$/i
166
- capabilities[$1] ||= Capability.new
167
- capabilities[$1][$2] = value.to_actual_value
168
- else
169
- capabilities[key] = value.to_actual_value
170
- end
171
- end
172
-
173
- capabilities
174
- end
168
+ actual_capabilities = MessagePack.unpack(Devices.get(device_id)) rescue nil
175
169
 
176
- def build_capabilities(device_id)
177
- capabilities = Capability.new
178
- actual_capabilities = Devices.keys_values(device_id)
179
170
  return capabilities if actual_capabilities.nil?
180
171
 
181
172
  capabilities['fall_back_tree'] ||= Array.new
@@ -188,24 +179,26 @@ module WurflDevice
188
179
  if value.kind_of?(Hash)
189
180
  capabilities[key] ||= Capability.new
190
181
  value.each_pair do |k, v|
191
- capabilities[key][k] = v.to_actual_value
182
+ capabilities[key][k] = v
192
183
  end
193
184
  elsif value.is_a?(Array)
194
185
  capabilities[key] ||= Array.new
195
- capabilities[key] |= value.to_actual_value
186
+ capabilities[key] |= value
196
187
  else
197
- capabilities[key] = value.to_actual_value
188
+ capabilities[key] = value
198
189
  end
199
190
  end
200
191
  end
201
192
  end
202
193
 
203
194
  actual_capabilities.each_pair do |key, value|
204
- if key =~ /^(.+)\:(.+)$/i
205
- capabilities[$1] ||= Capability.new
206
- capabilities[$1][$2] = value.to_actual_value
195
+ if value.kind_of?(Hash)
196
+ capabilities[key] ||= Capability.new
197
+ value.each_pair do |k, v|
198
+ capabilities[key][k] = v
199
+ end
207
200
  else
208
- capabilities[key] = value.to_actual_value
201
+ capabilities[key] = value
209
202
  end
210
203
  end
211
204
 
@@ -48,10 +48,16 @@ module WurflDevice
48
48
  method_option "matched-only", :type => :boolean, :banner => "show user agents that were matched", :aliases => "-m"
49
49
  def list
50
50
  matched_only = options['matched-only']
51
- WurflDevice::Cache::UserAgents.entries.each do |user_agent|
52
- kv = WurflDevice::Cache::UserAgents.keys_values user_agent
53
- next if kv.count <= 1 && matched_only
54
- WurflDevice.ui.info "#{user_agent}:#{kv['id']}"
51
+ if matched_only
52
+ Cache::UserAgentsMatched.entries.each do |user_agent|
53
+ capabilities = WurflDevice.capabilities_from_user_agent(user_agent)
54
+ WurflDevice.ui.info "#{user_agent}:#{capabilities.id}"
55
+ end
56
+ else
57
+ Cache::UserAgents.entries.each do |user_agent|
58
+ device_id = Cache::UserAgents.get(user_agent)
59
+ WurflDevice.ui.info "#{user_agent}:#{device_id}"
60
+ end
55
61
  end
56
62
  end
57
63
 
@@ -61,14 +67,14 @@ module WurflDevice
61
67
  xml_file ||= Settings.default_wurfl_xml_file
62
68
  unless options.update?
63
69
  WurflDevice.ui.info "clearing existing device cache."
64
- WurflDevice::Cache.clear
70
+ Cache.clear
65
71
  end
66
72
  WurflDevice.ui.info "initializing wurfl device cache."
67
- WurflDevice::Cache.initialize_cache(xml_file)
73
+ Cache.initialize_cache(xml_file)
68
74
 
69
75
  if options.update?
70
76
  WurflDevice.ui.info "rebuilding user agent cache."
71
- WurflDevice::Cache.rebuild_user_agents
77
+ Cache.rebuild_user_agents
72
78
  end
73
79
 
74
80
  status true
@@ -77,31 +83,25 @@ module WurflDevice
77
83
  desc "status", "show wurfl cache information"
78
84
  def status(skip_version=false)
79
85
  version unless skip_version
80
- unless WurflDevice::Cache.initialized?
86
+ unless Cache.initialized?
81
87
  WurflDevice.ui.info "cache is not initialized"
82
88
  return
83
89
  end
84
90
  WurflDevice.ui.info "cache info:"
85
- WurflDevice.ui.info " wurfl-xml version: " + WurflDevice::Cache::Status.version.join(' ')
86
- WurflDevice.ui.info " cache last updated: " + WurflDevice::Cache::Status.last_updated
87
- devices = WurflDevice::Cache::Devices.entries
88
- user_agents = WurflDevice::Cache::UserAgents.entries
91
+ WurflDevice.ui.info " wurfl-xml version: " + Cache::Status.version.join(' ')
92
+ WurflDevice.ui.info " cache last updated: " + Cache::Status.last_updated
93
+ devices = Cache::Devices.entries
94
+ user_agents = Cache::UserAgents.entries
89
95
  user_agents_message = ''
90
96
  user_agents_message = " (warning count should be greater than or equal to devices count)" if user_agents.length < devices.length
91
97
 
92
- matched_count = 0
93
- WurflDevice::Cache::UserAgents.entries.each do |user_agent|
94
- kv = WurflDevice::Cache::UserAgents.keys_values user_agent
95
- next if kv.count == 1
96
- matched_count = matched_count + 1
97
- end
98
98
  WurflDevice.ui.info " " + commify(devices.length) + " device id's"
99
99
  WurflDevice.ui.info " " + commify(user_agents.length) + " user agents in cache" + user_agents_message
100
- WurflDevice.ui.info " " + commify(matched_count) + " user agents matched"
100
+ WurflDevice.ui.info " " + commify(Cache::UserAgentsMatched.entries.count) + " user agents matched"
101
101
 
102
102
  user_agent_manufacturers = Array.new
103
- WurflDevice::Cache::UserAgentsManufacturers.entries.each do |index|
104
- user_agent_manufacturers << "#{index}(" + commify(WurflDevice::Cache::UserAgentsManufacturers.keys(index).length) + ")"
103
+ Cache::UserAgentsManufacturers.entries.each do |index|
104
+ user_agent_manufacturers << "#{index}(" + commify(Cache::UserAgentsManufacturers.hkeys(index).length) + ")"
105
105
  end
106
106
  user_agent_manufacturers.sort!
107
107
  WurflDevice.ui.info "wurfl user agent manufacturers:"
@@ -115,7 +115,7 @@ module WurflDevice
115
115
 
116
116
  desc "version", "show the wurfl_device version information"
117
117
  def version
118
- WurflDevice.ui.info "wurfl_device version #{WurflDevice::VERSION.freeze}"
118
+ WurflDevice.ui.info "wurfl_device version #{VERSION.freeze}"
119
119
  end
120
120
  map %w(-v --version) => :version
121
121
 
@@ -10,10 +10,5 @@ module WurflDevice
10
10
  capabilities = WurflDevice.capabilities_from_user_agent(user_agent)
11
11
  yield(capabilities)
12
12
  end
13
-
14
- def capability_from_user_agent(capability, user_agent)
15
- capabilities = WurflDevice.capability_from_user_agent(capability, user_agent)
16
- yield(capabilities)
17
- end
18
13
  end
19
14
  end
@@ -14,7 +14,7 @@ module WurflDevice
14
14
 
15
15
  def is_desktop_browser?
16
16
  ua = self.downcase
17
- WurflDevice::Settings::DESKTOP_BROWSERS.each do |sig|
17
+ Settings::DESKTOP_BROWSERS.each do |sig|
18
18
  return true if ua.index(sig)
19
19
  end
20
20
  return false
@@ -24,7 +24,7 @@ module WurflDevice
24
24
  ua = self.downcase
25
25
  return false if self.is_desktop_browser?
26
26
  return true if ua =~ /[^\d]\d{3}x\d{3}/
27
- WurflDevice::Settings::DESKTOP_BROWSERS.each do |sig|
27
+ Settings::DESKTOP_BROWSERS.each do |sig|
28
28
  return true if ua.index(sig)
29
29
  end
30
30
  return false
@@ -32,7 +32,7 @@ module WurflDevice
32
32
 
33
33
  def is_robot?
34
34
  ua = self.downcase
35
- WurflDevice::Settings::ROBOTS.each do |sig|
35
+ Settings::ROBOTS.each do |sig|
36
36
  return true if ua.index(sig)
37
37
  end
38
38
  return false
@@ -11,46 +11,47 @@ module WurflDevice
11
11
  @user_agent = user_agent
12
12
 
13
13
  # exact match
14
- capabilities = WurflDevice::Cache::UserAgents.keys_values(user_agent)
14
+ matched_data = Cache::UserAgentsMatched.get(user_agent)
15
+ unless matched_data.nil?
16
+ @capabilities = Capability.new(MessagePack.unpack(matched_data))
17
+ return self
18
+ end
15
19
 
16
20
  matched_ua = nil
17
- if capabilities['id'].nil? || capabilities['id'].empty?
18
- matcher = "matcher_#{user_agent.manufacturer.downcase}"
19
- if self.respond_to?(matcher)
20
- matched_ua = self.send(matcher, user_agent)
21
+ matcher = "matcher_#{user_agent.manufacturer.downcase}"
22
+ user_agent = user_agent.cleaned
23
+ if self.respond_to?(matcher)
24
+ matched_ua = self.send(matcher, user_agent)
25
+ else
26
+ if user_agent =~ /^Mozilla/i
27
+ tolerance = 5
28
+ matched_ua = ld_match(user_agent, tolerance)
21
29
  else
22
- if user_agent =~ /^Mozilla/i
23
- tolerance = 5
24
- matched_ua = ld_match(user_agent, tolerance)
25
- else
26
- tolerance = @user_agent.first_slash
27
- matched_ua = ris_match(@user_agent, tolerance)
28
- end
29
- end
30
-
31
- unless matched_ua.nil?
32
- capabilities = WurflDevice::Cache::UserAgents.keys_values(matched_ua)
30
+ tolerance = user_agent.first_slash
31
+ matched_ua = ris_match(user_agent, tolerance)
33
32
  end
34
33
  end
35
34
 
36
- if capabilities['id'].nil? || capabilities['id'].empty?
37
- capabilities = WurflDevice::Cache::UserAgents.keys_values(last_attempts(user_agent.cleaned))
35
+ unless matched_ua.nil?
36
+ device_id = Cache::UserAgents.get(matched_ua)
37
+ @capabilities = Cache.build_capabilities(device_id)
38
38
  end
39
39
 
40
- if capabilities.count == 1
41
- @capabilities = Cache.build_capabilities(capabilities['id'])
42
- Cache.update_actual_capabilities(user_agent, @capabilities)
43
- else
44
- @capabilities = WurflDevice::Cache.parse_actual_capabilities(capabilities)
40
+ if @capabilities.nil?
41
+ user_agent = user_agent.cleaned
42
+ device_id = Cache::UserAgents.get(last_attempts(user_agent))
43
+ @capabilities = Cache.build_capabilities(device_id)
45
44
  end
46
45
 
46
+ Cache::UserAgentsMatched.set @user_agent, MessagePack.pack(@capabilities)
47
+
47
48
  return self
48
49
  end
49
50
 
50
51
  def ris_match(user_agent, tolerance=nil)
51
- tolerance = WurflDevice::Settings::WORST_MATCH if tolerance.nil?
52
+ tolerance = Settings::WORST_MATCH if tolerance.nil?
52
53
  device = nil
53
- user_agent_list = WurflDevice::Cache::UserAgentsManufacturers.keys(user_agent.manufacturer).sort
54
+ user_agent_list = Cache::UserAgentsManufacturers.hkeys(user_agent.manufacturer).sort
54
55
  curlen = user_agent.length
55
56
  while curlen >= tolerance
56
57
  user_agent_list.each do |ua|
@@ -66,8 +67,8 @@ module WurflDevice
66
67
  end
67
68
 
68
69
  def ld_match(user_agent, tolerance=nil)
69
- tolerance = WurflDevice::Settings::WORST_MATCH if tolerance.nil?
70
- user_agent_list = WurflDevice::Cache::UserAgentsManufacturers.keys(user_agent.manufacturer).sort
70
+ tolerance = Settings::WORST_MATCH if tolerance.nil?
71
+ user_agent_list = Cache::UserAgentsManufacturers.hkeys(user_agent.manufacturer).sort
71
72
  length = user_agent.length
72
73
  best = tolerance
73
74
  current = 0
@@ -134,7 +135,7 @@ module WurflDevice
134
135
  when user_agent.contains(['Mozilla/4.0', 'Mozilla/5.0', 'Mozilla/6.0'])
135
136
  'DO_NOT_MATCH_GENERIC_WEB_BROWSER'
136
137
  else
137
- WurflDevice::Settings::GENERIC
138
+ Settings::GENERIC
138
139
  end
139
140
 
140
141
  return device_ua
@@ -260,7 +261,7 @@ module WurflDevice
260
261
  when user_agent.contains('iPhone')
261
262
  'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A538a Safari/419.3'
262
263
  else
263
- WurflDevice::Contants::GENERIC
264
+ Settings::GENERIC
264
265
  end
265
266
  end
266
267
  return matched_ua
@@ -388,7 +389,7 @@ module WurflDevice
388
389
  end
389
390
 
390
391
  def matcher_portalmmm(user_agent)
391
- return WurflDevice::Settings::GENERIC
392
+ return Settings::GENERIC
392
393
  end
393
394
 
394
395
  def matcher_qtek(user_agent)
@@ -512,7 +513,7 @@ module WurflDevice
512
513
  if user_agent.contains(['SLCC1', 'Media Center PC', '.NET CLR', 'OfficeLiveConnector'])
513
514
  matched_ua'DO_NOT_MATCH_GENERIC_WEB_BROWSER'
514
515
  else
515
- matched_ua = WurflDevice::Settings::GENERIC
516
+ matched_ua = Settings::GENERIC
516
517
  end
517
518
  end
518
519
  return matched_ua
@@ -582,7 +583,7 @@ module WurflDevice
582
583
  when user_agent.contains('Macintosh') || user_agent.contains('Windows')
583
584
  'DO_NOT_MATCH_GENERIC_WEB_BROWSER'
584
585
  else
585
- WurflDevice::Settings::GENERIC
586
+ Settings::GENERIC
586
587
  end
587
588
  end
588
589
  return matched_ua
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module WurflDevice
4
- VERSION = "0.1.10".freeze
4
+ VERSION = "0.2.0".freeze
5
5
  end
@@ -3,6 +3,15 @@ require 'ox'
3
3
 
4
4
  module WurflDevice
5
5
  class XmlLoader
6
+ def self.to_actual_value(value)
7
+ return value unless value.kind_of?(String)
8
+ return false if value =~ /^false/i
9
+ return true if value =~ /^true/i
10
+ return value.to_i if (value == value.to_i.to_s)
11
+ return value.to_f if (value == value.to_f.to_s)
12
+ value
13
+ end
14
+
6
15
  def self.load_xml_file(wurfl_file, &blk)
7
16
  begin
8
17
  file_contents = File.open(wurfl_file).read.force_encoding('UTF-8')
@@ -34,16 +43,16 @@ module WurflDevice
34
43
  elem2.nodes.map do |device|
35
44
  next unless device.value =~ /device/i
36
45
  capabilities = Hash.new
37
- capabilities['id'] = device.attributes[:id] || ''
38
- capabilities['user_agent'] = device.attributes[:user_agent] || ''
39
- capabilities['fall_back'] = device.attributes[:fall_back] || ''
46
+ capabilities['id'] = (device.attributes[:id] || '')
47
+ capabilities['user_agent'] = (device.attributes[:user_agent] || '')
48
+ capabilities['fall_back'] = (device.attributes[:fall_back] || '')
40
49
 
41
50
  device.nodes.map do |group|
42
51
  next unless group.value =~ /group/i
43
52
  group.nodes.map do |capability|
44
53
  capabilities[group.attributes[:id]] ||= Hash.new
45
54
  next unless capability.value =~ /capability/i
46
- capabilities[group.attributes[:id]][capability.attributes[:name]] = capability.attributes[:value]
55
+ capabilities[group.attributes[:id]][capability.attributes[:name]] = to_actual_value(capability.attributes[:value])
47
56
  end
48
57
  end
49
58
  yield capabilities if block_given?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wurfl_device
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: msgpack-rpc
16
- requirement: &38015820 !ruby/object:Gem::Requirement
16
+ requirement: &227074280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *38015820
24
+ version_requirements: *227074280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: daemons
27
- requirement: &38015120 !ruby/object:Gem::Requirement
27
+ requirement: &227073240 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *38015120
35
+ version_requirements: *227073240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hiredis
38
- requirement: &38014260 !ruby/object:Gem::Requirement
38
+ requirement: &227072160 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *38014260
46
+ version_requirements: *227072160
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: redis
49
- requirement: &38013380 !ruby/object:Gem::Requirement
49
+ requirement: &227071320 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *38013380
57
+ version_requirements: *227071320
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: thor
60
- requirement: &38011220 !ruby/object:Gem::Requirement
60
+ requirement: &227070660 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *38011220
68
+ version_requirements: *227070660
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: ox
71
- requirement: &38009440 !ruby/object:Gem::Requirement
71
+ requirement: &227070000 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *38009440
79
+ version_requirements: *227070000
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: text
82
- requirement: &38007400 !ruby/object:Gem::Requirement
82
+ requirement: &227069080 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *38007400
90
+ version_requirements: *227069080
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: bundler
93
- requirement: &38004280 !ruby/object:Gem::Requirement
93
+ requirement: &227058420 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 1.0.10
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *38004280
101
+ version_requirements: *227058420
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rake
104
- requirement: &37181180 !ruby/object:Gem::Requirement
104
+ requirement: &227057900 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 0.9.2
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *37181180
112
+ version_requirements: *227057900
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: rspec-core
115
- requirement: &37176540 !ruby/object:Gem::Requirement
115
+ requirement: &227057420 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '2.0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *37176540
123
+ version_requirements: *227057420
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: rspec-expectations
126
- requirement: &37174980 !ruby/object:Gem::Requirement
126
+ requirement: &227056840 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ~>
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '2.0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *37174980
134
+ version_requirements: *227056840
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: rr
137
- requirement: &37173860 !ruby/object:Gem::Requirement
137
+ requirement: &227056380 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ~>
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '1.0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *37173860
145
+ version_requirements: *227056380
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: simplecov
148
- requirement: &37173180 !ruby/object:Gem::Requirement
148
+ requirement: &227055880 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ~>
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: 0.5.3
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *37173180
156
+ version_requirements: *227055880
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: fakeredis
159
- requirement: &37171500 !ruby/object:Gem::Requirement
159
+ requirement: &227055380 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ~>
@@ -164,7 +164,7 @@ dependencies:
164
164
  version: 0.2.2
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *37171500
167
+ version_requirements: *227055380
168
168
  description: Ruby client library for mobile handset detection
169
169
  email:
170
170
  - ahutalla@gmail.com