expressive 0.0.25 → 0.0.26

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- expressive (0.0.25)
4
+ expressive (0.0.26)
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 $sub 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 datetime get put lookup $lookup $head $tail $reverse round $round $days_ago $hours_ago $minutes_ago $append $id $hash)
24
24
  end
25
25
 
26
26
  module Boolean
@@ -1,3 +1,3 @@
1
1
  module Expressive
2
- VERSION = "0.0.25"
2
+ VERSION = "0.0.26"
3
3
  end
@@ -21,7 +21,7 @@ grammar Expressive
21
21
  end
22
22
 
23
23
  rule word
24
- [a-zA-Z]+
24
+ [a-zA-Z0-9_]+
25
25
  end
26
26
 
27
27
  rule string
@@ -88,6 +88,17 @@ module Expressive
88
88
  end
89
89
  end
90
90
 
91
+ syntax('$hash') do |scope, cells|
92
+ puts "$hash..."
93
+ hash = {}
94
+ cells.each do |cell|
95
+ key = cell.elements[1].elements[0].elements[1].text_value
96
+ value = cell.elements[1].elements[1].elements[1].instance_eval{eval(scope)}
97
+ puts value.class
98
+ hash[key] = value
99
+ end
100
+ hash
101
+ end
91
102
 
92
103
  syntax('$lookup') {|scope, cells| perform_lookup(scope, cells)}
93
104
  syntax('lookup') {|scope, cells| perform_lookup(scope, cells)}
@@ -113,6 +124,14 @@ module Expressive
113
124
  Date.new(values[0], values[1], values[2]).to_time.utc
114
125
  end
115
126
  end
127
+ syntax('datetime') do |scope, cells|
128
+ if cells.empty?
129
+ DateTime.now
130
+ else
131
+ date = cells.first.text_value.gsub(/[\)\(]/, '')
132
+ DateTime.parse(date)
133
+ end
134
+ end
116
135
 
117
136
  define('$id') {|*args| args.first.id }
118
137
  define('+') {|a,b| a.to_f + b.to_f }
@@ -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 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 datetime lookup round $round $days_ago $hours_ago $minutes_ago $append $id $head $lookup $reverse $tail $hash) }
10
10
  end
11
11
 
12
12
  describe "understands booleans" do
@@ -26,6 +26,15 @@ describe "Expressive" do
26
26
  it { Expressive.run('"hello world false"').should eql "hello world false" }
27
27
  end
28
28
 
29
+ describe "understands hash values" do
30
+ it { Expressive.run('($hash (test "value"))').should eql ({"test" => "value"})}
31
+ it { Expressive.run('($hash (test 5))').should eql ({"test" => 5})}
32
+ it { Expressive.run('($hash (test 5.3))').should eql ({"test" => 5.3})}
33
+ it { Expressive.run('($hash (test "value") (test2 64))').should eql ({"test" => "value", "test2" => 64})}
34
+ it { Expressive.run('($hash (test "value") (test2 (date)))').should eql ({"test" => "value", "test2" => Time.parse(Date.today.to_s).utc})}
35
+ it { Expressive.run('($hash (test "value") (test2 (date)) (key ($hash (within "a_hash"))))').should eql ({"test" => "value", "test2" => Time.parse(Date.today.to_s).utc, "key" => {"within" => "a_hash"}})}
36
+ end
37
+
29
38
  it "understands variables" do
30
39
  @scope["hello"] = "World"
31
40
  Expressive.run("hello", @scope).should eql "World"
@@ -179,6 +188,20 @@ EOH
179
188
  end
180
189
  end
181
190
 
191
+ describe "understands datetime parsing" do
192
+ it "will return the current date and time" do
193
+ Timecop.freeze(DateTime.now) do
194
+ now = DateTime.now
195
+ Expressive.run('(datetime)').should eql now
196
+ end
197
+ end
198
+
199
+ it "will return a date and time parsed from text" do
200
+ date = DateTime.parse("22nd November 2012 13:04")
201
+ Expressive.run('(datetime(22/11/2012 13:04:00))').should eql date
202
+ end
203
+ end
204
+
182
205
  describe "understands using lookup tables" do
183
206
  before(:each) do
184
207
  @user1 = mock(:user, id:1, login: "user1", display_name: "User 1")
@@ -215,8 +238,13 @@ EOH
215
238
  Expressive.run('($append participating_teams (1 2 3))', @scope)
216
239
  @scope['participating_teams'].should == [0, 1, 2, 3]
217
240
  end
241
+ it "add a hash to a list of values" do
242
+ @scope['documents'] = []
243
+ Expressive.run('($append documents ($hash (test "value") (another_test 53.2) (and_a_date (date))))', @scope)
244
+ @scope['documents'].should == [{"test" => "value", "another_test" => 53.2, "and_a_date" => Time.parse(Date.today.to_s).utc}]
245
+ end
218
246
  end
219
-
247
+
220
248
  describe "understands retrieving the id of an object" do
221
249
  it do
222
250
  @scope["an_object"] = mock(:an_object, id: 5)
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.25
4
+ version: 0.0.26
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-06-10 00:00:00.000000000 Z
12
+ date: 2013-06-26 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: -1947057546795348556
297
+ hash: 4009429271067879068
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: -1947057546795348556
306
+ hash: 4009429271067879068
307
307
  requirements: []
308
308
  rubyforge_project:
309
309
  rubygems_version: 1.8.24