Class: Usamin::Value

Inherits:
Object
  • Object
show all
Defined in:
ext/usamin/usamin.cpp

Direct Known Subclasses

Array, Hash

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Boolean

Returns whether the value is equals to the other value.

Returns:

  • (Boolean)


627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
# File 'ext/usamin/usamin.cpp', line 627

static VALUE w_value_equal(const VALUE self, const VALUE other) {
    if (self == other)
        return Qtrue;
    UsaminValue *value_self = get_value(self);
    check_value(value_self);
    if (rb_obj_is_kind_of(other, rb_cUsaminValue)) {
        UsaminValue *value_other = get_value(other);
        check_value(value_other);
        return value_self->value->operator==(*value_other->value) ? Qtrue : Qfalse;
    } else if (value_self->value->IsArray() && RB_TYPE_P(other, T_ARRAY)) {
        if (value_self->value->Size() != RARRAY_LEN(other))
            return Qfalse;
        return rb_equal(other, eval_array(*value_self->value, value_self->root_document));
    } else if (value_self->value->IsObject() && RB_TYPE_P(other, T_HASH)) {
        if (value_self->value->MemberCount() != RHASH_SIZE(other))
            return Qfalse;
        return rb_equal(other, eval_object(*value_self->value, value_self->root_document));
    }
    return Qfalse;
}

#===(other) ⇒ Boolean

Returns whether the value is equals to the other value.

Returns:

  • (Boolean)


627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
# File 'ext/usamin/usamin.cpp', line 627

static VALUE w_value_equal(const VALUE self, const VALUE other) {
    if (self == other)
        return Qtrue;
    UsaminValue *value_self = get_value(self);
    check_value(value_self);
    if (rb_obj_is_kind_of(other, rb_cUsaminValue)) {
        UsaminValue *value_other = get_value(other);
        check_value(value_other);
        return value_self->value->operator==(*value_other->value) ? Qtrue : Qfalse;
    } else if (value_self->value->IsArray() && RB_TYPE_P(other, T_ARRAY)) {
        if (value_self->value->Size() != RARRAY_LEN(other))
            return Qfalse;
        return rb_equal(other, eval_array(*value_self->value, value_self->root_document));
    } else if (value_self->value->IsObject() && RB_TYPE_P(other, T_HASH)) {
        if (value_self->value->MemberCount() != RHASH_SIZE(other))
            return Qfalse;
        return rb_equal(other, eval_object(*value_self->value, value_self->root_document));
    }
    return Qfalse;
}

#array?Boolean

Returns whether the value is array.

Returns:

  • (Boolean)


651
652
653
654
655
# File 'ext/usamin/usamin.cpp', line 651

static VALUE w_value_isarray(const VALUE self) {
    UsaminValue *value = get_value(self);
    check_value(value);
    return value->value->IsArray() ? Qtrue : Qfalse;
}

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


696
697
698
699
700
701
702
703
704
705
706
# File 'ext/usamin/usamin.cpp', line 696

static VALUE w_value_eql(const VALUE self, const VALUE other) {
    if (self == other)
        return Qtrue;
    if (!rb_obj_is_kind_of(other, rb_cUsaminValue))
        return Qfalse;
    UsaminValue *value_self = get_value(self);
    UsaminValue *value_other = get_value(other);
    check_value(value_self);
    check_value(value_other);
    return eql_value(*value_self->value, *value_other->value) ? Qtrue : Qfalse;
}

#evalObject

Convert to Ruby data structures.

Returns:

  • (Object)


671
672
673
674
675
676
677
678
679
680
# File 'ext/usamin/usamin.cpp', line 671

static VALUE w_value_eval(const VALUE self) {
    UsaminValue *value = get_value(self);
    check_value(value);
    if (value->value->IsObject())
        return eval_object(*(value->value), value->root_document);
    else if (value->value->IsArray())
        return eval_array(*(value->value), value->root_document);
    else
        return Qnil;
}

#eval_rObject

Convert to Ruby data structures recursively.

Returns:

  • (Object)


687
688
689
690
691
# File 'ext/usamin/usamin.cpp', line 687

static VALUE w_value_eval_r(const VALUE self) {
    UsaminValue *value = get_value(self);
    check_value(value);
    return eval_r(*(value->value));
}

#frozen?Boolean

Always true.

Returns:

  • (Boolean)


711
712
713
# File 'ext/usamin/usamin.cpp', line 711

static VALUE w_value_isfrozen(const VALUE self) {
    return Qtrue;
}

#hashInteger

Returns:

  • (Integer)


718
719
720
721
722
# File 'ext/usamin/usamin.cpp', line 718

static VALUE w_value_hash(const VALUE self) {
    UsaminValue *value = get_value(self);
    check_value(value);
    return ST2FIX(hash_value(*value->value));
}

#hash?Boolean

Returns whether the value is object.

Returns:

  • (Boolean)


660
661
662
663
664
# File 'ext/usamin/usamin.cpp', line 660

static VALUE w_value_isobject(const VALUE self) {
    UsaminValue *value = get_value(self);
    check_value(value);
    return value->value->IsObject() ? Qtrue : Qfalse;
}

#object?Boolean

Returns whether the value is object.

Returns:

  • (Boolean)


660
661
662
663
664
# File 'ext/usamin/usamin.cpp', line 660

static VALUE w_value_isobject(const VALUE self) {
    UsaminValue *value = get_value(self);
    check_value(value);
    return value->value->IsObject() ? Qtrue : Qfalse;
}

#rootUsaminValue

Returns root object.

Returns:

  • (UsaminValue)


729
730
731
732
733
# File 'ext/usamin/usamin.cpp', line 729

static VALUE w_value_root(const VALUE self) {
    UsaminValue *value = get_value(self);
    check_value(value);
    return value->root_document;
}