Module: YAB62

Defined in:
lib/yab62/version.rb,
ext/yab62/yab62.c

Constant Summary collapse

VERSION =
"1.0.1"

Class Method Summary collapse

Class Method Details

.decode62(arg) ⇒ Object



101
102
103
104
105
# File 'ext/yab62/yab62.c', line 101

static VALUE alphadecimal_base62_decode(VALUE self, VALUE arg) {
  char* str = StringValuePtr(arg);
  long val = base62_decode(str);
  return ULL2NUM(val);
}

.encode62(arg) ⇒ Object

Ruby code starts here



91
92
93
94
95
96
97
98
99
# File 'ext/yab62/yab62.c', line 91

static VALUE alphadecimal_base62_encode(VALUE self, VALUE arg) {
  long val = NUM2LONG(arg);
  if (val < 0)
    rb_raise(rb_eRangeError, "Number must be greater than or equal to 0");

  char str[12];
  base62_encode(val, str, 12);
  return rb_str_new2(str);
}