Class: Usamin::Value
- Inherits:
-
Object
- Object
- Usamin::Value
- Defined in:
- ext/usamin/usamin.cpp
Instance Method Summary collapse
-
#array? ⇒ Boolean
Returns whether the value is array.
-
#eval ⇒ Object
Convert to Ruby data structures.
-
#eval_r ⇒ Object
Convert to Ruby data structures recursively.
-
#frozen? ⇒ Boolean
Always true.
-
#hash? ⇒ Boolean
Returns whether the value is object.
-
#marshal_dump ⇒ String
Dumps data in JSON.
-
#marshal_load(source) ⇒ self
Loads marshal data.
-
#object? ⇒ Boolean
Returns whether the value is object.
Instance Method Details
#array? ⇒ Boolean
Returns whether the value is array.
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;
}
|
#eval ⇒ Object
Convert to Ruby data structures.
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_r ⇒ Object
Convert to Ruby data structures recursively.
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.
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.
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_dump ⇒ String
Dumps data in JSON.
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.
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.
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;
}
|