require 'digest/sha1' # # A wrapper for generating SHA1 hash value # Simply done by concatenating all values using the colon symbol for delimiter. # This algorithm is mostly used by payment gateways. # # Usage: # # SHA1Generator.digest('foo', 'bar', 'fizz', 'buzz') # => "e723e86a6000fc8462142eb4821672de107535c1" # 40 chars # # hash_value = SHA1Generator.new('foo', 'bar', 'fizz', 'buzz') # hash_value.digestible_attributes # => "foo:bar:fizz:buzz" # # hash_value.digest # => "e723e86a6000fc8462142eb4821672de107535c1" # 40 chars # class SHA1Generator def self.digest(*attributes) new(*attributes).digest end def initialize(*attributes) @attrs = attributes end def digestible_attributes @attrs * ":" end def digest Digest::SHA1.hexdigest(digestible_attributes) end end