expressive 0.0.18 → 0.0.20

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- expressive (0.0.18)
4
+ expressive (0.0.20)
5
5
  awesome_print (~> 1.0.2)
6
6
  json
7
7
  polyglot (~> 0.3.3)
@@ -17,23 +17,30 @@ GEM
17
17
  crack (0.3.1)
18
18
  diff-lcs (1.1.3)
19
19
  ffi (1.1.5)
20
+ ffi (1.1.5-java)
20
21
  guard (1.3.2)
21
22
  listen (>= 0.4.2)
22
23
  thor (>= 0.14.6)
23
24
  guard-rspec (1.2.1)
24
25
  guard (>= 1.1)
25
26
  json (1.7.4)
27
+ json (1.7.4-java)
26
28
  listen (0.4.7)
27
29
  rb-fchange (~> 0.0.5)
28
30
  rb-fsevent (~> 0.9.1)
29
31
  rb-inotify (~> 0.8.8)
30
32
  method_source (0.8)
31
- mime-types (1.21)
33
+ mime-types (1.22)
32
34
  polyglot (0.3.3)
33
35
  pry (0.9.10)
34
36
  coderay (~> 1.0.5)
35
37
  method_source (~> 0.8)
36
38
  slop (~> 3.3.1)
39
+ pry (0.9.10-java)
40
+ coderay (~> 1.0.5)
41
+ method_source (~> 0.8)
42
+ slop (~> 3.3.1)
43
+ spoon (~> 0.0)
37
44
  rake (10.0.0)
38
45
  rb-fchange (0.0.5)
39
46
  ffi
@@ -54,6 +61,8 @@ GEM
54
61
  rspec-mocks (2.11.2)
55
62
  ruby_gntp (0.3.4)
56
63
  slop (3.3.2)
64
+ spoon (0.0.3)
65
+ ffi
57
66
  thor (0.16.0)
58
67
  timecop (0.5.3)
59
68
  treetop (1.4.12)
@@ -64,6 +73,7 @@ GEM
64
73
  crack (>= 0.1.7)
65
74
 
66
75
  PLATFORMS
76
+ java
67
77
  ruby
68
78
 
69
79
  DEPENDENCIES
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 post >= > < <= and or if date get put lookup round $days_ago $hours_ago $minutes_ago $append $id)
23
+ %w(+ - * / = set sum post >= > < <= and or if date get put lookup $lookup $head $tail $reverse 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.18"
2
+ VERSION = "0.0.20"
3
3
  end
data/lib/scope.rb CHANGED
@@ -88,19 +88,9 @@ module Expressive
88
88
  end
89
89
  end
90
90
 
91
- syntax('lookup') do |scope, cells|
92
- lookup_result = scope.lookups[cells.first.text_value]
93
- if lookup_result
94
- key = cells[1] ? cells[1].text_value[1..-2] : nil
95
- if lookup_result.is_a?(Hash)
96
- lookup_result[key]
97
- elsif lookup_result.is_a?(Array)
98
- options = lookup_result.first
99
- the_proc = lookup_result.last
100
- the_proc.call(options, key, *Array(cells[2..-1]).map {|cell| cell.eval(scope)})
101
- end
102
- end
103
- end
91
+
92
+ syntax('$lookup') {|scope, cells| perform_lookup(scope, cells)}
93
+ syntax('lookup') {|scope, cells| perform_lookup(scope, cells)}
104
94
 
105
95
  syntax('post') do |scope, cells|
106
96
  perform_webhook(:post, scope, cells)
@@ -138,10 +128,16 @@ module Expressive
138
128
  define('or') {|a,b| !!a || !!b }
139
129
  define('sum') { |*args| args.flatten.map(&:to_f).reduce(:+) || 0 }
140
130
  define('if') { |*args| args.compact!; args[0] ? args[1] : args[2] }
141
- define('round'){|*args| args[0].to_f.round(args[1]) }
142
131
  define('$days_ago'){|*args| Time.now - args[0].to_i * 86400 }
143
132
  define('$hours_ago'){|*args| Time.now - args[0].to_i * 3600 }
144
133
  define('$minutes_ago'){|*args| Time.now - args[0].to_i * 60 }
134
+ define('$head'){|*args| args.flatten.first }
135
+ define('$tail'){|*args| args.flatten[1..-1] }
136
+ define('$reverse'){|*args| args.flatten.reverse }
137
+
138
+ define('$round'){|*args| perform_round(args) }
139
+ define('round'){|*args| perform_round(args) }
140
+
145
141
  end
146
142
 
147
143
  def to_hash
@@ -153,6 +149,24 @@ module Expressive
153
149
 
154
150
  #(post "http://example.com" "*" (headers "AUTH-TOKEN=13415") )
155
151
  #(post "http://example.com" name email john smith (headers "AUTH-TOKEN=13415") )
152
+ def perform_round(*args)
153
+ tuple = args.first
154
+ tuple[0].to_f.round(tuple[1])
155
+ end
156
+
157
+ def perform_lookup(scope, cells)
158
+ lookup_result = scope.lookups[cells.first.text_value]
159
+ if lookup_result
160
+ key = cells[1] ? cells[1].text_value[1..-2] : nil
161
+ if lookup_result.is_a?(Hash)
162
+ lookup_result[key]
163
+ elsif lookup_result.is_a?(Array)
164
+ options = lookup_result.first
165
+ the_proc = lookup_result.last
166
+ the_proc.call(options, key, *Array(cells[2..-1]).map {|cell| cell.eval(scope)})
167
+ end
168
+ end
169
+ end
156
170
 
157
171
  def perform_webhook(verb, scope, cells)
158
172
  #convert cells to array so it can manipulated easily
@@ -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 $days_ago $hours_ago $minutes_ago $append $id) }
9
+ it { Expressive.all_symbols.should =~ %w(+ - * / = set sum get put post >= > < <= and or if date lookup round $days_ago $hours_ago $minutes_ago $append $id $head $lookup $reverse $tail) }
10
10
  end
11
11
 
12
12
  describe "understands booleans" do
@@ -53,6 +53,12 @@ describe "Expressive" do
53
53
  it { Expressive.run("(<= 4 4)").should eql true }
54
54
  end
55
55
 
56
+ describe "understands list operations" do
57
+ it { Expressive.run("($head (1 2 3))").should eql 1 }
58
+ it { Expressive.run("($tail (1 2 3))").should eql [2, 3] }
59
+ it { Expressive.run("($reverse (1 2 3))").should eql [3 ,2 ,1] }
60
+ end
61
+
56
62
  describe "understands compound statements" do
57
63
  it { Expressive.run("(= (+ 4 2) 6)").should eql true }
58
64
  it { Expressive.run("(if (and (< 3 9) (> 2 1)), true, false)").should eql true }
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.18
4
+ version: 0.0.20
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-04-01 00:00:00.000000000 Z
12
+ date: 2013-04-23 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: -2330211989650066237
297
+ hash: -973593716025882143
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: -2330211989650066237
306
+ hash: -973593716025882143
307
307
  requirements: []
308
308
  rubyforge_project:
309
309
  rubygems_version: 1.8.23