Copyright © 2014 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.
Constants to make keys more readable
# File ../../device_api/trunk/ruby/src/lib/ua_props.rb, line 39 def initialize tree_provider super(tree_provider, KEY_UA_RULES) # process the regexes - we need to override the default ones with any API # specific regexes init_process_regexes end
# File ../../device_api/trunk/ruby/src/lib/ua_props.rb, line 46 def put_properties user_agent, props_to_vals, sought = nil # first check list of items that skip rules - these are typically non-mobile # boolean properties such as isBrowser, isBot etc if skip_ua_rules props_to_vals return end regexes = @branch[KEY_REGEXES] # 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 rule_groups = @branch[KEY_RULE_GROUPS] rules_to_run = ua_property_rules(user_agent, props_to_vals, rule_groups, regexes) # STEP 2: try and extract properties using the rules if !rules_to_run.nil? extract_properties rules_to_run, user_agent, regexes, sought end end
Find all the properties that are used for matching.
group
The rule group that can contain a property matcher
prop_ids
The list of found property IDs
# File ../../device_api/trunk/ruby/src/lib/ua_props.rb, line 78 def init_get_matcher_propery_ids group, prop_ids # the properties matcher may not exist.... if group[KEY_PROPERTY_MATCHER] group[KEY_PROPERTY_MATCHER].each do |prop_id, prop_value| prop_ids.push(prop_id) unless prop_ids.include?(prop_id) end 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 ../../device_api/trunk/ruby/src/lib/ua_props.rb, line 92 def init_rule_sets group sets = group[KEY_RULE_SET] group[KEY_RULE_SET_COUNT] = sets.length return sets end