clipsruby 0.0.14 → 0.0.15

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 +52 -12
  3. data/ext/clipsruby/clipsruby.c +98 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f33a751deeebf96aa16135763365063f9facdd95c2cd7e7df7de0e3e90bea56b
4
- data.tar.gz: f24d9c9901986b83ce38ffd97d5ef9f06c2409ae3b24de85094a73b78f39dbc4
3
+ metadata.gz: 1c09bd00794b99f18db2f3e1a7e79add255696071f73192f1009d97f6bc6a222
4
+ data.tar.gz: e68259458eb14602e69184d82723518b3ad99bf082a4a23994f0fb6b54ffffa3
5
5
  SHA512:
6
- metadata.gz: 1d8d10e392c06bb956d2c889e3090afce100ae4b9ef27a2a8463da231d5d00c645890b82376656bc7f17cdc33f248d49f8dd274ac341a7e60fdaf76d8a3d8496
7
- data.tar.gz: caf7c237fb87e4e04d842593fb7cb23d7d65b4494a373cd59fb5fc775a48dbe6c71a7cd86fbfa2d2efc93b338994079f26b9f406f47390cdad52d352476e1846
6
+ metadata.gz: f147d8a530205d27de62750701a2359ed5e0fdc9b7e6d01f9d953878f9dbc501f742406f6199a27b57231e465c48e608c1df4514b758e524f12e5f40d4f6fac4
7
+ data.tar.gz: 7927273ee5ed8945f122032796c07cb44def5d597d6a07cc1e24d2aa7788b3b02477b134463d007a4f4db32339e8860ccfa91bf9225d1d685e3d5e931daf0f62
data/README.md CHANGED
@@ -45,8 +45,8 @@ env.batch_star("./my-batch.bat")
45
45
  Pass the path in which we'll save the environment constructs.
46
46
 
47
47
  ```ruby
48
- CLIPS::Environment.save(env, "./my-save.bin")
49
- env.save("./my-save.bin")
48
+ CLIPS::Environment.save(env, "./my-save.clp")
49
+ env.save("./my-save.clp")
50
50
  ```
51
51
 
52
52
  ### `CLIPS::Environment.load`
@@ -56,8 +56,8 @@ Pass the path to a file that will load the constructs stored in the file
56
56
  into the environment. Remember to `reset` the environment if you need.
57
57
 
58
58
  ```ruby
59
- CLIPS::Environment.load(env, "./my-load.bin")
60
- env.load("./my-load.bin")
59
+ CLIPS::Environment.load(env, "./my-load.clp")
60
+ env.load("./my-load.clp")
61
61
  ```
62
62
 
63
63
  ### `CLIPS::Environment.save_facts`
@@ -68,12 +68,12 @@ The third argument is optional, and determines whether to store the visible or l
68
68
  By default, it'll store local.
69
69
 
70
70
  ```ruby
71
- CLIPS::Environment.save_facts(env, "./my-save-facts.bin")
72
- env.save_facts("./my-save-facts.bin")
73
- CLIPS::Environment.save_facts(env, "./my-save-facts.bin", :local)
74
- env.save_facts("./my-save-facts.bin", :local)
75
- CLIPS::Environment.save_facts(env, "./my-save-facts.bin", :visible)
76
- env.save_facts("./my-save-facts.bin", :visible)
71
+ CLIPS::Environment.save_facts(env, "./my-save-facts.clp")
72
+ env.save_facts("./my-save-facts.clp")
73
+ CLIPS::Environment.save_facts(env, "./my-save-facts.clp", :local)
74
+ env.save_facts("./my-save-facts.clp", :local)
75
+ CLIPS::Environment.save_facts(env, "./my-save-facts.clp", :visible)
76
+ env.save_facts("./my-save-facts.clp", :visible)
77
77
  ```
78
78
 
79
79
  ### `CLIPS::Environment.load_facts`
@@ -83,8 +83,8 @@ Pass the path to a file that will load the facts stored in the file
83
83
  into the environment.
84
84
 
85
85
  ```ruby
86
- CLIPS::Environment.load_facts(env, "./my-load-facts.bin")
87
- env.load_facts("./my-load-facts.bin")
86
+ CLIPS::Environment.load_facts(env, "./my-load-facts.clp")
87
+ env.load_facts("./my-load-facts.clp")
88
88
  ```
89
89
 
90
90
  ### `CLIPS::Environment.bsave`
@@ -338,6 +338,46 @@ CLIPS::Environment::Fact.modify(fact, bar: 123)
338
338
  fact.modify(foo: "my new foo!")
339
339
  ```
340
340
 
341
+ ### `CLIPS::Environment.find_defrule`
342
+ ### `CLIPS::Environment#find_defrule`
343
+
344
+ Finds a defrule by name and returns a CLIPS::Environment::Defrule object
345
+
346
+ ```ruby
347
+ CLIPS::Environment.find_defrule(:a)
348
+ env.find_defrule("foo")
349
+ ```
350
+
351
+ ### `CLIPS::Environment::Defrule.name`
352
+ ### `CLIPS::Environment::Defrule#name`
353
+
354
+ Returns the name of a defrule as a symbol
355
+
356
+ ```ruby
357
+ CLIPS::Environment::Defrule.name(defrule)
358
+ defrule.name
359
+ ```
360
+
361
+ ### `CLIPS::Environment::Defrule.is_deletable`
362
+ ### `CLIPS::Environment::Defrule#is_deletable`
363
+
364
+ Returns a boolean whether the Defrule is deletable or not
365
+
366
+ ```ruby
367
+ CLIPS::Environment::Defrule.is_deletable(defrule)
368
+ defrule.is_deletable
369
+ ```
370
+
371
+ ### `CLIPS::Environment::Defrule.pp_form`
372
+ ### `CLIPS::Environment::Defrule#pp_form`
373
+
374
+ Returns a pretty printed string representation of the Defrule
375
+
376
+ ```ruby
377
+ CLIPS::Environment::Defrule.pp_form(defrule)
378
+ defrule.pp_form
379
+ ```
380
+
341
381
  ## Running the tests
342
382
 
343
383
  Simply do `rake compile` and then `rake test` in order to run the tests.
@@ -1,6 +1,18 @@
1
1
  #include "clips.h"
2
2
  #include "ruby.h"
3
3
 
4
+ size_t defrule_size(const void *data)
5
+ {
6
+ return sizeof(Defrule);
7
+ }
8
+
9
+ static const rb_data_type_t Defrule_type = {
10
+ .function = {
11
+ .dsize = defrule_size
12
+ },
13
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
14
+ };
15
+
4
16
  size_t fact_size(const void *data)
5
17
  {
6
18
  return sizeof(Fact);
@@ -1167,6 +1179,82 @@ static VALUE clips_environment_fact_static_index(VALUE self, VALUE rbFact)
1167
1179
  return clips_environment_fact_index(rbFact);
1168
1180
  }
1169
1181
 
1182
+ static VALUE clips_environment_find_defrule(VALUE self, VALUE defrule_name)
1183
+ {
1184
+ Environment *env;
1185
+ Defrule *rule;
1186
+
1187
+ TypedData_Get_Struct(self, Environment, &Environment_type, env);
1188
+
1189
+ switch (TYPE(defrule_name)) {
1190
+ case T_STRING:
1191
+ rule = FindDefrule(env, StringValueCStr(defrule_name));
1192
+ break;
1193
+ case T_SYMBOL:
1194
+ rule = FindDefrule(env, rb_id2name(SYM2ID(defrule_name)));
1195
+ break;
1196
+ default:
1197
+ rb_warn("defrule name must be a symbol or string");
1198
+ return Qnil;
1199
+ }
1200
+
1201
+ if (rule == NULL) {
1202
+ return Qnil;
1203
+ } else {
1204
+ return TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Defrule")), &Defrule_type, rule);
1205
+ }
1206
+ }
1207
+
1208
+ static VALUE clips_environment_static_find_defrule(VALUE self, VALUE rbEnvironment, VALUE defrule_name)
1209
+ {
1210
+ return clips_environment_find_defrule(rbEnvironment, defrule_name);
1211
+ }
1212
+
1213
+ static VALUE clips_environment_defrule_name(VALUE self)
1214
+ {
1215
+ Defrule *defrule;
1216
+
1217
+ TypedData_Get_Struct(self, Defrule, &Defrule_type, defrule);
1218
+
1219
+ return ID2SYM(rb_intern(DefruleName(defrule)));
1220
+ }
1221
+
1222
+ static VALUE clips_environment_defrule_static_name(VALUE self, VALUE rbDefrule)
1223
+ {
1224
+ return clips_environment_defrule_name(rbDefrule);
1225
+ }
1226
+
1227
+ static VALUE clips_environment_defrule_pp_form(VALUE self)
1228
+ {
1229
+ Defrule *defrule;
1230
+
1231
+ TypedData_Get_Struct(self, Defrule, &Defrule_type, defrule);
1232
+
1233
+ return rb_str_new2(DefrulePPForm(defrule));
1234
+ }
1235
+
1236
+ static VALUE clips_environment_defrule_static_pp_form(VALUE self, VALUE rbDefrule)
1237
+ {
1238
+ return clips_environment_defrule_pp_form(rbDefrule);
1239
+ }
1240
+
1241
+ static VALUE clips_environment_defrule_is_deletable(VALUE self)
1242
+ {
1243
+ Defrule *defrule;
1244
+
1245
+ TypedData_Get_Struct(self, Defrule, &Defrule_type, defrule);
1246
+
1247
+ if (DefruleIsDeletable(defrule)) {
1248
+ return Qtrue;
1249
+ } else {
1250
+ return Qfalse;
1251
+ }
1252
+ }
1253
+
1254
+ static VALUE clips_environment_defrule_static_is_deletable(VALUE self, VALUE rbDefrule)
1255
+ {
1256
+ return clips_environment_defrule_is_deletable(rbDefrule);
1257
+ }
1170
1258
 
1171
1259
  void Init_clipsruby(void)
1172
1260
  {
@@ -1215,6 +1303,8 @@ void Init_clipsruby(void)
1215
1303
  rb_define_method(rbEnvironment, "bsave_facts", clips_environment_bsave_facts, -1);
1216
1304
  rb_define_singleton_method(rbEnvironment, "bload_facts", clips_environment_static_bload_facts, 2);
1217
1305
  rb_define_method(rbEnvironment, "bload_facts", clips_environment_bload_facts, 1);
1306
+ rb_define_singleton_method(rbEnvironment, "find_defrule", clips_environment_static_find_defrule, 2);
1307
+ rb_define_method(rbEnvironment, "find_defrule", clips_environment_find_defrule, 1);
1218
1308
 
1219
1309
  VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
1220
1310
  rb_define_singleton_method(rbFact, "deftemplate_name", clips_environment_fact_static_deftemplate_name, 1);
@@ -1232,5 +1322,13 @@ void Init_clipsruby(void)
1232
1322
  rb_define_singleton_method(rbFact, "index", clips_environment_fact_static_index, 1);
1233
1323
  rb_define_method(rbFact, "index", clips_environment_fact_index, 0);
1234
1324
 
1325
+ VALUE rbDefrule = rb_define_class_under(rbEnvironment, "Defrule", rb_cObject);
1326
+ rb_define_singleton_method(rbDefrule, "name", clips_environment_defrule_static_name, 1);
1327
+ rb_define_method(rbDefrule, "name", clips_environment_defrule_name, 0);
1328
+ rb_define_singleton_method(rbDefrule, "pp_form", clips_environment_defrule_static_pp_form, 1);
1329
+ rb_define_method(rbDefrule, "pp_form", clips_environment_defrule_pp_form, 0);
1330
+ rb_define_singleton_method(rbDefrule, "is_deletable", clips_environment_defrule_static_is_deletable, 1);
1331
+ rb_define_method(rbDefrule, "is_deletable", clips_environment_defrule_is_deletable, 0);
1332
+
1235
1333
  VALUE rbInstance = rb_define_class_under(rbEnvironment, "Instance", rb_cObject);
1236
1334
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clipsruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Johnston
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-07 00:00:00.000000000 Z
11
+ date: 2024-09-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Calling the CLIPS programming language from within Ruby
14
14
  email: mrryanjohnston@gmail.com