Class: Wurfl::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/wurfl/loader.rb

Overview

Handles the loading of WURFL handsets

Instance Method Summary collapse

Constructor Details

#initializeLoader

Returns a new instance of Loader.



14
15
16
# File 'lib/wurfl/loader.rb', line 14

def initialize 
  @handsets = Hash::new
end

Instance Method Details

#load_wurfl(wurflfilepath) ⇒ Object

Returns a Hash of loaded handsets.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/wurfl/loader.rb', line 19

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"], nil, element.attributes["actual_device_root"])
    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