clipsruby 0.0.7 → 0.0.8

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 +10 -0
  3. data/ext/clipsruby/clipsruby.c +29 -4
  4. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75e4ce843f3549eb6b8508d4d97ab8193dc8434acab30659af50871953759991
4
- data.tar.gz: 5372088f0743df5a5e3e94833bb7334608bfe85c0ede4879476e3a014eeb034d
3
+ metadata.gz: 8bca9526858c7578fb8f1347584b76bdf99c5f8f74d301554751941bd3e3dde8
4
+ data.tar.gz: '018e3bd14394a440793cd5006c75e2ce6fa0e2395ec2c85304bcb2a4e7757118'
5
5
  SHA512:
6
- metadata.gz: e3700fb8eb942640cd698985ecf00190ad447b89dfeed35df3125924e577de0be0f6b56695a1f0e2adfc078b2cdc7655bbdf08c22f40624eb305d4d539da2fd5
7
- data.tar.gz: 7626b936453007c332c1cc1f191e449ce3c68f9447281a595fceef524a0cc9bc5a5c603d2afd5553887049d380c6297d0a8e27e9256f9fc54330722cdaaf8ba5
6
+ metadata.gz: 77e80952f44f747a30e40ebdc433bf46734a5c48e172557c438ec84b94de91ba486ee7791974837442a229c401b06b56658fc33eb2dd9251c617ce3a4eadaab5
7
+ data.tar.gz: ad93fe9c5b7803738e449a1b373cffde734c84baef745364cfe9f866a5585e82cd757fd750263d2ca02c204f1cff002eb69e04f955ab6fa80f75c7eca197a890
data/README.md CHANGED
@@ -113,6 +113,16 @@ CLIPS::Environment.facts(env)
113
113
  env.facts
114
114
  ```
115
115
 
116
+ ### `CLIPS::Environment::Fact.to_h`
117
+ ### `CLIPS::Environment::Fact#to_h`
118
+
119
+ Returns a hash representing the fact slot names and their values
120
+
121
+ ```ruby
122
+ CLIPS::Environment::Fact.to_h(fact)
123
+ fact.to_h
124
+ ```
125
+
116
126
  ### `CLIPS::Environment::Fact.deftemplate_name`
117
127
  ### `CLIPS::Environment::Fact#deftemplate_name`
118
128
 
@@ -350,7 +350,7 @@ static void CLIPSValue_to_VALUE(CLIPSValue *from, VALUE *value, VALUE *rbEnviron
350
350
  } else if (from->lexemeValue == FalseSymbol(env)) {
351
351
  *value = Qfalse;
352
352
  } else {
353
- *value = rb_str_new2(from->lexemeValue->contents);
353
+ *value = ID2SYM(rb_intern(from->lexemeValue->contents));
354
354
  }
355
355
  break;
356
356
  case INTEGER_TYPE:
@@ -402,7 +402,7 @@ static void UDFValue_to_VALUE(UDFValue *from, VALUE *value, VALUE *rbEnvironment
402
402
  } else if (from->lexemeValue == FalseSymbol(env)) {
403
403
  *value = Qfalse;
404
404
  } else {
405
- *value = rb_str_new2(from->lexemeValue->contents);
405
+ *value = ID2SYM(rb_intern(from->lexemeValue->contents));
406
406
  }
407
407
  break;
408
408
  case INTEGER_TYPE:
@@ -657,6 +657,33 @@ static VALUE clips_environment_static_find_all_facts(int argc, VALUE *argv, VALU
657
657
  rb_sprintf("(find-all-facts (%s) %s)", StringValueCStr(fact_set_template), StringValueCStr(query)));
658
658
  }
659
659
 
660
+ static VALUE clips_environment_fact_to_h(VALUE self)
661
+ {
662
+ Fact *fact;
663
+ CLIPSValue key, value;
664
+ VALUE rbEnvironment = rb_iv_get(self, "@environment");
665
+
666
+ TypedData_Get_Struct(self, Fact, &Fact_type, fact);
667
+
668
+ FactSlotNames(fact, &key);
669
+
670
+ VALUE hash = rb_hash_new();
671
+ for (size_t i = 0; i < key.multifieldValue->length; i++)
672
+ {
673
+ VALUE innerValue;
674
+ GetFactSlot(fact, key.multifieldValue->contents[i].lexemeValue->contents, &value);
675
+ CLIPSValue_to_VALUE(&value, &innerValue, &rbEnvironment);
676
+ rb_hash_aset(hash, rb_str_new2(key.multifieldValue->contents[i].lexemeValue->contents), innerValue);
677
+ }
678
+
679
+ return hash;
680
+ }
681
+
682
+ static VALUE clips_environment_fact_static_to_h(VALUE self, VALUE rbFact)
683
+ {
684
+ return clips_environment_fact_to_h(rbFact);
685
+ }
686
+
660
687
  void Init_clipsruby(void)
661
688
  {
662
689
  VALUE rbCLIPS = rb_define_module("CLIPS");
@@ -684,10 +711,8 @@ void Init_clipsruby(void)
684
711
  VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
685
712
  rb_define_singleton_method(rbFact, "deftemplate_name", clips_environment_fact_static_deftemplate_name, 1);
686
713
  rb_define_method(rbFact, "deftemplate_name", clips_environment_fact_deftemplate_name, 0);
687
- /*
688
714
  rb_define_singleton_method(rbFact, "to_h", clips_environment_fact_static_to_h, 1);
689
715
  rb_define_method(rbFact, "to_h", clips_environment_fact_to_h, 0);
690
- */
691
716
 
692
717
  VALUE rbInstance = rb_define_class_under(rbEnvironment, "Instance", rb_cObject);
693
718
  }
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.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Johnston
@@ -367,6 +367,7 @@ homepage: https://rubygems.org/gems/clipsruby
367
367
  licenses:
368
368
  - MIT
369
369
  metadata:
370
+ documentation_uri: https://github.com/mrryanjohnston/clipsruby/blob/main/README.md
370
371
  source_code_uri: https://github.com/mrryanjohnston/clipsruby
371
372
  post_install_message:
372
373
  rdoc_options: []