Class: Ace::Idea::Atoms::IdeaIdFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/idea/atoms/idea_id_formatter.rb

Overview

Generates and formats raw b36ts IDs for ideas. Ideas use raw 6-char b36ts IDs without type markers. Example: “8ppq7w” (no “.t.” or “.i.” separator)

Class Method Summary collapse

Class Method Details

.decode_time(id) ⇒ Time

Decode a raw idea ID to the time it was created

Parameters:

  • id (String)

    Raw 6-char b36ts ID

Returns:

  • (Time)

    The time encoded in the ID



31
32
33
# File 'lib/ace/idea/atoms/idea_id_formatter.rb', line 31

def self.decode_time(id)
  Ace::B36ts.decode(id)
end

.generate(time = Time.now.utc) ⇒ String

Generate a new raw 6-char b36ts ID for an idea

Parameters:

  • time (Time) (defaults to: Time.now.utc)

    Time to encode (default: now)

Returns:

  • (String)

    6-character raw b36ts ID (e.g., “8ppq7w”)



15
16
17
# File 'lib/ace/idea/atoms/idea_id_formatter.rb', line 15

def self.generate(time = Time.now.utc)
  Ace::B36ts.encode(time, format: :"2sec")
end

.valid?(id) ⇒ Boolean

Validate that a string is a valid raw idea ID

Parameters:

  • id (String)

    The ID to validate

Returns:

  • (Boolean)

    True if valid 6-char b36ts ID



22
23
24
25
26
# File 'lib/ace/idea/atoms/idea_id_formatter.rb', line 22

def self.valid?(id)
  return false if id.nil? || id.empty?

  Ace::B36ts.valid?(id)
end