Module: Lti2Commons::Utils
- Defined in:
- lib/lti2_commons/lib/lti2_commons/utils.rb
Instance Method Summary collapse
- #hash_to_query_string(hash) ⇒ Object
- #is_hash_intersect(node, constraint_hash) ⇒ Object
- #substitute_template_values_from_hash(source_string, prefix, suffix, hash) ⇒ Object
Instance Method Details
#hash_to_query_string(hash) ⇒ Object
17 18 19 20 21 22 |
# 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) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# 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) ⇒ Object
24 25 26 |
# 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 |