rast 0.6.1.pre → 0.6.2.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9c4a7088f327bf84d6eaf26c5a52b0e4f232522a0114e302b22bbc26bff8247
4
- data.tar.gz: fcbbd503e41761eb57543b66940ba680bec5710f1c05ed69690858b103db8de4
3
+ metadata.gz: 0eaf03a698891eb852079e41704e991c2d5e2732376f7966a785e1ca38f8a67f
4
+ data.tar.gz: 856abb598e0e163878109683e26cc301f3398498b091373a5b26e19f3dacc021
5
5
  SHA512:
6
- metadata.gz: 106f21c7e0cb06bb010719fe1adc17923ff1753f74fba1691ed7f63d9b91580761b71d51c3abda0a1e978eb30b76f24a9a18274287ca11bf1204f9042e125b83
7
- data.tar.gz: 194bbd079a183ee340edbeace605315227529e1d99374232494209cfcb91a3f3fa429d92b1988a798af7deccbbce1a40a525ebf3120e2e459b228deb2f497219
6
+ metadata.gz: 53b66163427b7fa80ffc986dc27ce26d5c01406fcf5c15362b164dc8d96ee9af49a29c1554555a8a100b7e5a7379ad2c0feebc55ddc4b24d31d52ffd961ec409
7
+ data.tar.gz: 6026193252d5c2829c68fbeee17932dec81102879edba3feccce0e76fef574ae612116c6a20f06be75216fadfb421874e4da1583d67f89c7a70f2c95245eb856
data/CHANGELOG.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Change log
2
2
 
3
+ - 0.6.2.pre - Bugfix for 1D array of numbers scenario.
3
4
  - 0.6.1.pre - Bugfix on the converters when used with rule exclusion.
4
5
  - 0.6.0.pre - Reverted redesign.
5
6
  - 0.5.0.pre - Redesigned to have subject as first block parameter. Everything inside
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Example single number answer
4
+ class Positive
5
+ def positive?(number)
6
+ number > 0
7
+ end
8
+ end
@@ -28,11 +28,11 @@ class Rule
28
28
  end
29
29
 
30
30
  duplicates << outcome
31
- clause = remove_spaces(string: clause, separator: '\(')
32
- clause = remove_spaces(string: clause, separator: '\)')
33
- clause = remove_spaces(string: clause, separator: '&')
34
- clause = remove_spaces(string: clause, separator: '\|')
35
- clause = remove_spaces(string: clause, separator: '!')
31
+ clause = remove_spaces(token: clause, separator: '\(')
32
+ clause = remove_spaces(token: clause, separator: '\)')
33
+ clause = remove_spaces(token: clause, separator: '&')
34
+ clause = remove_spaces(token: clause, separator: '\|')
35
+ clause = remove_spaces(token: clause, separator: '!')
36
36
  @outcome_clause_hash[outcome.to_s] = clause.strip
37
37
  end
38
38
  end
@@ -47,8 +47,8 @@ class Rule
47
47
  # * @param string rule clause.
48
48
  # * @param separator rule clause token.
49
49
  # */
50
- def remove_spaces(string: '', separator: '')
51
- string.gsub(Regexp.new("\\s*#{separator} \\s*"), separator)
50
+ def remove_spaces(token: nil, separator: '')
51
+ token.to_s.gsub(Regexp.new("\\s*#{separator} \\s*"), separator)
52
52
  end
53
53
 
54
54
  # /**
@@ -29,6 +29,7 @@ class RuleEvaluator
29
29
  DEFAULT_CONVERT_HASH = {
30
30
  Integer => IntConverter.new,
31
31
  Float => FloatConverter.new,
32
+ Fixnum => FloatConverter.new,
32
33
  TrueClass => BoolConverter.new,
33
34
  FalseClass => BoolConverter.new,
34
35
  String => StrConverter.new
@@ -77,7 +78,7 @@ class RuleEvaluator
77
78
  if @stack_rpn.empty?
78
79
  true
79
80
  elsif @stack_rpn.size == 1
80
- evaluate_one_rpn(scenario: scenario)
81
+ evaluate_one_rpn(scenario: scenario).to_s
81
82
  else
82
83
  evaluate_multi_rpn(
83
84
  scenario: scenario,
@@ -258,11 +259,11 @@ class RuleEvaluator
258
259
  def evaluate_one_rpn(scenario: [])
259
260
  single = @stack_rpn.last
260
261
  subscript = extract_subscript(token: single)
262
+ default_converter = DEFAULT_CONVERT_HASH[scenario.first.class]
261
263
  if subscript > -1
262
- default_converter = DEFAULT_CONVERT_HASH[scenario.first.class]
263
264
  scenario[subscript] == default_converter.convert(single[RE_TOKEN_BODY])
264
265
  else
265
- scenario.include? single
266
+ scenario.include?(default_converter.convert(single))
266
267
  end
267
268
  end
268
269
 
data/rast.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'rast'
5
- spec.version = '0.6.1.pre'
5
+ spec.version = '0.6.2.pre'
6
6
  spec.authors = ['Royce Remulla']
7
7
  spec.email = ['royce.com@gmail.com']
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1.pre
4
+ version: 0.6.2.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Royce Remulla
@@ -31,6 +31,7 @@ files:
31
31
  - examples/logic_checker.rb
32
32
  - examples/logic_four.rb
33
33
  - examples/phone.rb
34
+ - examples/positive.rb
34
35
  - examples/prime_number.rb
35
36
  - examples/recruiter.rb
36
37
  - examples/worker.rb