clipsruby 0.0.39 → 0.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -0
  3. data/ext/clipsruby/clipsruby.c +95 -4
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80e4a680ddbc8bf4562a2b6995c645c0b5dd436ad36a1ee3445ba3fec7f13971
4
- data.tar.gz: 297c0e0c46cb3355acddde65530c2f424d0994691a25aa84fd030fd041631d59
3
+ metadata.gz: f9f5ef0ebbc5224f3c9ee6ab3bc3a025e543ec210aea37062d6eb7a8389424e6
4
+ data.tar.gz: d850a5303be6baca4514d9ed7de5061efacad449666fa56e80a15c7c29dd6e67
5
5
  SHA512:
6
- metadata.gz: c46acccb9d8b0edc1841f56ad046f8a36c06bcae3baf155b08ef3dff1b46acdf61ef82bcfc73ca5059796bfb87e767571f25f00fbc5a89bf359c992c38b3d32b
7
- data.tar.gz: 76c92b24f599195d9878907a09d6ef765aea158784fcb1847692e608220463de97932baa96bcf9c6c5bdd484eed4d14ed9fffc9c0a8370d634531528d445b95d
6
+ metadata.gz: 282703a59de83937e2afafb3bf66b315cc5bf0175d87ffb7eba3f3e34e831fbc7ebd8f764f64b430062d1cec587c3e4ce12248d5e6417b24b139d126be9a90d0
7
+ data.tar.gz: afaaf02eca5132f0092cec3665e0a4820b4e9517f04bda680f8c15cef85f8cdbcc2fd80a3dc752a103f220c11d270a26299b4a6c8121356394dc284df81842cf
data/README.md CHANGED
@@ -464,6 +464,19 @@ CLIPS::Environment::Instance.defclass(instance)
464
464
  instance.defclass
465
465
  ```
466
466
 
467
+ ### `CLIPS::Environment::Instance.to_h`
468
+ ### `CLIPS::Environment::Instance#to_h`
469
+
470
+ Returns a hash representing the instance slot names and their values.
471
+ Pass a `true` as an argument to get inhereted slots as well.
472
+
473
+ ```ruby
474
+ CLIPS::Environment::Instance.to_h(instance)
475
+ instance.to_h
476
+ CLIPS::Environment::Instance.to_h(instance, true)
477
+ instance.to_h(true)
478
+ ```
479
+
467
480
  ### `CLIPS::Environment::Defclass.name`
468
481
  ### `CLIPS::Environment::Defclass#name`
469
482
 
@@ -484,6 +497,19 @@ CLIPS::Environment::Defclass.pp_form(defclass)
484
497
  defclass.pp_form
485
498
  ```
486
499
 
500
+ ### `CLIPS::Environment::Defclass.slots`
501
+ ### `CLIPS::Environment::Defclass#slots`
502
+
503
+ Returns an array representing the slot names of a Defclass.
504
+ Pass `true` as an argument to get inherited slots, as well.
505
+
506
+ ```ruby
507
+ CLIPS::Environment::Defclass.slots(defclass)
508
+ defclass.slots
509
+ CLIPS::Environment::Defclass.slots(defclass, true)
510
+ defclass.slots(true)
511
+ ```
512
+
487
513
  ### `CLIPS::Environment::Defclass.defmodule_name`
488
514
  ### `CLIPS::Environment::Defclass#defmodule_name`
489
515
 
@@ -1266,10 +1266,6 @@ static VALUE clips_environment_defclass_subclasses(int argc, VALUE *argv, VALUE
1266
1266
 
1267
1267
  rb_scan_args(argc, argv, "01", &inherit);
1268
1268
 
1269
- if (NIL_P(inherit)) {
1270
- inherit = Qfalse;
1271
- }
1272
-
1273
1269
  TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
1274
1270
 
1275
1271
  ClassSubclasses(defclass, &value, RTEST(inherit));
@@ -1299,6 +1295,46 @@ static VALUE clips_environment_defclass_static_subclasses(int argc, VALUE *argv,
1299
1295
  return out;
1300
1296
  }
1301
1297
 
1298
+ static VALUE clips_environment_defclass_slots(int argc, VALUE *argv, VALUE rbDefclass)
1299
+ {
1300
+ VALUE rbEnvironment, inherit;
1301
+ Defclass *defclass;
1302
+ CLIPSValue value;
1303
+ VALUE out;
1304
+
1305
+ rbEnvironment = rb_iv_get(rbDefclass, "@environment");
1306
+
1307
+ rb_scan_args(argc, argv, "01", &inherit);
1308
+
1309
+ TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
1310
+
1311
+ ClassSlots(defclass, &value, RTEST(inherit));
1312
+
1313
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1314
+
1315
+ return out;
1316
+ }
1317
+
1318
+ static VALUE clips_environment_defclass_static_slots(int argc, VALUE *argv, VALUE klass)
1319
+ {
1320
+ VALUE rbEnvironment, inherit, rbDefclass;
1321
+ Defclass *defclass;
1322
+ CLIPSValue value;
1323
+ VALUE out;
1324
+
1325
+ rb_scan_args(argc, argv, "11", &rbDefclass, &inherit);
1326
+
1327
+ TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
1328
+
1329
+ rbEnvironment = rb_iv_get(rbDefclass, "@environment");
1330
+
1331
+ ClassSlots(defclass, &value, RTEST(inherit));
1332
+
1333
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1334
+
1335
+ return out;
1336
+ }
1337
+
1302
1338
  static VALUE clips_environment_run(int argc, VALUE *argv, VALUE environment) {
1303
1339
  VALUE integer;
1304
1340
  Environment *env;
@@ -1436,6 +1472,57 @@ static VALUE clips_environment_fact_static_to_h(VALUE self, VALUE rbFact)
1436
1472
  return clips_environment_fact_to_h(rbFact);
1437
1473
  }
1438
1474
 
1475
+ static VALUE clips_environment_instance_to_h(int argc, VALUE *argv, VALUE rbInstance)
1476
+ {
1477
+ VALUE rbEnvironment, inherit;
1478
+ Instance *instance;
1479
+ CLIPSValue key, value;
1480
+ rbEnvironment = rb_iv_get(rbInstance, "@environment");
1481
+
1482
+ TypedData_Get_Struct(rbInstance, Instance, &Instance_type, instance);
1483
+
1484
+ rb_scan_args(argc, argv, "01", &inherit);
1485
+
1486
+ ClassSlots(InstanceClass(instance), &key, RTEST(inherit));
1487
+
1488
+ VALUE hash = rb_hash_new();
1489
+ for (size_t i = 0; i < key.multifieldValue->length; i++)
1490
+ {
1491
+ VALUE innerValue;
1492
+ DirectGetSlot(instance, key.multifieldValue->contents[i].lexemeValue->contents, &value);
1493
+ CLIPSValue_to_VALUE(&value, &innerValue, &rbEnvironment);
1494
+ rb_hash_aset(hash, ID2SYM(rb_intern(key.multifieldValue->contents[i].lexemeValue->contents)), innerValue);
1495
+ }
1496
+
1497
+ return hash;
1498
+ }
1499
+
1500
+ static VALUE clips_environment_instance_static_to_h(int argc, VALUE *argv, VALUE klass)
1501
+ {
1502
+ VALUE rbInstance, rbEnvironment, inherit;
1503
+ Instance *instance;
1504
+ CLIPSValue key, value;
1505
+
1506
+ rb_scan_args(argc, argv, "11", &rbInstance, &inherit);
1507
+
1508
+ rbEnvironment = rb_iv_get(rbInstance, "@environment");
1509
+
1510
+ TypedData_Get_Struct(rbInstance, Instance, &Instance_type, instance);
1511
+
1512
+ ClassSlots(InstanceClass(instance), &key, RTEST(inherit));
1513
+
1514
+ VALUE hash = rb_hash_new();
1515
+ for (size_t i = 0; i < key.multifieldValue->length; i++)
1516
+ {
1517
+ VALUE innerValue;
1518
+ DirectGetSlot(instance, key.multifieldValue->contents[i].lexemeValue->contents, &value);
1519
+ CLIPSValue_to_VALUE(&value, &innerValue, &rbEnvironment);
1520
+ rb_hash_aset(hash, ID2SYM(rb_intern(key.multifieldValue->contents[i].lexemeValue->contents)), innerValue);
1521
+ }
1522
+
1523
+ return hash;
1524
+ }
1525
+
1439
1526
  static VALUE clips_environment_batch_star(VALUE self, VALUE path)
1440
1527
  {
1441
1528
  Environment *env;
@@ -4416,6 +4503,8 @@ void Init_clipsruby(void)
4416
4503
  rb_define_method(rbDefclass, "superclasses", clips_environment_defclass_superclasses, -1);
4417
4504
  rb_define_singleton_method(rbDefclass, "subclasses", clips_environment_defclass_static_subclasses, -1);
4418
4505
  rb_define_method(rbDefclass, "subclasses", clips_environment_defclass_subclasses, -1);
4506
+ rb_define_singleton_method(rbDefclass, "slots", clips_environment_defclass_static_slots, -1);
4507
+ rb_define_method(rbDefclass, "slots", clips_environment_defclass_slots, -1);
4419
4508
 
4420
4509
  VALUE rbInstance = rb_define_class_under(rbEnvironment, "Instance", rb_cObject);
4421
4510
  rb_define_alloc_func(rbInstance, instance_alloc);
@@ -4429,4 +4518,6 @@ void Init_clipsruby(void)
4429
4518
  rb_define_method(rbInstance, "name", clips_environment_instance_name, 0);
4430
4519
  rb_define_singleton_method(rbInstance, "pp_form", clips_environment_instance_static_pp_form, 1);
4431
4520
  rb_define_method(rbInstance, "pp_form", clips_environment_instance_pp_form, 0);
4521
+ rb_define_singleton_method(rbInstance, "to_h", clips_environment_instance_static_to_h, -1);
4522
+ rb_define_method(rbInstance, "to_h", clips_environment_instance_to_h, -1);
4432
4523
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clipsruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.39
4
+ version: 0.0.40
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Johnston