Module: Lti2Commons::Utils

Defined in:
lib/lti2_commons/utils.rb

Instance Method Summary collapse

Instance Method Details

#hash_to_query_string(hash) ⇒ Object



18
19
20
21
22
23
# File 'lib/lti2_commons/utils.rb', line 18

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) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/lti2_commons/utils.rb', line 7

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 {|k,v|
    if constraint_hash.has_key? k 
      return false unless v == constraint_hash[k]
    end
  }
  true
end

#log(msg) ⇒ Object



25
26
27
# File 'lib/lti2_commons/utils.rb', line 25

def log(msg)
  # puts msg
end

#substitute_template_values_from_hash(source_string, prefix, suffix, hash) ⇒ Object



29
30
31
# File 'lib/lti2_commons/utils.rb', line 29

def substitute_template_values_from_hash(source_string, prefix, suffix, hash)
  hash.each { |k,v| source_string.sub!(prefix+k+suffix, v) }
end