Class: Ace::B36ts::Commands::EncodeCommand
- Inherits:
-
Object
- Object
- Ace::B36ts::Commands::EncodeCommand
- Defined in:
- lib/ace/b36ts/commands/encode_command.rb
Overview
Command to encode a timestamp to a compact ID
Class Method Summary collapse
-
.execute(time_string, options = {}) ⇒ Integer
Execute the encode command.
Class Method Details
.execute(time_string, options = {}) ⇒ Integer
Execute the encode command
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ace/b36ts/commands/encode_command.rb', line 25 def execute(time_string, = {}) time = parse_time(time_string) config = Molecules::ConfigResolver.resolve() display_config_summary("encode", config, ) # Validate mutually exclusive options if [:split] if [:format] raise ArgumentError, "--split and --format are mutually exclusive" end if [:count] raise ArgumentError, "--count and --split are mutually exclusive" end levels = parse_split_levels([:split]) output = Atoms::CompactIdEncoder.encode_split( time, levels: levels, year_zero: config[:year_zero], alphabet: config[:alphabet] ) if [:path_only] puts output[:path] elsif [:json] puts JSON.generate(output.transform_keys(&:to_s)) else display_split_output(levels, output) end else # Get format from options or config (default: :"2sec") # Normalize hyphens to underscores for CLI compatibility (e.g., high-8 -> high_8) format = [:format] format = format.to_s.tr("-", "_").to_sym if format format ||= config[:default_format]&.to_sym || :"2sec" if [:count] count = [:count].to_i ids = Atoms::CompactIdEncoder.encode_sequence( time, count: count, format: format, year_zero: config[:year_zero], alphabet: config[:alphabet] ) if [:json] puts JSON.generate(ids) else ids.each { |id| puts id } end else compact_id = Atoms::CompactIdEncoder.encode_with_format( time, format: format, year_zero: config[:year_zero], alphabet: config[:alphabet] ) puts compact_id end end 0 rescue ArgumentError => e warn "Error: #{e.}" raise rescue => e warn "Error encoding timestamp: #{e.}" warn e.backtrace.first(5).join("\n") if Ace::B36ts.debug? raise end |