Module: Macserialrb

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

Constant Summary collapse

VERSION =
"0.3.0"

Class Method Summary collapse

Class Method Details

.generate(*args) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'ext/macserialrb/macserialrb.c', line 57

static VALUE
generate(int argc, VALUE *argv, VALUE self)
{
  VALUE model = Qnil;
  VALUE obj   = rb_hash_new();

  for (int i = 0; i < argc; ++i)
  {
    model = rb_hash_aref(argv[i], rb_to_symbol( rb_str_new2("model") ));
  }

  if (NIL_P(model))
  {
    rb_raise(rb_eTypeError, "model is required!");
    exit(0);
  }

  SERIALINFO info = get_serialinfo(model);

  if (get_serial(&info)) {
    char mlb[MLB_MAX_SIZE];
    char ssn[MLB_MAX_SIZE];

    get_mlb(&info, mlb, MLB_MAX_SIZE);
    sprintf(ssn, "%s%s%s%s%s", info.country, info.year, info.week, info.line, info.model);

    VALUE productName = rb_str_new2(ApplePlatformData[info.modelIndex].productName);
    VALUE SystemSerialNumber = rb_str_new2(ssn);
    VALUE MLB = rb_str_new2(mlb);

    rb_hash_aset(obj, rb_to_symbol( rb_str_new2("productName") ), productName);
    rb_hash_aset(obj, rb_to_symbol( rb_str_new2("SystemSerialNumber") ), SystemSerialNumber);
    rb_hash_aset(obj, rb_to_symbol( rb_str_new2("MLB") ), MLB);
  }

  return obj;
}

.modelsObject



23
24
25
26
27
28
29
30
31
32
# File 'ext/macserialrb/macserialrb.c', line 23

static VALUE
models()
{
  VALUE obj = rb_ary_new_capa(APPLE_MODEL_MAX);

  for (int32_t idx = 0; idx < APPLE_MODEL_MAX; idx++) {
    rb_ary_push(obj, rb_str_new_cstr(ApplePlatformData[idx].productName));
  }
  return obj;
}