module Elixir::Base

Constants

LOWERCASE
UPPERCASE

Public Instance Methods

decode16(string, char_case: :upper) click to toggle source
# File lib/elixir/base.rb, line 11
def decode16 string, char_case: :upper
  case char_case
  when :upper
    return :error if string =~ LOWERCASE
  when :lower
    return :error if string =~ UPPERCASE
  end

  [:ok, [string].pack('H*')] rescue :error
end
decode16!(string, char_case: :upper) click to toggle source
# File lib/elixir/base.rb, line 22
def decode16! string, char_case: :upper
  case char_case
  when :upper
    raise ArgumentError if string =~ LOWERCASE
  when :lower
    raise ArgumentError if string =~ UPPERCASE
  end

  [string].pack 'H*'
end
decode32(string, char_case: :upper) click to toggle source
# File lib/elixir/base.rb, line 33
def decode32 string, char_case: :upper
  case char_case
  when :upper
    return :error if string =~ LOWERCASE
  when :lower
    return :error if string =~ UPPERCASE
  end

  [:ok, Base32.decode(string)] rescue :error
end
decode32!(string, char_case: :upper) click to toggle source
# File lib/elixir/base.rb, line 44
def decode32! string, char_case: :upper
  case char_case
  when :upper
    raise ArgumentError if string =~ LOWERCASE
  when :lower
    raise ArgumentError if string =~ UPPERCASE
  end

  Base32.decode string
end
decode64(string) click to toggle source
# File lib/elixir/base.rb, line 55
def decode64 string
  [:ok, Base64.strict_decode64(string)] rescue :error
end
decode64!(string) click to toggle source
# File lib/elixir/base.rb, line 59
def decode64! string
  Base64.strict_decode64 string
end
encode16(data, char_case: :upper) click to toggle source
# File lib/elixir/base.rb, line 63
def encode16 data, char_case: :upper
  encoded = data.unpack('H*').first

  char_case == :upper ? encoded.upcase : encoded
end
encode32(data, char_case: :upper) click to toggle source
# File lib/elixir/base.rb, line 69
def encode32 data, char_case: :upper
  encoded = Base32.encode data

  char_case == :upper ? encoded.upcase : encoded
end
encode64(data) click to toggle source
# File lib/elixir/base.rb, line 75
def encode64 data
  Base64.strict_encode64(data)
end
hex_decode32(string, char_case: :upper) click to toggle source
# File lib/elixir/base.rb, line 83
def hex_decode32 string, char_case: :upper
  # TODO
end
hex_decode32!(string, char_case: :upper) click to toggle source
# File lib/elixir/base.rb, line 87
def hex_decode32! string, char_case: :upper
  # TODO
end
hex_encode32(string, char_case: :upper) click to toggle source
# File lib/elixir/base.rb, line 79
def hex_encode32 string, char_case: :upper
  # TODO
end
url_decode64(string) click to toggle source
# File lib/elixir/base.rb, line 91
def url_decode64 string
  # TODO
end
url_decode64!(string) click to toggle source
# File lib/elixir/base.rb, line 95
def url_decode64! string
  # TODO
end