Class: Kibuvits_krl171bt4_GUID_generator

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/kibuvits_ruby_library_krl171bt4_.rb

Overview

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeKibuvits_krl171bt4_GUID_generator

Returns a new instance of Kibuvits_krl171bt4_GUID_generator.



140
141
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 140

def initialize
end

Class Method Details

.generate_GUIDObject

generate_GUID



234
235
236
237
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 234

def Kibuvits_krl171bt4_GUID_generator.generate_GUID
   s_guid=Kibuvits_krl171bt4_GUID_generator.instance.generate_GUID
   return s_guid
end

.selftestObject



240
241
242
243
244
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 240

def Kibuvits_krl171bt4_GUID_generator.selftest
   ar_msgs=Array.new
   kibuvits_krl171bt4_testeval binding(), "Kibuvits_krl171bt4_GUID_generator.generate_GUID"
   return ar_msgs
end

Instance Method Details

#generate_GUIDObject

Returns a string



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 205

def generate_GUID
   t=Time.now
   #        3 characters    1 character
   s_guid=t.year.to_s(16)+t.month.to_s(16) # 3 digit year, 1 digit month
   s_guid=s_guid+"0" if t.day<16
   s_guid=s_guid+t.day.to_s(16)
   s_guid=s_guid+"0" if t.hour<16 # 60.to_s(16).length<=2
   s_guid=s_guid+t.hour.to_s(16)
   s_guid=s_guid+"0" if t.min<16
   s_guid=s_guid+t.min.to_s(16)
   s_guid=s_guid+"0" if t.sec<16
   s_guid=s_guid+t.sec.to_s(16)
   s_guid=s_guid+((t.usec*1.0)/1000).round.to_s(16)
   while s_guid.length<36 do
      s_guid<<rand(100000000).to_s(16)
   end # loop
   # The reason, why it is beneficial to place the
   # timestamp part of the GUID to the end of the GUID is
   # that the randomly generated digits have a
   # bigger variance than the timestamp digits have.
   # If the GUIDs are used as ID-s or file names,
   # then the bigger the variance of first digits of the string,
   # the less amount of digits search algorithms have to study to
   # exclude majority of irrelevant records from further inspection.
   s_1=s_guid[0..35].reverse
   s_guid=convert_2_GUID_format(s_1)
   return s_guid
end