Skip to content

Instantly share code, notes, and snippets.

@cilquirm
Created February 22, 2013 15:42
Show Gist options
  • Save cilquirm/5014302 to your computer and use it in GitHub Desktop.
Save cilquirm/5014302 to your computer and use it in GitHub Desktop.
self.guid = Digest::SHA2.new.tap do |d|
d << (self.name || "NULL")
d << (self.key || "NULL")
d << (self.infogroup_id || "NULL")
d << (self.street || "NULL")
d << (self.city || "NULL" )
d << (self.state || "NULL")
end
@ebarendt
Copy link

How about:

self.guid = Digest::SHA2.new.tap do |d|
  %w(name key infogroup_id street city state).each do |field|
    d << (send(field) || "NULL")
  end
end

@matthuhiggins
Copy link

Digest::SHA2.hexdigest attributes.values_at('name', 'key', 'infogroup_id', 'street', 'city', 'state').to_json

Eric's answer is more complete. What I pasted is what we do in place_directory, which you'll see in a few files called identity.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment