Module: ESS::Helpers

Included in:
Element
Defined in:
lib/ess/helpers.rb

Class Method Summary collapse

Class Method Details

.uuid(key = nil, prefix = 'ESSID:') ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ess/helpers.rb', line 6

def self.uuid key=nil, prefix='ESSID:'
  new_id = nil
  if key.nil?
    new_id = SecureRandom.uuid
  else
    chars = Digest::MD5.hexdigest(key)
    new_id = chars[0..8] + '-' +
             chars[8..12] + '-' +
             chars[12..16] + '-' +
             chars[16..20] + '-' +
             chars[20..32]
  end
  return prefix + new_id
end