Sha256: ff313a09cd421912dde71b3e62da02ba09af16cfa602f5a19c343cb7fb366a3d

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

class String
  # Encode a string into decimal (string to hexadecimal then hexadecimal to decimal)
  # @param opts [Hash] optional parameters (see {String#to_hex} and {String#hex2dec})
  # @return [String] the decimal encoded string
  # @example
  #   'noraj'.to_dec # => "474316169578"
  def to_dec(opts = {})
    to_hex(opts).hex2dec(opts)
  end

  # Encode a string into decimal in place as described for {String#to_dec}.
  def to_dec!(opts = {})
    replace(to_dec(opts))
  end

  # Decode a decimal string (decimal to hexadecimal then hexadecimal to string)
  # @param opts [Hash] optional parameters (see {String#dec2hex} and {String#from_hex})
  # @return [String] the decimal decoded string
  # @example
  #   '1834615104613964215417'.from_dec # => "ctf-party"
  def from_dec(opts = {})
    dec2hex(opts).from_hex(opts)
  end

  # Decode a decimal string in place as described for {String#from_dec}.
  def from_dec!(opts = {})
    replace(from_dec(opts))
  end

  # Alias for {String#to_dec}.
  def str2dec(opts = {})
    to_dec(opts)
  end

  # Alias for {String#to_dec!}.
  def str2dec!(opts = {})
    replace(str2dec(opts))
  end

  # Alias for {String#from_dec}.
  def dec2str(opts = {})
    from_dec(opts)
  end

  # Alias for {String#from_dec!}.
  def dec2str!(opts = {})
    replace(dec2str(opts))
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ctf-party-3.0.0 lib/ctf_party/dec.rb