expressive 0.0.23 → 0.0.24

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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- expressive (0.0.23)
4
+ expressive (0.0.24)
5
5
  awesome_print (~> 1.0.2)
6
6
  json
7
7
  polyglot (~> 0.3.3)
@@ -20,7 +20,7 @@ module Expressive
20
20
  end
21
21
 
22
22
  def self.all_symbols
23
- %w(+ - * / = set sum post >= > < <= and or if date get put lookup $lookup $head $tail $reverse round $round $days_ago $hours_ago $minutes_ago $append $id)
23
+ %w(+ - * / = set sum $sub post >= > < <= and or if date get put lookup $lookup $head $tail $reverse round $round $days_ago $hours_ago $minutes_ago $append $id)
24
24
  end
25
25
 
26
26
  module Boolean
@@ -1,3 +1,3 @@
1
1
  module Expressive
2
- VERSION = "0.0.23"
2
+ VERSION = "0.0.24"
3
3
  end
@@ -126,8 +126,10 @@ module Expressive
126
126
  define('<=') {|a,b| a.to_f <= b.to_f }
127
127
  define('and') {|a,b| !!a && !!b }
128
128
  define('or') {|a,b| !!a || !!b }
129
- define('sum') { |*args| args.flatten.map(&:to_f).reduce(:+) || 0 }
130
- define('if') { |*args| args.compact!; args[0] ? args[1] : args[2] }
129
+ define('sum') {|*args| args.flatten.map(&:to_f).reduce(:+) || 0 }
130
+ define('$sum') {|*args| args.flatten.map(&:to_f).reduce(:+) || 0 }
131
+ define('sub') {|*args| result = args.flatten.map(&:to_f).reduce(:-) || 0 }
132
+ define('if') {|*args| args.compact!; args[0] ? args[1] : args[2] }
131
133
  define('$days_ago'){|*args| Time.now - args[0].to_i * 86400 }
132
134
  define('$hours_ago'){|*args| Time.now - args[0].to_i * 3600 }
133
135
  define('$minutes_ago'){|*args| Time.now - args[0].to_i * 60 }
@@ -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 get put post >= > < <= and or if date lookup round $round $days_ago $hours_ago $minutes_ago $append $id $head $lookup $reverse $tail) }
9
+ it { Expressive.all_symbols.should =~ %w(+ - * / = set sum $sub get put post >= > < <= and or if date lookup round $round $days_ago $hours_ago $minutes_ago $append $id $head $lookup $reverse $tail) }
10
10
  end
11
11
 
12
12
  describe "understands booleans" do
@@ -37,6 +37,7 @@ describe "Expressive" do
37
37
  it { Expressive.run("(* 4 2)").should eql 8.0 }
38
38
  it { Expressive.run("(/ 4 2)").should eql 2.0 }
39
39
  it { Expressive.run("(sum 1 2 3)").should eql 6.0 }
40
+ it { Expressive.run("(sub 1 2 3)").should eql -4.0 }
40
41
  it { Expressive.run("(sum )").should eql 0 }
41
42
  it { Expressive.run("(- (sum 1 5 7) 3)").should eql 10.0}
42
43
  it { Expressive.run("(round 0.12345 2)").should eql 0.12}
@@ -79,6 +80,59 @@ describe "Expressive" do
79
80
  it { Expressive.run('(if (<= nil_value 4) "greater" "not so greater")', @scope).should eql "greater" }
80
81
  it { Expressive.run('(if (>= 4 nil_value) "greater" "not so greater")', @scope).should eql "greater" }
81
82
  end
83
+
84
+ context "multiple if statements" do
85
+ before do
86
+ @scope["depth"] = "4mm"
87
+ @statement = <<-EOH
88
+ (if (= depth "8mm") 1
89
+ (if (= depth "7mm") 0.8
90
+ (if (= depth "6mm") 0.65
91
+ (if (= depth "5mm") 0.5
92
+ (if (= depth "4mm") 0.35
93
+ (if (= depth "3mm") 0.2
94
+ (if (= depth "2mm") 0.05 0)
95
+ )
96
+ )
97
+ )
98
+ )
99
+ )
100
+ )
101
+ EOH
102
+ end
103
+ it do
104
+ @scope["depth"] = "8mm"
105
+ Expressive.run(@statement, @scope).should eql 1
106
+ end
107
+ it do
108
+ @scope["depth"] = "7mm"
109
+ Expressive.run(@statement, @scope).should eql 0.8
110
+ end
111
+ it do
112
+ @scope["depth"] = "6mm"
113
+ Expressive.run(@statement, @scope).should eql 0.65
114
+ end
115
+ it do
116
+ @scope["depth"] = "5mm"
117
+ Expressive.run(@statement, @scope).should eql 0.5
118
+ end
119
+ it do
120
+ @scope["depth"] = "4mm"
121
+ Expressive.run(@statement, @scope).should eql 0.35
122
+ end
123
+ it do
124
+ @scope["depth"] = "3mm"
125
+ Expressive.run(@statement, @scope).should eql 0.2
126
+ end
127
+ it do
128
+ @scope["depth"] = "2mm"
129
+ Expressive.run(@statement, @scope).should eql 0.05
130
+ end
131
+ it do
132
+ @scope["depth"] = "1.6mm"
133
+ Expressive.run(@statement, @scope).should eql 0
134
+ end
135
+ end
82
136
  end
83
137
 
84
138
  describe "understands logical statements" 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.23
4
+ version: 0.0.24
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-17 00:00:00.000000000 Z
12
+ date: 2013-06-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby_gntp
@@ -294,7 +294,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
294
294
  version: '0'
295
295
  segments:
296
296
  - 0
297
- hash: 1273434099019022077
297
+ hash: 419564563370159517
298
298
  required_rubygems_version: !ruby/object:Gem::Requirement
299
299
  none: false
300
300
  requirements:
@@ -303,7 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
303
303
  version: '0'
304
304
  segments:
305
305
  - 0
306
- hash: 1273434099019022077
306
+ hash: 419564563370159517
307
307
  requirements: []
308
308
  rubyforge_project:
309
309
  rubygems_version: 1.8.24