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

#array?Boolean

Returns whether the value is array.

Returns:

  • (Boolean)


459
460
461
462
463
# File 'ext/usamin/usamin.cpp', line 459

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

#evalObject

Convert to Ruby data structures.

Returns:

  • (Object)


479
480
481
482
483
484
485
486
487
488
# File 'ext/usamin/usamin.cpp', line 479

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));
    else if (value->value->IsArray())
        return eval_array(*(value->value));
    else
        return Qnil;
}

#eval_rObject

Convert to Ruby data structures recursively.

Returns:

  • (Object)


495
496
497
498
499
# File 'ext/usamin/usamin.cpp', line 495

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)


504
505
506
# File 'ext/usamin/usamin.cpp', line 504

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

#hash?Boolean

Returns whether the value is object.

Returns:

  • (Boolean)


468
469
470
471
472
# File 'ext/usamin/usamin.cpp', line 468

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

#marshal_dumpString

Dumps data in JSON.

Returns:

  • (String)


513
514
515
516
517
518
519
520
# File 'ext/usamin/usamin.cpp', line 513

static VALUE w_value_marshal_dump(const VALUE self) {
    UsaminValue *value = get_value(self);
    check_value(value);
    rapidjson::StringBuffer buf;
    rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
    write_value(writer, *value->value);
    return rb_str_new(buf.GetString(), buf.GetSize());
}

#marshal_load(source) ⇒ self

Loads marshal data.

Returns:

  • (self)


527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# File 'ext/usamin/usamin.cpp', line 527

static VALUE w_value_marshal_load(const VALUE self, VALUE source) {
    Check_Type(source, T_STRING);
    rapidjson::Document *doc = new rapidjson::Document();
    rapidjson::ParseResult result = doc->Parse<rapidjson::kParseFullPrecisionFlag | rapidjson::kParseNanAndInfFlag>(RSTRING_PTR(source), RSTRING_LEN(source));
    if (!result) {
        delete doc;
        rb_raise(rb_eParserError, "%s Offset: %lu", GetParseError_En(result.Code()), result.Offset());
    }
    if (doc->IsObject() || doc->IsArray()) {
        set_value(self, new UsaminValue(doc, true));
        return self;
    }
    auto type = doc->GetType();
    delete doc;
    rb_raise(rb_eUsaminError, "Invalid Value Type for marshal_load: %d", type);
    return Qnil;
}

#object?Boolean

Returns whether the value is object.

Returns:

  • (Boolean)


468
469
470
471
472
# File 'ext/usamin/usamin.cpp', line 468

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