expressive 0.0.30 → 0.0.31

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDExOTI2N2Y5ZGUwNTgyMmYzZjE4N2E1NDcxZDZmNjI2NjhlNjk4OQ==
4
+ M2NkNDAxY2NhMmU4NjU2ZDAwNGYxZDQwYzExMWNkZDVjNTIxZTRjMw==
5
5
  data.tar.gz: !binary |-
6
- ODFkMmRkYzljNmFmZjU1NmYwNTllZDg3NTNhZDZhYTY2OWQyZTAxNA==
6
+ MWY3NzkwOGYyNTc2ZWQ3ODU3ZjdmOTY2OTQ0ZDliMWFlMTc0ZTMxZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZmQ3YTBmOWEyZjYyN2YwZGZiOTRjYzY1YjFhYTU2YjJlY2JhZDhjZWI4MWRk
10
- ZGU3MzhkZjYzOTcwM2ZmOTk3OWUwMDFmNmJiYmJjMmU2MmViZGMwNzA1MTBj
11
- MmU3MDI2MjdiYTRlYTk3MmQ3MWZiNDQ3OTJiNWNmMGFkMTViMzU=
9
+ MGI4MTUwNjcwMDk4OTI4OWYxNDhmMDE5OTg0OWU1NmRjOWVjMjI5MDQ2NDE5
10
+ NTc0NjgwYWNlZWQxNjVhMzljMzY1MDI3YjBiNTcwMTdiODY1YWQ2NzUyNDI0
11
+ NDViNTc5MzFkMjc0MDQ2OWYwYzY4MDQ4MWZhZTVhNDNmYjY4MGQ=
12
12
  data.tar.gz: !binary |-
13
- ODBjNmMwNTFhMzVlZWE1YzE3NDIxMTNlNDdkOGIyNTZkNWNjMWIzZDdkNWFh
14
- NjE3MzlmZTNhZGQ0YTU5NmJjMWNlM2I0NjA0NzcxYTk5OTQzYzVmNjE1NGQ0
15
- Y2I4NTlhM2Y4NTNjM2RlMDgxODVjNzJkOTg1MWJhY2NhNDEwMGE=
13
+ ZmE0Yjc5NTFmOTI3NTA1YjU1NjcyYjNkOThhOTZmZDZlZWQ0YzBjOTVhMzlj
14
+ M2FiZDY0OGRiNTQ3NTA5OTEwNGNiOWVjMjQ0ZDE3NzdlYTZlN2Q1NDJjM2Jh
15
+ ZjIxNDQ5ODUzNjM5ZDlkMGZjZGFhYWI4MWMxMzVlNTRmNTM2OTg=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- expressive (0.0.30)
4
+ expressive (0.0.31)
5
5
  awesome_print (~> 1.0.2)
6
6
  json
7
7
  polyglot (~> 0.3.3)
data/lib/expressive.rb CHANGED
@@ -20,7 +20,7 @@ module Expressive
20
20
  end
21
21
 
22
22
  def self.all_symbols
23
- %w(+ - * / = set sum $sub post >= > < <= and or if date datetime get put lookup $lookup $head $tail $reverse round $round $days_ago $hours_ago $minutes_ago $append $id $hash $concat $split $sms $hval $index)
23
+ %w(+ - * / = set sum $sub post >= > < <= and or if date datetime get put lookup $lookup $head $tail $reverse round $round $days_ago $hours_ago $minutes_ago $append $id $hash $concat $split $sms $hval $index $random $join)
24
24
  end
25
25
 
26
26
  module Boolean
@@ -1,3 +1,3 @@
1
1
  module Expressive
2
- VERSION = "0.0.30"
2
+ VERSION = "0.0.31"
3
3
  end
data/lib/scope.rb CHANGED
@@ -126,10 +126,18 @@ module Expressive
126
126
  perform_concat(scope, cells)
127
127
  end
128
128
 
129
+ syntax('$join') do |scope, cells|
130
+ perform_join(scope, cells)
131
+ end
132
+
129
133
  syntax('$sms') do |scope, cells|
130
134
  perform_sms(scope, cells)
131
135
  end
132
136
 
137
+ syntax('$random') do |scope, cells|
138
+ perform_random(scope, cells)
139
+ end
140
+
133
141
  syntax('$split') do |scope, cells|
134
142
  perform_split(scope, cells)
135
143
  end
@@ -198,6 +206,10 @@ module Expressive
198
206
  return cells[0].eval(scope).to_s + cells[1].eval(scope).to_s
199
207
  end
200
208
 
209
+ def perform_join(scope, cells)
210
+ return cells[0].eval(scope).to_s + " " + cells[1].eval(scope).to_s
211
+ end
212
+
201
213
  def perform_sms(scope, cells)
202
214
  uri = URI.parse("http://api.clickatell.com/http/sendmsg")
203
215
 
@@ -223,6 +235,12 @@ module Expressive
223
235
 
224
236
  end
225
237
 
238
+ def perform_random(scope, cells)
239
+ evaluated_cells = cells.map{|cell| cell.eval(scope)}
240
+ chosen_cell = rand(Range.new(0,evaluated_cells.count-1))
241
+ evaluated_cells[chosen_cell]
242
+ end
243
+
226
244
  def perform_split(scope, cells)
227
245
  return cells[0].elements[1].text_value.split(cells[1].elements[1].text_value)
228
246
  end
@@ -6,7 +6,7 @@ describe "Expressive" do
6
6
  end
7
7
 
8
8
  describe "all_symbols" do
9
- it { Expressive.all_symbols.should =~ %w(+ - * / = set sum $sub get put post >= > < <= and or if date datetime lookup round $round $days_ago $hours_ago $minutes_ago $append $id $head $lookup $reverse $tail $hash $concat $split $sms $hval $index) }
9
+ it { Expressive.all_symbols.should =~ %w(+ - * / = set sum $sub get put post >= > < <= and or if date datetime lookup round $round $days_ago $hours_ago $minutes_ago $append $id $head $lookup $reverse $tail $hash $concat $split $sms $hval $index $random $join) }
10
10
  end
11
11
 
12
12
  describe "understands booleans" do
@@ -27,6 +27,7 @@ describe "Expressive" do
27
27
 
28
28
  context "string manipulation" do
29
29
  it {Expressive.run('($concat "hello" " world")').should eql "hello world" }
30
+ it {Expressive.run('($join "hello" "world")').should eql "hello world" }
30
31
  it {
31
32
  @scope["scope_value"] = "world"
32
33
  Expressive.run('($concat "hello " scope_value)', @scope).should eql "hello world"
@@ -251,6 +252,34 @@ EOH
251
252
  it { Expressive.run('(or true true)').should eql true }
252
253
  it { Expressive.run('(or true false)').should eql true }
253
254
  it { Expressive.run('(or false false)').should eql false }
255
+ it { Expressive.run('(or false (or false false))').should eql false }
256
+ it { Expressive.run('(or false (or false true))').should eql true }
257
+ it { Expressive.run('(or false (or true false))').should eql true }
258
+ it { Expressive.run('(or true (or false false))').should eql true }
259
+
260
+ it "handles compound ors" do
261
+ expressive = "(if (or (= answer_2 \"Unemployed\") (or (= answer_2 \"Self-employed\") (or (= answer_2 \"Retired\") (= answer_2 \"Student\")))) 2 \"\")"
262
+
263
+ @scope["answer_2"] = "asdf"
264
+ result = Expressive.run(expressive, @scope)
265
+ result.should == ""
266
+
267
+ @scope["answer_2"] = "Unemployed"
268
+ result = Expressive.run(expressive, @scope)
269
+ result.should == 2
270
+
271
+ @scope["answer_2"] = "Self-employed"
272
+ result = Expressive.run(expressive, @scope)
273
+ result.should == 2
274
+
275
+ @scope["answer_2"] = "Retired"
276
+ result = Expressive.run(expressive, @scope)
277
+ result.should == 2
278
+
279
+ @scope["answer_2"] = "Student"
280
+ result = Expressive.run(expressive, @scope)
281
+ result.should == 2
282
+ end
254
283
 
255
284
  context "nil values" do
256
285
  it { Expressive.run('(and true nil_value)', @scope).should eql false }
@@ -260,6 +289,19 @@ EOH
260
289
  end
261
290
  end
262
291
 
292
+ describe "generates random values" do
293
+ it "generates random literal values" do
294
+ [1, 2, 3, 4].include?(Expressive.run('($random 1 2 3 4)', @scope)).should be_true
295
+ end
296
+ it "generates random values from scope" do
297
+ @scope["field1"] = "value1"
298
+ @scope["field2"] = "value2"
299
+ @scope["field3"] = "value3"
300
+ @scope["field4"] = "value4"
301
+ %W(value1 value2 value3 value4).include?(Expressive.run('($random field1 field2 field3 field4)', @scope)).should be_true
302
+ end
303
+ end
304
+
263
305
  describe "understands the modification of scope" do
264
306
 
265
307
  it "sets scope based off rounded equality calculation" do
@@ -279,11 +321,46 @@ EOH
279
321
  Expressive.run('(if (= ($round total_payment_amount 2) ($round refund_amount 2)) true, false)', @scope).should eql false
280
322
  Expressive.run('(= (- ($round total_payment_amount 2) ($round refund_amount 2)) 0)', @scope).should eql false
281
323
  Expressive.run('(set payment_reconciled (if (= ($round total_payment_amount 2) ($round refund_amount 2)) true false))', @scope)
282
- puts @scope['payment_reconciled']
283
324
  @scope['payment_reconciled'].should eql false
284
325
 
285
326
  end
286
327
 
328
+ describe "set field only if value of other fields equate" do
329
+ before(:each) do
330
+ @scope.add_lookup_function("state_by_name") do |options, name, additional_query_specs = []|
331
+ if name == "Reconciled"
332
+ 2
333
+ else
334
+ 3
335
+ end
336
+ end
337
+
338
+ @scope["number_of_related_matters"] = "asdf"
339
+ @scope["x_current_state"] = 3
340
+ end
341
+
342
+ it "when value matches" do
343
+ @scope.add_lookup_function("related_matters_count") do |options, additional_query_specs = []|
344
+ 1
345
+ end
346
+ result = Expressive.run("(set x_current_state (if (= (lookup related_matters_count) 1) (lookup state_by_name 'Reconciled') x_current_state)) (lookup related_matters_count)", @scope)
347
+
348
+ result.should eql 1
349
+ @scope["x_current_state"].should eql 2
350
+ end
351
+
352
+ it "when value does not match" do
353
+ @scope.add_lookup_function("related_matters_count") do |options, additional_query_specs = []|
354
+ 0
355
+ end
356
+ result = Expressive.run("(set x_current_state (if (= (lookup related_matters_count) 1) (lookup state_by_name 'Reconciled') x_current_state)) (lookup related_matters_count)", @scope)
357
+
358
+ result.should eql 0
359
+ @scope["x_current_state"].should eql 3
360
+ end
361
+
362
+ end
363
+
287
364
  it "using single set commands" do
288
365
  @scope['vsi'] = 'oldvalue'
289
366
  Expressive.run('(set vsi "vsi1234")', @scope).should eql "vsi1234"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expressive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.30
4
+ version: 0.0.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ijonas Kisselbach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-12 00:00:00.000000000 Z
11
+ date: 2014-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_gntp