def build_url(pattern, fragments)

      # Only allow league if sport is passed in.
      fragments.delete(:league) if fragments[:sport].to_s.empty?

      # Remove the /headlines section if fragments does not include a :method.
      # This is due to the HEADLINES API being a little strange.
      unless fragments.include? :method
        pattern.gsub!('headlines', '')
      end

      template = URITemplate.new(:colon, pattern)
      url = template.expand(fragments)

      # Remove duplicate slashes (if any)
      url = url.gsub(/\/{2,}/,'/')

      # Remove trailing slash (if any)
      url = url.gsub(/\/+$/, '')

      url
    end
def build_url(pattern, fragments)

      # Only allow league if sport is passed in.
      fragments.delete(:league) if fragments[:sport].to_s.empty?

      # Remove the /headlines section if fragments does not include a :method.
      # This is due to the HEADLINES API being a little strange.
      unless fragments.include? :method
        pattern.gsub!('headlines', '')
      end

      template = URITemplate.new(:colon, pattern)
      url = template.expand(fragments)

      # Remove duplicate slashes (if any)
      url = url.gsub(/\/{2,}/,'/')

      # Remove trailing slash (if any)
      url = url.gsub(/\/+$/, '')

      url
    end
Internal: Takes a pattern and a Hash of fragments and constructs a url.
 If the fragments include a league but not a sport, the league will be
 deleted from the Hash so it does not get sent along.

 pattern   - The pattern to match fragments against.
 fragments - The Array of fragments to apply to the pattern.

 Returns a String.