Copyright © 2013 by mTLD Top Level Domain Limited. All rights reserved.
Portions copyright © 2008 by Argo Interactive Limited.
Portions copyright © 2008 by Nokia Inc.
Portions copyright © 2008 by Telecom Italia Mobile S.p.A.
Portions copyright © 2008 by Volantis Systems Limited.
Portions copyright © 2002-2008 by Andreas Staeding.
Portions copyright © 2008 by Zandan.
dotMobi
This class tries to extract properties from the User-Agent string itself. This is a completely separate step to the main JSON tree walk but uses the results of the tree walk to optimise the property extraction. The property extraction is done in two steps.
Step 1: Try and identify the type of User-Agent and thus the set of property extraction rules to run. This is optimised by the properties from the tree walk.
Step 2: Run the rules found in step 1 to try and extract the properties.
Set a public static constant.
# File ../Src/uaprops.rb, line 38 def initialize(tree) # Set the private constants @SKIP_IDS = 'sk' @RULE_GROUPS = "rg" @REGEXES = "reg" @DEFAULT_REGEX_SET = "d" @REFINE_REGEX_ID = "f" @SEARCH_REGEX_ID = "s" @RULE_REGEX_ID = "r" @REGEX_MATCH_POS = "m" super(tree, UA_RULES) # process the regexes - we need to override the default ones with any API # specific regexes initProcessRegexes end
Get the User-Agent string properties using the User-Agent rules.
userAgent
The User-Agent to find properties for
idProperties
The results of the tree walk, map of property id to value id
sought
A set of properties to return values for.
typedValues
Whether to return typed values or string values
# File ../Src/uaprops.rb, line 118 def getProperties(userAgent, idProperties, sought, typedValues) propsToReturn = nil # first check list of items that skip rules - these are typically non-mobile # boolean properties such as isBrowser, isBot etc if skipUaRules(idProperties) return propsToReturn end regexes = @branch[@REGEXES] # we'll need this later... # now find the rules to run on the UA. This is a two step process. # Step 1 identifies the UA type and finds as list of rules to run. # Step 2 uses the list of rules to find properties in a UA # STEP 1: try and find the rules to run on the UA ruleGroups = @branch[@RULE_GROUPS] rulesToRun = getUaPropertyRules(userAgent, idProperties, ruleGroups, regexes) # STEP 2: try and extract properties using the rules if rulesToRun.any? propsToReturn = extractProperties(rulesToRun, userAgent, regexes, sought, typedValues) end propsToReturn end
Find all the properties that are used for matching. This is needed in case the Api.getProperty() function is called as we need these properties for the User-Agent extraction rules to work correctly.
group
The rule group that can contain a property matcher
propIds
The list of found property IDs
# File ../Src/uaprops.rb, line 64 def initGetMatcherPropertyIds(group, propIds) # the properties matcher may not exist.... if group[@PROPERTY_MATCHER] group[@PROPERTY_MATCHER].each { |propId, propValue| propIds.push(propId) unless propIds.include?(propId) } end end
Prepare the rule set by extracting it from the current group and counting the items in the group. This is done to avoid counting the items on every request.
group
The current parent group.
# File ../Src/uaprops.rb, line 79 def initRuleSets(group) sets = group[@RULE_SET] group[@RULE_SET_COUNT] = sets.length sets end