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)


497
498
499
500
501
# File 'ext/usamin/usamin.cpp', line 497

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)


517
518
519
520
521
522
523
524
525
526
# File 'ext/usamin/usamin.cpp', line 517

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

#eval_rObject

Convert to Ruby data structures recursively.

Returns:

  • (Object)


533
534
535
536
537
# File 'ext/usamin/usamin.cpp', line 533

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)


542
543
544
# File 'ext/usamin/usamin.cpp', line 542

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

#hash?Boolean

Returns whether the value is object.

Returns:

  • (Boolean)


506
507
508
509
510
# File 'ext/usamin/usamin.cpp', line 506

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)


551
552
553
554
555
556
557
558
# File 'ext/usamin/usamin.cpp', line 551

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)


565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
# File 'ext/usamin/usamin.cpp', line 565

static VALUE w_value_marshal_load(const VALUE self, const 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)


506
507
508
509
510
# File 'ext/usamin/usamin.cpp', line 506

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