Class: Ace::B36ts::Commands::DecodeCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/b36ts/commands/decode_command.rb

Overview

Command to decode a compact ID to a timestamp

Examples:

Usage

DecodeCommand.execute("i50jj3")
# => "2025-01-06 12:30:00 UTC"

Class Method Summary collapse

Class Method Details

.execute(compact_id, options = {}) ⇒ Integer

Execute the decode command

Parameters:

  • compact_id (String)

    2-8 character compact ID to decode

  • options (Hash) (defaults to: {})

    Command options

Options Hash (options):

  • :year_zero (Integer)

    Override year_zero config

  • :format (String)

    Output format (:iso, :timestamp, :readable)

  • :quiet (Boolean)

    Suppress config summary output

Returns:

  • (Integer)

    Exit code (0 for success, 1 for error)



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ace/b36ts/commands/decode_command.rb', line 22

def execute(compact_id, options = {})
  config = Molecules::ConfigResolver.resolve(options)

  display_config_summary("decode", config, options)

  # Use split decoding for hierarchical paths, otherwise auto-detect
  time = if options[:split] || contains_split_separator?(compact_id)
    Atoms::CompactIdEncoder.decode_path(
      compact_id,
      year_zero: config[:year_zero],
      alphabet: config[:alphabet]
    )
  else
    Atoms::CompactIdEncoder.decode_auto(
      compact_id,
      year_zero: config[:year_zero],
      alphabet: config[:alphabet]
    )
  end

  output = format_output(time, options[:format])
  puts output
  0
rescue ArgumentError => e
  warn "Error: #{e.message}"
  raise
rescue => e
  warn "Error decoding compact ID: #{e.message}"
  warn e.backtrace.first(5).join("\n") if Ace::B36ts.debug?
  raise
end