Module: UidHelper
Instance Method Summary collapse
- #nsec_uuid(prefix = '') ⇒ Object
- #rand_string(len = 4) ⇒ Object
- #sec_uuid(prefix = '') ⇒ Object
- #uuid(int, prefix = '', suffix = '') ⇒ Object
Instance Method Details
#nsec_uuid(prefix = '') ⇒ Object
16 17 18 19 20 |
# File 'lib/rails_com/helpers/uid_helper.rb', line 16 def nsec_uuid(prefix = '') time = Time.now str = time.to_i.to_s + time.nsec.to_s uuid str.to_i, prefix, rand_string end |
#rand_string(len = 4) ⇒ Object
27 28 29 |
# File 'lib/rails_com/helpers/uid_helper.rb', line 27 def rand_string(len = 4) len.times.map { ((0..9).to_a + ('A'..'Z').to_a).sample }.join end |
#sec_uuid(prefix = '') ⇒ Object
22 23 24 25 |
# File 'lib/rails_com/helpers/uid_helper.rb', line 22 def sec_uuid(prefix = '') time = Time.now uuid time.to_i, prefix, rand_string(2) end |
#uuid(int, prefix = '', suffix = '') ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/rails_com/helpers/uid_helper.rb', line 4 def uuid(int, prefix = '', suffix = '') str = int.to_s(36) str = str + suffix str = str.upcase.scan(/.{1,4}/).join('-') if prefix.present? str = prefix + '-' + str end str end |