Class OpenWFE::KotobaWfidGenerator
In: lib/openwfe/expool/wfidgen.rb
Parent: DefaultWfidGenerator

This extension of DefaultWfidGenerator produces ids like "20070318-jonowoguya" or "20071224-jesoshimoha" that are a bit easier to grasp than full integer wfids.

Now relying on the ‘rufus-mnemo’ gem.

Methods

Public Class methods

[Source]

     # File lib/openwfe/expool/wfidgen.rb, line 248
248:         def self.from_time (t)
249: 
250:             to_string(t.to_f * 10 * 1000).to_i
251:         end

This method is called by OpenWFE::split_wfid() when it has detected a wfid following the ‘kotoba’ scheme. Returns the ‘kotoba’ wfid split into its syllables

[Source]

     # File lib/openwfe/expool/wfidgen.rb, line 220
220:         def self.split_wfid (wfid)
221: 
222:             Rufus::Mnemo::split(wfid[9..-1])
223:         end

That‘s here that the numeric wfid gets turned into a ‘kotoba’. A static method easily accessible by any.

[Source]

     # File lib/openwfe/expool/wfidgen.rb, line 204
204:         def self.to_string (numeric_id)
205: 
206:             i = numeric_id % (10 * 1000 * 60 * 60 * 24)
207:             t = Time.now.gmtime
208: 
209:             s = sprintf "%4d%02d%02d", t.year, t.month, t.day
210:             s << "-"
211:             s << Rufus::Mnemo::from_integer(i)
212:             s
213:         end

Turns a KotobaWfidGenerator produced wfid into a UTC date.

[Source]

     # File lib/openwfe/expool/wfidgen.rb, line 228
228:         def self.to_time (wfid)
229: 
230:             year = wfid[0, 4]
231:             month = wfid[4, 2]
232:             day = wfid[6, 2]
233: 
234:             s = wfid[9..-1]
235: 
236:             i = Rufus::Mnemo::to_integer(s)
237: 
238:             hour = (i / (10000 * 60 * 60)) % 24
239:             min = (i / (10000 * 60)) % 60
240:             sec = (i / 10000) % 60
241:             usec = (i * 100) % 1000000
242: 
243:             #puts "hms #{hour} #{min} #{sec} #{usec}"
244: 
245:             Time.utc(year, month, day, hour, min, sec, usec)
246:         end

Public Instance methods

Overrides the to_string() method of the DefaultWfidGenerator,

[Source]

     # File lib/openwfe/expool/wfidgen.rb, line 195
195:         def to_string (numeric_id)
196: 
197:             self.class.to_string(numeric_id)
198:         end

[Validate]