lib/blinkbox/common_mapping.rb
# Uses the mapping file retrieved to convert a token into URLs. The first item in the hash
# will be the first provider listed in the first matched label group etc.
#
# Will retrieve the mapping afresh if the mapping data has expired (is older than the
# timeout value used to initialise this object)
#
# @param [URI] token The token (as a URI object) to look up.
# @raise UnknownLabelError if no mappings exist for the token given.
# @raise InvalidTokenError if the given token string isn't a valid token
# @return [Hash] A hash of provider names (key) to URLs (value) for this asset.
Uses the mapping file retrieved to convert a token into URLs. The first item in the hash
will be the first provider listed in the first matched label group etc.

Will retrieve the mapping afresh if the mapping data has expired (is older than the
timeout value used to initialise this object)
Uses the mapping file retrieved to convert a token into URLs . The first item in the hash will be the first provider listed in the first matched label group etc . Will retrieve the mapping afresh if the mapping data has expired ( is older than the timeout value used to initialise this object )
def map(token)
      raise InvalidTokenError unless valid_token?(token)
      retrieve_mapping! if (Time.now.to_i - @mapping[:timestamp].to_i > @timeout)
      @@logger.debug "Using mapping: #{@mapping[:data]}"
      matched_providers = {}
      @mapping[:data].each do |label_map|
        re = Regexp.new(label_map['extractor'])
        if token.match(re)
          @@logger.debug "Using #{label_map['label']}"
          capture_groups = Hash[
            Regexp.last_match.names.zip(Regexp.last_match.captures)
          ].inject({}){ |memo, (k, v)|
            memo[k.to_sym] = v
            memo
          }
          label_map['providers'].each_pair do |name, url_template|
            begin
              matched_providers[name] ||= (url_template % capture_groups)
            rescue
            end
          end
        end
      end
      matched_providers
    end
def map ( token ) raise InvalidTokenError unless valid_token? ( token ) retrieve_mapping! if ( Time . now . to_i - @mapping [ :timestamp ] . to_i > @timeout ) @@logger . debug "Using mapping: #{@mapping[:data]}" matched_providers = { } @mapping [ :data ] . each do | label_map | re = Regexp . new ( label_map [ 'extractor' ] ) if token . match ( re ) @@logger . debug "Using #{label_map['label']}" capture_groups = Hash [ Regexp . last_match . names . zip ( Regexp . last_match . captures ) ] . inject ( { } ) { | memo , ( k , v ) | memo [ k . to_sym ] = v memo } label_map [ 'providers' ] . each_pair do | name , url_template | begin matched_providers [ name ] ||= ( url_template % capture_groups ) rescue end end end end matched_providers end
Uses the mapping file retrieved to convert a token into URLs.
Uses the mapping file retrieved to convert a token into URLs .
# If there are multiple matching label_maps then providers from the first will take priority over later ones.
A hash of provider names (key) to URLs (value) for this asset.
A hash of provider names ( key ) to URLs ( value ) for this asset .
Hash
UnknownLabelError if no mappings exist for the token given.
UnknownLabelError if no mappings exist for the token given .
InvalidTokenError if the given token string isn't a valid token
InvalidTokenError if the given token string isn ' t a valid token
token
token The token (as a URI object) to look up.
token The token ( as a URI object ) to look up .