Sha256: 04ee0b12e13f6bc13a3136c7e8fc0aaec05d999e813261cd638c1b164f74923e

Contents?: true

Size: 944 Bytes

Versions: 2

Compression:

Stored size: 944 Bytes

Contents

require "wurfl/handset"
begin
  require "xml"
rescue LoadError
  require "rubygems"
  require "xml"
end

module Wurfl; end

# Handles the loading of WURFL handsets
class Wurfl::Loader
  
  def initialize 
    @handsets = Hash::new
  end
  
  # Returns a Hash of loaded handsets.
  def load_wurfl(wurflfilepath)
    fallbacks = {}
    doc = XML::Document.file(wurflfilepath)
    doc.find("///devices/device").each do |element| 
      wurfl_id = element.attributes["id"]  
      h = @handsets[wurfl_id] ||= Wurfl::Handset.new(wurfl_id, element.attributes["user_agent"])
      fall_back_id = element.attributes["fall_back"]
      fallbacks[wurfl_id] = fall_back_id unless fall_back_id == "root"
      
      element.find("group/capability").each do |capability|
        h[capability.attributes["name"]] = capability.attributes["value"]
      end
    end

    fallbacks.each {|k,v| @handsets[k].fallback = @handsets[v]}
  
    @handsets
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wurfl-1.3.0 lib/wurfl/loader.rb
wurfl-1.3.1 lib/wurfl/loader.rb