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.
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;
}
|
#eval ⇒ Object
Convert to Ruby data structures.
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_r ⇒ Object
Convert to Ruby data structures recursively.
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.
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.
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_dump ⇒ String
Dumps data in JSON.
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.
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.
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;
}
|