Skip to content

Commit

Permalink
added preparation tool, Rakefile and jeweler integration
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkas authored and pinkas committed Sep 27, 2010
1 parent 4516d75 commit 0ea4d89
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1 +1,3 @@
run
pkg
rdoc
10 changes: 5 additions & 5 deletions README
Expand Up @@ -5,14 +5,14 @@ Included are tools to keep the WURFL file up to date automatically and to prepar
allow a fast device detection.

== Mode of Operation
The complete WURFL file is as big as ~16MB. A simple device detection against it in Ruby took 12 seconds, which is
The complete WURFL file is as big as ~16MB. A single device detection against it in Ruby took me 12 seconds, which is
inaceptable even for the first request of any client.

There are three optimizations to make the detection work faster:
1.) Client devices are roughly detected by type (e.g. iPhone like, Nokia devices, etc.)
2.) The WURFL file is customized to remove unused capabilities, reducing it's size considerably. (TERA-WURFL idea)
3.) The WURFL Client prepares lookup tables for the roughly detected device types in a Ruby PStore data structure, so Ruby
doesn't have to parse XML files on each request.
1.) The WURFL file is customized to remove unused capabilities, reducing it's size considerably. (TERA-WURFL idea)
2.) Client devices are roughly detected by type (e.g. iPhone like, Nokia devices, etc.)
3.) The WURFL Client works with previously prepared lookup tables for the roughly detected device types
in a Ruby PStore data structure, so Ruby doesn't have to parse XML files on each request.

The lookup tables are prepared during the WURFL update task, which takes quite some time. But this allows for a
very fast and for our appliances also accurate recognition.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.3.1
0.4.0
1 change: 1 addition & 0 deletions bin/prepare_lookup.rb
@@ -1,3 +1,4 @@
#!/usr/bin/env ruby
require "wurfl_client/lookup_preparer"
require "yaml"

Expand Down
1 change: 1 addition & 0 deletions bin/wurfl_minimize.rb
@@ -1,3 +1,4 @@
#!/usr/bin/env ruby
require "xml"
require "yaml"

Expand Down
47 changes: 27 additions & 20 deletions lib/wurfl_client/lookup_preparer.rb
@@ -1,25 +1,44 @@
require "lookup_helper.rb"
require "wurfl/loader"
require "wurfl_client/lookup_helper.rb"
require "wurfl_client/ua_device_detector.rb"
require "pstore"

module WurflClient

class LookupPreparer
def initialize(lookup_base_path)
@helper = LookupHelper.new(lookup_base_path)

def initialize(set_config)
config = set_config || {}
@wurfl_path = config['wurfl_path'] || 'wurfl-custom.xml'
@lookup_base_path = config['lookup_base_path'] || 'lookup/'

@helper = LookupHelper.new(@lookup_base_path)
end

def prepareLookupTables
@handsets = Wurfl::Loader.new.load_wurfl(@wurfl_path)
@handsets.each do |wurfl_id, handset|
target = UserAgentDeviceDetector.detect(handset.user_agent)
if target.lookup_prefix && !(target.lookup_prefix =~ /DO_NOT_MATCH/)
saveLookupTable target
else
puts "IGNORING UA: #{handset.user_agent}"
end
end
end

private

def saveLookupTable(profile)
store_filename = @helper.getStoreFilePath(profile.lookup_prefix)
return if File.exists?(store_filename)

# puts "building store: #{store_filename}"
@@handsets ||= Wurfl::Loader.new.load_wurfl(@wurfl_path)
puts "building store: #{store_filename}"

# load similar user agent strings
lookup_table = {}
detector = UserAgentDeviceDetector.new
@@handsets.each do |wurfl_id, handset|
target = detector.detect(handset.user_agent)
@handsets.each do |wurfl_id, handset|
target = UserAgentDeviceDetector.detect(handset.user_agent)
if target.lookup_prefix==profile.lookup_prefix
lookup_table[wurfl_id] ||= handset
end
Expand All @@ -29,17 +48,5 @@ def saveLookupTable(profile)
PStore.new(store_filename).transaction {|ps| ps["handsets"] = lookup_table}
end

def prepareLookupTables
@@handsets ||= Wurfl::Loader.new.load_wurfl(@wurfl_path)
detector = UserAgentDeviceDetector.new
@@handsets.each do |wurfl_id, handset|
target = detector.detect(handset.user_agent)
if target.lookup_prefix && !(target.lookup_prefix =~ /DO_NOT_MATCH/)
saveLookupTable target
else
puts "IGNORING UA: #{handset.user_agent}"
end
end
end
end
end

0 comments on commit 0ea4d89

Please sign in to comment.