clipsruby 0.0.18 → 0.0.19

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 +97 -0
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33891d80ffdc546c56d9cfa73c522f9b53ebbe666f21da00239aebb184d1f424
4
- data.tar.gz: 10fae8b4acc60835743bbb301e936c21ed96a989fdc90d8119313494d406d3f1
3
+ metadata.gz: c06b3f9f05fc87da93b208ba7f77de5097f964a689e2a9d1cdc8d8e0d992c826
4
+ data.tar.gz: 151dd0c82d9213a7ce971935513cbd9c16ab76bc08b123c7321ecfe1fa5cf985
5
5
  SHA512:
6
- metadata.gz: b212ee718009840bd627f666ec1cb16ea1732386dc3a3dc8bd12f39aac2ae24c9ccf207a0247e37298ba1411518c44bfb450cec70568c4db141bc0da6ddb8e28
7
- data.tar.gz: ebc27064ab0edd3113683de4d6b75889b12ed4b2522b3d1e2de7598223526caf67dba7199c3520d22c712bb5e821981d99904b0ba228e9ded9b5cdfd5417d678
6
+ metadata.gz: d545c65c3587d29c3b0a4fa12ffa6ecc030c242c472bcb5eb607014de3a03bd465defbe34fa4753e2594e55b2f5685f4111d8ab1c38b2467a9fa38256e31458c
7
+ data.tar.gz: c49a1fa673d5f680ee9c6fc2a38ed4dd4708cc996b8624f620e97d5161a5f533077542d7b0a4e788c4a6a4b9be49ad1bbf4307e769fde4cc537dde92905b8b86
data/README.md CHANGED
@@ -168,6 +168,22 @@ CLIPS::Environment.find_fact(env, "(?f my_deftemplate)", "(eq ?f:b \"asdf\")")
168
168
  env.find_fact("(?f my_deftemplate)", "(= ?f:a 1)")
169
169
  ```
170
170
 
171
+ ### `CLIPS::Environment.get_fact_list`
172
+ ### `CLIPS::Environment#get_fact_list`
173
+
174
+ Return an array of Facts in the environment. Pass an argument of a
175
+ symbol, string, or Defmodule object in order to only get Facts with deftemplates
176
+ in that Defmodule. If you do not, it will return all Facts in all modules.
177
+
178
+ ```ruby
179
+ CLIPS::Environment.get_fact_list
180
+ env.get_fact_list
181
+ CLIPS::Environment.get_fact_list(:MAIN)
182
+ env.get_fact_list(:MAIN)
183
+ CLIPS::Environment.get_fact_list(defmodule)
184
+ env.get_fact_list(defmodule)
185
+ ```
186
+
171
187
  ### `CLIPS::Environment.find_all_facts`
172
188
  ### `CLIPS::Environment#find_all_facts`
173
189
 
@@ -468,6 +484,16 @@ CLIPS::Environment::Defmodule.set_current(defmodule)
468
484
  defmodule.set_current
469
485
  ```
470
486
 
487
+ ### `CLIPS::Environment::Defmodule.get_fact_list`
488
+ ### `CLIPS::Environment::Defmodule#get_fact_list`
489
+
490
+ Return an array of Facts with deftemplates in the Defmodule
491
+
492
+ ```ruby
493
+ CLIPS::Environment::Defmodule.get_fact_list(defmodule)
494
+ defmodule.get_fact_list
495
+ ```
496
+
471
497
  ## Running the tests
472
498
 
473
499
  Simply do `rake compile` and then `rake test` in order to run the tests.
@@ -1313,6 +1313,75 @@ static VALUE clips_environment_static_find_defmodule(VALUE self, VALUE rbEnviron
1313
1313
  return clips_environment_find_defmodule(rbEnvironment, defmodule_name);
1314
1314
  }
1315
1315
 
1316
+ static VALUE clips_environment_get_fact_list(int argc, VALUE *argv, VALUE rbEnvironment) {
1317
+ VALUE defmodule_or_defmodule_name;
1318
+ Environment *env;
1319
+ Defmodule *module;
1320
+ CLIPSValue value;
1321
+ VALUE out;
1322
+
1323
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
1324
+
1325
+ rb_scan_args(argc, argv, "01", &defmodule_or_defmodule_name);
1326
+ switch (TYPE(defmodule_or_defmodule_name)) {
1327
+ case T_NIL:
1328
+ module = NULL;
1329
+ break;
1330
+ case T_STRING:
1331
+ case T_SYMBOL:
1332
+ TypedData_Get_Struct(
1333
+ clips_environment_find_defmodule(rbEnvironment, defmodule_or_defmodule_name),
1334
+ Defmodule, &Defmodule_type, module);
1335
+ break;
1336
+ case T_DATA:
1337
+ TypedData_Get_Struct(defmodule_or_defmodule_name, Defmodule, &Defmodule_type, module);
1338
+ break;
1339
+ default:
1340
+ rb_warn("defmodule name must be a symbol or string");
1341
+ return Qnil;
1342
+ }
1343
+ GetFactList(env, &value, module);
1344
+
1345
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1346
+
1347
+ return out;
1348
+ }
1349
+
1350
+ static VALUE clips_environment_static_get_fact_list(int argc, VALUE *argv, VALUE klass) {
1351
+ VALUE rbEnvironment, defmodule_or_defmodule_name;
1352
+ Environment *env;
1353
+ Defmodule *module;
1354
+ CLIPSValue value;
1355
+ VALUE out;
1356
+
1357
+ rb_scan_args(argc, argv, "11", &rbEnvironment, &defmodule_or_defmodule_name);
1358
+
1359
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
1360
+ switch (TYPE(defmodule_or_defmodule_name)) {
1361
+ case T_NIL:
1362
+ module = NULL;
1363
+ break;
1364
+ case T_STRING:
1365
+ case T_SYMBOL:
1366
+ TypedData_Get_Struct(
1367
+ clips_environment_find_defmodule(rbEnvironment, defmodule_or_defmodule_name),
1368
+ Defmodule, &Defmodule_type, module);
1369
+ break;
1370
+ case T_DATA:
1371
+ TypedData_Get_Struct(defmodule_or_defmodule_name, Defmodule, &Defmodule_type, module);
1372
+ break;
1373
+ default:
1374
+ rb_warn("defmodule name must be a symbol or string");
1375
+ return Qnil;
1376
+ }
1377
+ GetFactList(env, &value, module);
1378
+
1379
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1380
+
1381
+ return out;
1382
+
1383
+ }
1384
+
1316
1385
  static VALUE clips_environment_defmodule_name(VALUE self)
1317
1386
  {
1318
1387
  Defmodule *defmodule;
@@ -1361,6 +1430,30 @@ static VALUE clips_environment_defmodule_static_set_current(VALUE self, VALUE rb
1361
1430
  return clips_environment_defmodule_set_current(rbDefmodule);
1362
1431
  }
1363
1432
 
1433
+ static VALUE clips_environment_defmodule_get_fact_list(VALUE self)
1434
+ {
1435
+ Defmodule *module;
1436
+ Environment *env;
1437
+ CLIPSValue value;
1438
+ VALUE out;
1439
+
1440
+ VALUE rbEnvironment = rb_iv_get(self, "@environment");
1441
+
1442
+ TypedData_Get_Struct(self, Defmodule, &Defmodule_type, module);
1443
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
1444
+
1445
+ GetFactList(env, &value, module);
1446
+
1447
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1448
+
1449
+ return out;
1450
+ }
1451
+
1452
+ static VALUE clips_environment_defmodule_static_get_fact_list(VALUE self, VALUE rbDefmodule)
1453
+ {
1454
+ return clips_environment_defmodule_get_fact_list(rbDefmodule);
1455
+ }
1456
+
1364
1457
  static VALUE clips_environment_defrule_name(VALUE self)
1365
1458
  {
1366
1459
  Defrule *defrule;
@@ -1514,6 +1607,8 @@ void Init_clipsruby(void)
1514
1607
  rb_define_method(rbEnvironment, "get_current_module", clips_environment_get_current_module, 0);
1515
1608
  rb_define_singleton_method(rbEnvironment, "set_current_module", clips_environment_static_set_current_module, 2);
1516
1609
  rb_define_method(rbEnvironment, "set_current_module", clips_environment_set_current_module, 1);
1610
+ rb_define_singleton_method(rbEnvironment, "get_fact_list", clips_environment_static_get_fact_list, -1);
1611
+ rb_define_method(rbEnvironment, "get_fact_list", clips_environment_get_fact_list, -1);
1517
1612
 
1518
1613
  VALUE rbDefmodule = rb_define_class_under(rbEnvironment, "Defmodule", rb_cObject);
1519
1614
  rb_define_alloc_func(rbDefmodule, defmodule_alloc);
@@ -1523,6 +1618,8 @@ void Init_clipsruby(void)
1523
1618
  rb_define_method(rbDefmodule, "pp_form", clips_environment_defmodule_pp_form, 0);
1524
1619
  rb_define_singleton_method(rbDefmodule, "set_current", clips_environment_defmodule_static_set_current, 1);
1525
1620
  rb_define_method(rbDefmodule, "set_current", clips_environment_defmodule_set_current, 0);
1621
+ rb_define_singleton_method(rbDefmodule, "get_fact_list", clips_environment_defmodule_static_get_fact_list, 1);
1622
+ rb_define_method(rbDefmodule, "get_fact_list", clips_environment_defmodule_get_fact_list, 0);
1526
1623
 
1527
1624
  VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
1528
1625
  rb_define_alloc_func(rbFact, fact_alloc);
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.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Johnston