Class: QRTools::Encoder

Inherits:
Object
  • Object
show all
Defined in:
lib/qrtools/encoder.rb,
ext/qrtools/qrtools_encoder.c

Constant Summary collapse

NULL =

Terminator (NUL character)

-1 # Terminator (NUL character)
NUMERIC =

Numeric mode

0
ALPHA_NUM =

Alphabet-numeric mode

1
EIGHT_BIT =

8-bit data mode

2
KANJI =

Kanji (shift-jis) mode

3
L =

Error Correction L (Lowest)

0
M =

Error Correction M

1
Q =

Error Corretion Q

2
H =

Error Corretion H (highest)

3

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.encode(*args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'ext/qrtools/qrtools_encoder.c', line 3

static VALUE encode(int argc, VALUE *argv, VALUE klass)
{
  //extern QRcode *QRcode_encodeString(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive);
  VALUE string, options;
  if(rb_scan_args(argc, argv, "11", &string, &options) == 1) {
    options = rb_hash_new();
  }

  VALUE version = rb_hash_aref(options, ID2SYM(rb_intern("version")));
  VALUE level = rb_hash_aref(options, ID2SYM(rb_intern("error_correction")));
  VALUE case_sensitive = rb_hash_aref(options, ID2SYM(rb_intern("case_sensitive")));
  VALUE mode = rb_hash_aref(options, ID2SYM(rb_intern("mode")));

  int cs = 0;
  if(RTEST(case_sensitive) && case_sensitive == Qtrue) cs = 1;

  QRcode * code = QRcode_encodeString(
      StringValuePtr(string),
      RTEST(version) ? NUM2INT(version) : 0,
      RTEST(level) ? NUM2INT(level) : 0,
      RTEST(mode) ? NUM2INT(mode) : 2,
      cs
  );
  if(NULL == code) rb_raise(rb_eRuntimeError, "could not create code");
  return Data_Wrap_Struct(cQRToolsQRCode, NULL, QRcode_free, code);
}

Instance Method Details

#versionObject



30
31
32
33
34
35
# File 'ext/qrtools/qrtools_encoder.c', line 30

static VALUE version(VALUE self)
{
  QRinput * input;
  Data_Get_Struct(self, QRinput, input);
  return INT2NUM(QRinput_getVersion(input));
}

#version=(version) ⇒ Object



37
38
39
40
41
42
43
44
# File 'ext/qrtools/qrtools_encoder.c', line 37

static VALUE set_version(VALUE self, VALUE version)
{
  QRinput * input;
  Data_Get_Struct(self, QRinput, input);
  QRinput_setVersion(input, NUM2INT(version));

  return self;
}