class Wurfl::Handset
A class that represents a handset based on information taken from the WURFL.
Attributes
Public Class Methods
Constructor Parameters: wurfl_id
: is the WURFL ID of the handset useragent: is the user agent of the handset fallback: is the fallback handset that this handset
uses for missing details.
# File lib/wurfl/handset.rb, line 19 def initialize (wurfl_id, useragent, fallback = nil, actual_device = nil) @capabilities = {} @wurfl_id = wurfl_id @user_agent = useragent @actual_device = actual_device @fallback = fallback end
Public Instance Methods
A method to do a simple equality check against two handsets. Parameter: other: Is the another WurflHandset to check against. Returns: true if the two handsets are equal in all values. false if they are not exactly equal in values, id and user agent. Note: for a more detailed comparison, use the compare method.
# File lib/wurfl/handset.rb, line 68 def ==(other) other.instance_of?(Wurfl::Handset) && self.wurfl_id == other.wurfl_id && self.user_agent == other.user_agent && other.keys.all? {|key| other[key] == self[key] } end
Hash accessor Parameters: key: the WURFL key whose value is desired Returns: The value of the key, nil if the handset does not have the key.
# File lib/wurfl/handset.rb, line 40 def [] (key) @capabilities.key?(key) ? @capabilities[key] : fallback[key] end
Setter, A method to set a key and value of the handset.
# File lib/wurfl/handset.rb, line 52 def []= (key,val) @capabilities[key] = val end
# File lib/wurfl/handset.rb, line 27 def actual_device? @actual_device end
# File lib/wurfl/handset.rb, line 75 def differences(other) keys = (self.keys | other.keys) keys.find_all {|k| self[k] != other[k]} end
# File lib/wurfl/handset.rb, line 31 def fallback @fallback || NullHandset.instance end
A method to get all of the keys that the handset has.
# File lib/wurfl/handset.rb, line 57 def keys @capabilities.keys | fallback.keys end
Returns: the wurfl id of the handset from which the value of a capability is obtained
# File lib/wurfl/handset.rb, line 47 def owner(key) @capabilities.key?(key) ? @wurfl_id : fallback.owner(key) end