expressive 0.0.35 → 0.0.36

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
- Yzg1YTRmMzc4ZWE0Y2YzNmFiODRjNGViZGZlYTk0ZDA0YWE3ODE2Mg==
4
+ NTZiZTNjOTMzNmUwOTA5ODg1NmE0MGViMmIxZTA4YWQ1NTQyOTE0Mw==
5
5
  data.tar.gz: !binary |-
6
- NTcyM2M0NjRiMjJjODBhZTcyYjNiZjQwYzdhNjNmNWEyMmEzZDZlZQ==
6
+ MDVhNDA4NzJhNzBhODM1NDg2NzU2ZjYyODkxYjQxMTc3YzlhODMxYw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MWFkMmNlZjRjM2QyYWJlOWUxNGQyNGY1YTZkZmRhZTdlZGFlZTcxZmE2ODU4
10
- M2VkNjk2NTkyZDJhZDlmNDg1NjcyZTIwM2IyYTM0MWYwYmY1Mjk3NTYxZjY5
11
- NWJiMTQ3NWNkNjQwM2YxNmQyYWFmMDI0OGY0MzM3NmE0ZmI2YWE=
9
+ ZWY0NTM0NmNhZGYyNzRlMDQ2M2FmZTAzOWNhMWI0YTljZTY4YjYzNTQwNWFj
10
+ MmE2ZjgyNTI1OTc3NzA1OGRlYjA1ODI2NWQyYThiNDc1OTQzZDMzNmMzZjlj
11
+ MTQxMzlkMTdkOTcyM2ZiZWUxY2IxZmY4ZjkyNGE5ZGZjMjdmMGE=
12
12
  data.tar.gz: !binary |-
13
- YjlkMGZhNDkxYzc2ODVlMGRiNTViMjFlZjM1MjQzMWUyOTIyNDBlN2I2YWQy
14
- YzgxNGMxNTNlN2YwYTdhZWZmMTZiZmM5NWE4ZjE2ZGExZDljMzBlYmNlYjVj
15
- NTY1ZjAzYzM5ZmFmMzBkNDUxMWI3ZDNiMjZlZmE3M2NiMDBmZGU=
13
+ ZjVmZTE5YTRkMjljY2ZlYzBlN2QzZDYzYmFhZjQ4NmM5ZDliZWE2NTA1ZTk0
14
+ ZmVmMmExNGVmMDFkNjYxMGJmOGFkYTA4MzNhOGMyZjlmMTZkNWE0YmFmMmFm
15
+ ZDZmY2ExMDI3ODQzNWJlZDEwNDgzNzEyMjU5YzcyZWVmMGQ3NjA=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- expressive (0.0.33)
4
+ expressive (0.0.36)
5
5
  awesome_print (~> 1.0.2)
6
6
  json
7
7
  polyglot (~> 0.3.3)
@@ -1,3 +1,3 @@
1
1
  module Expressive
2
- VERSION = "0.0.35"
2
+ VERSION = "0.0.36"
3
3
  end
data/lib/expressive.rb CHANGED
@@ -35,7 +35,7 @@ module Expressive
35
35
  end
36
36
 
37
37
  def self.all_symbols
38
- %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 $not $include)
38
+ %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 $not $include $string $float $integer)
39
39
  end
40
40
 
41
41
  module Boolean
data/lib/scope.rb CHANGED
@@ -191,6 +191,9 @@ module Expressive
191
191
  define('$tail'){|*args| args.flatten[1..-1] }
192
192
  define('$reverse'){|*args| args.flatten.reverse }
193
193
  define('$not'){|*args| not args.first }
194
+ define('$string'){|*args| args.first.to_s}
195
+ define('$float'){|*args| args.first.to_f}
196
+ define('$integer'){|*args| args.first.to_i}
194
197
 
195
198
  define('$round'){|*args| perform_round(args) }
196
199
  define('round'){|*args| perform_round(args) }
@@ -244,7 +247,7 @@ module Expressive
244
247
  end
245
248
 
246
249
  def perform_split(scope, cells)
247
- return cells[0].elements[1].text_value.split(cells[1].elements[1].text_value)
250
+ return cells[0].eval(scope).split(cells[1].eval(scope))
248
251
  end
249
252
 
250
253
  #(post "http://example.com" "*" (headers "AUTH-TOKEN=13415") )
@@ -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 $random $join $not $include) }
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 $not $include $string $float $integer) }
10
10
  end
11
11
 
12
12
  describe "understands booleans" do
@@ -33,8 +33,21 @@ describe "Expressive" do
33
33
  Expressive.run('($concat "hello " scope_value)', @scope).should eql "hello world"
34
34
  }
35
35
  it {Expressive.run('($split "a,b,c,d,e" ",")').should eql ['a', 'b', 'c', 'd', 'e'] }
36
+ it {
37
+ @scope["scope_value"] = "a,b,c,d,e"
38
+ Expressive.run('($split scope_value ",")', @scope).should eql ['a', 'b', 'c', 'd', 'e']
39
+ }
40
+
36
41
  end
42
+ end
37
43
 
44
+ describe "understands literals" do
45
+ it {
46
+ @scope["test_value"] = 1
47
+ @scope["test_1_value"] = 3
48
+ Expressive.run('test_value', @scope).should eql 1
49
+ Expressive.run('test_1_value', @scope).should eql 3
50
+ }
38
51
  end
39
52
 
40
53
  describe "hash manipulation" do
@@ -263,7 +276,7 @@ EOH
263
276
 
264
277
  it "handles compound ors" do
265
278
  expressive = "(if (or (= answer_2 \"Unemployed\") (or (= answer_2 \"Self-employed\") (or (= answer_2 \"Retired\") (= answer_2 \"Student\")))) 2 \"\")"
266
-
279
+
267
280
  @scope["answer_2"] = "asdf"
268
281
  result = Expressive.run(expressive, @scope)
269
282
  result.should == ""
@@ -539,6 +552,16 @@ EOH
539
552
  it { Expressive.run("($minutes_ago 12)").should eql (@now - 12 * 60) }
540
553
  end
541
554
 
555
+ describe "string" do
556
+ it {Expressive.run("($string 7)").should eql "7" }
557
+ end
558
+ describe "integer" do
559
+ it {Expressive.run("($integer 7)").should eql 7 }
560
+ end
561
+ describe "float" do
562
+ it {Expressive.run("($float 7)").should eql 7.0 }
563
+ end
564
+
542
565
  describe "concat" do
543
566
  it "string and number values" do
544
567
  Expressive.run('($concat "ref-" 3)').should eql "ref-3"
@@ -752,7 +775,7 @@ EOH
752
775
  end
753
776
  end
754
777
  end
755
-
778
+
756
779
  describe "parse error handling" do
757
780
  it "should raise parse exceptions" do
758
781
  expect{ Expressive.run(nil) }.to raise_error Expressive::ParseError, "Error parsing nil expression: undefined method `length' for nil:NilClass"
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.35
4
+ version: 0.0.36
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-06-09 00:00:00.000000000 Z
11
+ date: 2014-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_gntp