Sha256: aef3dd3376d2703b6546e0b1c27950b570923d5b2761ac4b42433117db41ba3f

Contents?: true

Size: 561 Bytes

Versions: 1

Compression:

Stored size: 561 Bytes

Contents

require "comfan/version"

module Comfan
  extend self

  def api_id(input_id)
    return input_id if input_id.nil? || input_id.length != 15
    suffix = ""

    3.times do |i|
      flags = 0
      5.times do |j|
        c = input_id[i * 5 + j]
        if c.upcase == c && c >= "A" && c <= "Z"
          flags = flags + (1 << j)
        end
      end
      suffix += "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"[flags]
    end
    input_id + suffix
  end

  def ui_id(input_id)
    return input_id if input_id.nil? || input_id.length != 18

    input_id[0..-4]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comfan-0.1.2 lib/comfan.rb