Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/updateagent/hash_extensions.rb
Instance Method Summary collapse
-
#values_for_hash(*attrs) ⇒ Object
creates a uniq sha1 digest of the hash’s values should mirror similar code in OneBody’s lib/db_tools.rb.
- #values_hash(*attrs) ⇒ Object
Instance Method Details
#values_for_hash(*attrs) ⇒ Object
creates a uniq sha1 digest of the hash’s values should mirror similar code in OneBody’s lib/db_tools.rb
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/updateagent/hash_extensions.rb', line 4 def values_for_hash(*attrs) attrs = keys.sort unless attrs.any? attrs = attrs.first if attrs.first.is_a?(Array) values = attrs.map do |attr| value = self[attr.to_s] if value.respond_to?(:strftime) value.strftime('%Y-%m-%d %H:%M:%S') elsif value == true 1 elsif value == false 0 else value end end end |
#values_hash(*attrs) ⇒ Object
21 22 23 |
# File 'lib/updateagent/hash_extensions.rb', line 21 def values_hash(*attrs) Digest::SHA1.hexdigest(values_for_hash(*attrs).join) end |