Sha256: 8479d414ad82471e99ed421d62cce5a18a0713f11c4d4037ba7e3cbc80839d6b

Contents?: true

Size: 608 Bytes

Versions: 17

Compression:

Stored size: 608 Bytes

Contents

class Hash
  # creates a uniq sha1 digest of the hash's values
  # should mirror similar code in OneBody's lib/db_tools.rb
  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
  
  def values_hash(*attrs)
    Digest::SHA1.hexdigest(values_for_hash(*attrs).join)
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
onebody-updateagent-0.6.7 lib/updateagent/hash_extensions.rb
onebody-updateagent-0.6.6 lib/updateagent/hash_extensions.rb
onebody-updateagent-0.6.5 lib/updateagent/hash_extensions.rb
onebody-updateagent-0.6.4 lib/updateagent/hash_extensions.rb
onebody-updateagent-0.6.3 lib/updateagent/hash_extensions.rb
onebody-updateagent-0.6.2 lib/updateagent/hash_extensions.rb
onebody-updateagent-0.6.1 lib/updateagent/hash_extensions.rb
onebody-updateagent-0.6.0 lib/updateagent/hash_extensions.rb
onebody-updateagent-0.5.4 lib/updateagent/hash_extensions.rb
onebody-updateagent-0.5.3 lib/updateagent/hash_extensions.rb
onebody-updateagent-0.5.2 lib/updateagent/hash_extensions.rb
onebody-updateagent-0.5.1 lib/updateagent/hash_extensions.rb
onebody-updateagent-0.5.0 lib/updateagent/hash_extensions.rb
onebody-updateagent-0.4.3 lib/updateagent/hash_extensions.rb
onebody-updateagent-0.4.2 lib/updateagent/hash_extensions.rb
onebody-updateagent-0.4.1 lib/updateagent/hash_extensions.rb
onebody-updateagent-0.4.0 lib/updateagent/hash_extensions.rb