expressive 0.0.29 → 0.0.30

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
- NjBiY2RjOWUzNTlmYmQzMGQzMWM5YzQ4NWQ2NTJiN2FlMTZkNjE3Zg==
4
+ NDExOTI2N2Y5ZGUwNTgyMmYzZjE4N2E1NDcxZDZmNjI2NjhlNjk4OQ==
5
5
  data.tar.gz: !binary |-
6
- NTIzMjJhNGYxMDBhN2M0ZDYyM2UwYzFiYjZlOGQ2N2UzMDA5NmU2Yw==
6
+ ODFkMmRkYzljNmFmZjU1NmYwNTllZDg3NTNhZDZhYTY2OWQyZTAxNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDA0ODU0NzI4OTM5Y2Q5OTdmY2YzM2I3YThiNjE3ODY5MDg3MTNiMzYzNTM3
10
- MmE1OGE4ZTcxYmE0MzFiZDhkYTZhNDc3YzIwOWYyZGY2YjZmY2QyZjliZjUy
11
- Mzk2ZDc0MzcwYTllNGJkY2IyZDhmOTgwMDI5Mjk0MjAyYThhYjI=
9
+ ZmQ3YTBmOWEyZjYyN2YwZGZiOTRjYzY1YjFhYTU2YjJlY2JhZDhjZWI4MWRk
10
+ ZGU3MzhkZjYzOTcwM2ZmOTk3OWUwMDFmNmJiYmJjMmU2MmViZGMwNzA1MTBj
11
+ MmU3MDI2MjdiYTRlYTk3MmQ3MWZiNDQ3OTJiNWNmMGFkMTViMzU=
12
12
  data.tar.gz: !binary |-
13
- ZGQ2ZGJkNmM4ZGFlMzZkY2Y1Y2NjMTZiYWNhNWNmZGFiZWVlZGQ4YTNkZmU5
14
- M2MxMTYzZjBkZjlmNTdlOGNhOWU0NDE2ZDExYmJmNzRmM2Q0MGI3YmM5MjA5
15
- YTA0NjZiZTA2OTk2NmQ3NWUyZGFiYTRmOTE0NzQzMDVkNjc4NWY=
13
+ ODBjNmMwNTFhMzVlZWE1YzE3NDIxMTNlNDdkOGIyNTZkNWNjMWIzZDdkNWFh
14
+ NjE3MzlmZTNhZGQ0YTU5NmJjMWNlM2I0NjA0NzcxYTk5OTQzYzVmNjE1NGQ0
15
+ Y2I4NTlhM2Y4NTNjM2RlMDgxODVjNzJkOTg1MWJhY2NhNDEwMGE=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- expressive (0.0.28)
4
+ expressive (0.0.30)
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)
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)
24
24
  end
25
25
 
26
26
  module Boolean
@@ -1,3 +1,3 @@
1
1
  module Expressive
2
- VERSION = "0.0.29"
2
+ VERSION = "0.0.30"
3
3
  end
data/lib/scope.rb CHANGED
@@ -103,6 +103,12 @@ module Expressive
103
103
  hash
104
104
  end
105
105
 
106
+ syntax('$index') do |scope, cell|
107
+ data = cell[0].eval(scope)
108
+ index = cell[1].eval(scope)
109
+ data[index]
110
+ end
111
+
106
112
  syntax('$hval') do |scope, cells|
107
113
  key = cells[0].eval(scope)
108
114
  hash = cells[1].eval(scope)
@@ -189,7 +195,7 @@ module Expressive
189
195
  private
190
196
 
191
197
  def perform_concat(scope, cells)
192
- return cells[0].eval(scope) + cells[1].eval(scope)
198
+ return cells[0].eval(scope).to_s + cells[1].eval(scope).to_s
193
199
  end
194
200
 
195
201
  def perform_sms(scope, cells)
@@ -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) }
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) }
10
10
  end
11
11
 
12
12
  describe "understands booleans" do
@@ -91,6 +91,7 @@ describe "Expressive" do
91
91
  it { Expressive.run("(= (+ 4 2) 6)").should eql true }
92
92
  it { Expressive.run("(if (and (< 3 9) (> 2 1)), true, false)").should eql true }
93
93
  it { Expressive.run("(if (and (< 10 9) (> 2 1)), true, false)").should eql false }
94
+
94
95
  end
95
96
 
96
97
  describe "understands conditional statements" do
@@ -261,7 +262,7 @@ EOH
261
262
 
262
263
  describe "understands the modification of scope" do
263
264
 
264
- it "works" do
265
+ it "sets scope based off rounded equality calculation" do
265
266
  @scope['total_payment_amount'] = 2.32
266
267
  @scope['refund_amount'] = 2.32
267
268
  @scope['payment_reconciled'] = "asdf"
@@ -359,6 +360,49 @@ EOH
359
360
 
360
361
  end
361
362
 
363
+ describe "$index" do
364
+ it "generates an array" do
365
+ Expressive.run('(2 3)').should eql [2,3]
366
+ end
367
+ it "picks out correct field" do
368
+ Expressive.run('($index (2 3) 1)').should eql 3
369
+ end
370
+
371
+ it "picks correct result from calculations" do
372
+ @scope["total_payment_amount"] = 56
373
+ @scope.add_lookup_function("related_payments_count") do |options, additional_query_specs = []|
374
+ 2
375
+ end
376
+
377
+ @scope.add_lookup_function("related_payments_summed") do |options, select_field, additional_query_specs = []|
378
+ 200.50
379
+ end
380
+
381
+ result = Expressive.run('($index ((set total_payment_amount ($round (lookup related_payments_summed \"total_amount\") 2)) (lookup related_payments_count)) 1)', @scope)
382
+
383
+ @scope["total_payment_amount"].should == 200.50
384
+ result.should == 2
385
+
386
+ end
387
+ end
388
+
389
+
390
+ it "sets value and then looksup another" do
391
+ @scope["total_payment_amount"] = 56
392
+ @scope.add_lookup_function("related_payments_count") do |options, additional_query_specs = []|
393
+ 2
394
+ end
395
+
396
+ @scope.add_lookup_function("related_payments_summed") do |options, select_field, additional_query_specs = []|
397
+ 200.50
398
+ end
399
+
400
+ result = Expressive.run('(set total_payment_amount ($round (lookup related_payments_summed \"total_amount\") 2)) (lookup related_payments_count)', @scope)
401
+
402
+ @scope["total_payment_amount"].should == 200.50
403
+ result.should == 2
404
+ end
405
+
362
406
  describe "understands adding values to lists" do
363
407
  it "add a single value to a list of values" do
364
408
  Expressive.run('($append participating_teams 1)', @scope)
@@ -394,6 +438,19 @@ EOH
394
438
  it { Expressive.run("($minutes_ago 12)").should eql (@now - 12 * 60) }
395
439
  end
396
440
 
441
+ describe "concat" do
442
+ it "string and number values" do
443
+ Expressive.run('($concat "ref-" 3)').should eql "ref-3"
444
+ end
445
+
446
+ it "concats from lookups" do
447
+ @scope.add_lookup_function("related_matter", case_type: "matter_case_type") do |options, select_field, additional_query_specs = []|
448
+ "value1"
449
+ end
450
+ Expressive.run('($concat "matter-" (lookup related_matter "field1"))', @scope).should eql "matter-value1"
451
+ end
452
+
453
+ end
397
454
 
398
455
  describe "understands using lookup functions" do
399
456
  it "should perform the lookup function (add account and reverse login)" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expressive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.29
4
+ version: 0.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ijonas Kisselbach