delorean_lang 0.0.40 → 0.0.42

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/lib/delorean/base.rb CHANGED
@@ -36,6 +36,8 @@ module Delorean
36
36
  ######################################################################
37
37
 
38
38
  def self._index(obj, args, _e)
39
+ return nil if obj.nil?
40
+
39
41
  if obj.instance_of?(Hash)
40
42
  raise InvalidIndex unless args.length == 1
41
43
  obj[args[0]]
@@ -42,4 +42,7 @@ module Delorean
42
42
  class UndefinedParamError < StandardError
43
43
  end
44
44
 
45
+ class InvalidIndex < StandardError
46
+ end
47
+
45
48
  end
@@ -82,7 +82,8 @@ module Delorean
82
82
  raise "Can only access date part of Infinity"
83
83
  end
84
84
 
85
- raise "non-time arg to TIMEPART" unless time.is_a?(Time)
85
+ raise "non-time arg to TIMEPART" unless
86
+ time.is_a?(DateTime) || time.is_a?(Time)
86
87
 
87
88
  case part
88
89
  when "h" then time.hour
@@ -159,6 +160,7 @@ module Delorean
159
160
  uniq: [Array],
160
161
  length: [[Array, String]],
161
162
  flatten: [Array, [Fixnum, nil]],
163
+ slice: [Array, Fixnum, Fixnum],
162
164
  }
163
165
 
164
166
  def RUBY(_e, method, *args)
@@ -186,7 +188,7 @@ module Delorean
186
188
 
187
189
  args[0].send(msg, *args[1, args.length])
188
190
  end
189
-
191
+
190
192
  RUBY_SIG = [ 1, Float::INFINITY ]
191
193
 
192
194
  ######################################################################
@@ -1,3 +1,3 @@
1
1
  module Delorean
2
- VERSION = "0.0.40"
2
+ VERSION = "0.0.42"
3
3
  end
data/spec/func_spec.rb CHANGED
@@ -217,6 +217,7 @@ describe "Delorean" do
217
217
  " e = RUBY('sort', dd)",
218
218
  " f = RUBY('uniq', e)",
219
219
  " g = RUBY('length', e)",
220
+ " gg = RUBY('length', a)",
220
221
  )
221
222
 
222
223
  engine.evaluate("A", "c").should == x.flatten(1)
@@ -225,6 +226,16 @@ describe "Delorean" do
225
226
  engine.evaluate("A", "e").should == dd.sort
226
227
  engine.evaluate("A", "f").should == dd.sort.uniq
227
228
  engine.evaluate("A", "g").should == dd.length
229
+ engine.evaluate("A", "gg").should == x.length
228
230
  end
229
231
 
232
+ it "should handle RUBY slice function" do
233
+ x = [[1, 2, [-3]], 4, [5, 6], -3, 4, 5, 0]
234
+
235
+ engine.parse defn("A:",
236
+ " a = #{x}",
237
+ " b = RUBY('slice',a,0,4)",
238
+ )
239
+ engine.evaluate("A", "b").should == x.slice(0,4)
240
+ end
230
241
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delorean_lang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.40
4
+ version: 0.0.42
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-02-19 00:00:00.000000000 Z
12
+ date: 2013-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: treetop