Class: Cornflake

Inherits:
Object
  • Object
show all
Defined in:
lib/cornflake.rb,
lib/cornflake/mac.rb,
ext/cornflake/cornflake.rb.c

Defined Under Namespace

Modules: Base62, MacAddress

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.macaddr=(rb_mac) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'ext/cornflake/cornflake.rb.c', line 72

static VALUE
rb_cornflake_set_mac(VALUE klass, VALUE rb_mac)
{
	Check_Type(rb_mac, T_STRING);

	if (cornflake_set_mac(StringValueCStr(rb_mac)) < 0)
		rb_raise(rb_eTypeError, "Invalid MAC Address: %s", StringValueCStr(rb_mac));

	return Qnil;
}

.new(rb_path) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'ext/cornflake/cornflake.rb.c', line 12

static VALUE
rb_cornflake__new(VALUE klass, VALUE rb_path)
{
	struct cornflake *corn;

	Check_Type(rb_path, T_STRING);

	corn = cornflake_new(StringValueCStr(rb_path));
	if (!corn)
		rb_raise(rb_eRuntimeError, "Failed to open Cornflake state at %s",
			StringValueCStr(rb_path));

	return Data_Wrap_Struct(klass, NULL, rb_cornflake__free, corn);
}

Instance Method Details

#base62Object



20
21
22
# File 'lib/cornflake.rb', line 20

def base62
  Base62.encode(self.hex.to_i(16))
end

#hexObject



60
61
62
63
64
65
66
67
68
69
70
# File 'ext/cornflake/cornflake.rb.c', line 60

static VALUE
rb_cornflake_gen_hex(VALUE self)
{
	char hex_uid[33];
	struct cornflake *corn;

	Data_Get_Struct(self, struct cornflake, corn);
	rb_cornflake_check(cornflake_gen_hex(hex_uid, sizeof(hex_uid), corn));

	return rb_str_new2(hex_uid);
}

#uidObject



48
49
50
51
52
53
54
55
56
57
58
# File 'ext/cornflake/cornflake.rb.c', line 48

static VALUE
rb_cornflake_gen(VALUE self)
{
	uint8_t uid[16];
	struct cornflake *corn;

	Data_Get_Struct(self, struct cornflake, corn);
	rb_cornflake_check(cornflake_gen(uid, corn));

	return rb_str_new((char *)uid, 16);
}