module Lti2Commons::Utils

Public Instance Methods

hash_to_query_string(hash) click to toggle source
# File lib/lti2_commons/lib/lti2_commons/utils.rb, line 17
def hash_to_query_string(hash)
  hash.keys.inject('') do |query_string, key|
    query_string << '&' unless key == hash.keys.first
    query_string << "#{URI.encode(key.to_s)}=#{CGI.escape(hash[key])}"
  end
end
is_hash_intersect(node, constraint_hash) click to toggle source
# File lib/lti2_commons/lib/lti2_commons/utils.rb, line 6
def is_hash_intersect(node, constraint_hash)
  # failed search if constraint_hash as invalid keys
  return nil if (constraint_hash.keys - node.keys).length > 0
  node.each_pair do |k, v|
    if constraint_hash.key?(k)
      return false unless v == constraint_hash[k]
    end
  end
  true
end
substitute_template_values_from_hash(source_string, prefix, suffix, hash) click to toggle source
# File lib/lti2_commons/lib/lti2_commons/utils.rb, line 24
def substitute_template_values_from_hash(source_string, prefix, suffix, hash)
  hash.each { |k, v| source_string.sub!(prefix + k + suffix, v) }
end