class PropsHandler

Copyright
Author

Class to provide methods and constants to handle properties.

The following public methods have been migrated from the v1.5.3 DeviceAtlas class:

Constants

ID_TO_PROPERTIES_WITH_TYPE
ID_TO_VALUES

Public static constant.

Public Class Methods

convertToTyped(propValue, type) click to toggle source

Given a property type, it converts a property value to a typed object.

# File ../Src/propshandler.rb, line 63
def self.convertToTyped(propValue, type) 
        case type
                when 's'
                        return propValue.to_s
                when 'b'
                        return (propValue.to_i == 1)
                when 'i'
                        return propValue.to_i
                when 'd'
                        return Date.parse(propValue)
        end
end
convertToTypedByPropertyId(tree, propValue, propertyId) click to toggle source

Given a property Id, it converts a property value to a typed object.

# File ../Src/propshandler.rb, line 56
def self.convertToTypedByPropertyId(tree, propValue, propertyId)
        type = tree[ID_TO_PROPERTIES_WITH_TYPE][propertyId.to_i][0..0]
        convertToTyped(propValue, type)
end
getValue(tree, propId, propValId, typed = false) click to toggle source

Gets the value for the property value id and either converts it to a strong type or returns a string.

# File ../Src/propshandler.rb, line 41
def self.getValue(tree, propId, propValId, typed = false)
        val = nil
        if typed
                # Return the property value as typed.
                obj = tree[ID_TO_VALUES][propValId]
                val = convertToTypedByPropertyId(tree, obj, propId)
        else
                # Return the value for a value's coded ID.                   
                val = tree[ID_TO_VALUES][propValId.to_i].to_s
        end
        val
end
mergeProperties(properties, uaProperties) click to toggle source

This function merges the properties that have been directly detected from the User-Agent with the main properties map from the JSON data file into one.

# File ../Src/propshandler.rb, line 30
def self.mergeProperties(properties, uaProperties)
        if properties && uaProperties
                uaProperties.each do |key,val|
                        properties[key] = val
                end
        end           
end
propertyFromId(tree, id) click to toggle source

Return the name for a property's coded ID.

# File ../Src/propshandler.rb, line 78
def self.propertyFromId(tree, id)
        string = tree[ID_TO_PROPERTIES_WITH_TYPE][id.to_i]
        return if string.nil? 
        string[1..string.size]
end