ext/attribute_builder/attribute_builder.c in faml-0.3.4 vs ext/attribute_builder/attribute_builder.c in faml-0.3.5
- old
+ new
@@ -77,11 +77,11 @@
}
static int
normalize_data_i2(VALUE key, VALUE value, VALUE ptr)
{
- if (!(RB_TYPE_P(value, T_FALSE) || NIL_P(value))) {
+ if (RTEST(value)) {
struct normalize_data_i2_arg *arg = (struct normalize_data_i2_arg *)ptr;
VALUE k = rb_str_dup(arg->key);
k = rb_str_dup(arg->key);
rb_str_cat(k, "-", 1);
@@ -105,11 +105,11 @@
arg.normalized = normalized;
rb_hash_foreach(normalize_data(value), FOREACH_FUNC(normalize_data_i2), (VALUE)(&arg));
} else if (RB_TYPE_P(value, T_TRUE)) {
/* Keep Qtrue value */
rb_hash_aset(normalized, key, value);
- } else if (RB_TYPE_P(value, T_FALSE) || NIL_P(value)) {
+ } else if (!RTEST(value)) {
/* Delete falsey values */
} else {
rb_hash_aset(normalized, key, rb_convert_type(value, T_STRING, "String", "to_s"));
}
return ST_CONTINUE;
@@ -154,11 +154,11 @@
rb_hash_delete(hash, key);
data = normalize_data(value);
rb_hash_foreach(data, FOREACH_FUNC(put_data_attribute), hash);
} else if (RB_TYPE_P(value, T_TRUE)) {
/* Keep Qtrue value */
- } else if (RB_TYPE_P(value, T_FALSE) || NIL_P(value)) {
+ } else if (!RTEST(value)) {
rb_hash_delete(hash, key);
} else {
rb_hash_aset(hash, key, rb_convert_type(value, T_STRING, "String", "to_s"));
}
}
@@ -212,11 +212,13 @@
if (len != 0) {
long i;
VALUE ary = rb_ary_new_capa(len);
for (i = 0; i < len; i++) {
VALUE v = RARRAY_AREF(value, i);
- rb_ary_push(ary, rb_convert_type(v, T_STRING, "String", "to_s"));
+ if (RTEST(v)) {
+ rb_ary_push(ary, rb_convert_type(v, T_STRING, "String", "to_s"));
+ }
}
rb_funcall(ary, id_sort_bang, 0);
rb_funcall(ary, id_uniq_bang, 0);
put_attribute(buf, attr_quote, key, rb_ary_join(ary, rb_const_get(rb_mAttributeBuilder, id_space)));
}
@@ -228,10 +230,12 @@
if (len != 0) {
long i;
VALUE ary = rb_ary_new_capa(len);
for (i = 0; i < len; i++) {
VALUE v = RARRAY_AREF(value, i);
- rb_ary_push(ary, rb_convert_type(v, T_STRING, "String", "to_s"));
+ if (RTEST(v)) {
+ rb_ary_push(ary, rb_convert_type(v, T_STRING, "String", "to_s"));
+ }
}
put_attribute(buf, attr_quote, key, rb_ary_join(ary, rb_const_get(rb_mAttributeBuilder, id_underscore)));
}
} else if (RB_TYPE_P(value, T_TRUE)) {
if (is_html) {