data_matrix 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c4f71b784d1454fdc371e8565479b0404f5f4bc
4
- data.tar.gz: e385701eaf8326b9a4fce2e04eb3414341643925
3
+ metadata.gz: 61a44ce56b60d36d4d999cddbc067ea276f0ebc6
4
+ data.tar.gz: 78b28d2f4e8ea39fca5a029f3d6739368b1d10b0
5
5
  SHA512:
6
- metadata.gz: 38213745494b7b57f1dfb489c778c1ff2c18274e88cbd0919337c158ec13a91101522f4f7a7f20b5d22c134da399aebd8d1967e37996ebed0114f94c2790d8a7
7
- data.tar.gz: aee294d8edf2b0db6eee86d41ee79c4855a1f8cd7edcddd4fdbe6f3c0e73c9b7830534635edaac3a3cebdfd20e2bbef3d1076013952a0b44b727efda5790a0c4
6
+ metadata.gz: 589f593ad79a1ee7be3c3755de39edf8fd9f653101a9b36060d273aac0e0f7a4f02248a017d69fa0ed677c42278cf8457eaa0923870ea94daedf4a9e039d152c
7
+ data.tar.gz: 9fc7c90ec08521995f7e5a2005bdf7804ee3cba84ec1fce3ab5e9422144f7330117e04a9e438ebf75e6a29835e255bbfd8a6005f9c93f25ed01a3b7cc1e5fb43
@@ -18,7 +18,6 @@ semacode_t* encode_string(semacode_t* semacode, const char *message) {
18
18
  free(semacode->encoding);
19
19
  }
20
20
 
21
- bzero(semacode, sizeof(semacode_t));
22
21
  fixed_message = strdup(message);
23
22
  strcat(fixed_message, " ");
24
23
 
@@ -35,13 +34,7 @@ semacode_t* encode_string(semacode_t* semacode, const char *message) {
35
34
  }
36
35
 
37
36
  static void data_matrix_mark(semacode_t* semacode) {
38
- semacode->width = 0;
39
- semacode->height = 0;
40
- semacode->raw_encoded_length = 0;
41
- semacode->symbol_capacity = 0;
42
- semacode->ecc_bytes = 0;
43
- semacode->encoding = NULL;
44
- semacode->data = NULL;
37
+ bzero(semacode, sizeof(semacode_t));
45
38
  }
46
39
 
47
40
  static void data_matrix_free(semacode_t* semacode) {
@@ -50,7 +43,6 @@ static void data_matrix_free(semacode_t* semacode) {
50
43
  free(semacode->encoding);
51
44
  free(semacode->data);
52
45
  }
53
- bzero(semacode, sizeof(semacode));
54
46
  free(semacode);
55
47
  }
56
48
  }
@@ -77,12 +69,17 @@ static VALUE data_matrix_grid(semacode_t *semacode) {
77
69
  }
78
70
 
79
71
  static VALUE data_matrix_allocate(VALUE klass) {
80
- semacode_t *semacode;
81
- return Data_Make_Struct(klass, semacode_t, data_matrix_mark, data_matrix_free, semacode);
72
+ semacode_t *semacode = malloc(sizeof(semacode_t));
73
+ bzero(semacode, sizeof(semacode_t));
74
+ return Data_Wrap_Struct(klass, data_matrix_mark, data_matrix_free, semacode);
82
75
  }
83
76
 
84
77
  static VALUE data_matrix_init(VALUE self, VALUE message) {
85
78
  semacode_t *semacode;
79
+
80
+ if (!rb_respond_to(message, rb_intern("to_s")))
81
+ rb_raise(rb_eArgError, "target must respond to 'to_s'");
82
+
86
83
  Data_Get_Struct(self, semacode_t, semacode);
87
84
 
88
85
  encode_string(semacode, StringValuePtr(message));
@@ -93,7 +90,7 @@ static VALUE data_matrix_init(VALUE self, VALUE message) {
93
90
  static VALUE data_matrix_encode(VALUE self, VALUE encoding) {
94
91
  semacode_t *semacode;
95
92
 
96
- if (!rb_respond_to(encoding, rb_intern ("to_s")))
93
+ if (!rb_respond_to(encoding, rb_intern("to_s")))
97
94
  rb_raise(rb_eRuntimeError, "target must respond to 'to_s'");
98
95
 
99
96
  Data_Get_Struct(self, semacode_t, semacode);
@@ -193,7 +190,7 @@ void Init_data_matrix(void) {
193
190
 
194
191
  rb_define_alloc_func(rb_cEncoder, data_matrix_allocate);
195
192
 
196
- rb_define_method(rb_cEncoder, "encode_string", data_matrix_init, 1);
193
+ rb_define_method(rb_cEncoder, "initialize", data_matrix_init, 1);
197
194
  rb_define_method(rb_cEncoder, "encode", data_matrix_encode, 1);
198
195
  rb_define_method(rb_cEncoder, "data", data_matrix_data, 0);
199
196
  rb_define_method(rb_cEncoder, "encoding", data_matrix_encoded, 0);
@@ -6,9 +6,10 @@ module DataMatrix
6
6
  alias to_str to_s
7
7
  alias to_a data
8
8
 
9
- def initialize(value)
10
- raise ArgumentError, 'Value must be convertible to string' unless value.respond_to?(:to_s)
11
- encode_string(value.to_s)
9
+ class << self
10
+ def encode_string(value)
11
+ new(value)
12
+ end
12
13
  end
13
14
 
14
15
  def length
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module DataMatrix
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_matrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikhail Bortnyk
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-03-15 00:00:00.000000000 Z
12
+ date: 2017-05-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler