ruby_list_comprehension 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby_list_comprehension.rb +25 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2d35273a3ae0a52a219848adb715d96ca5f13dbd0eb500c4ae80ea2cc151977
|
4
|
+
data.tar.gz: b5ddeb3771d13d9c314f0bc7588db1d918b79396fe32e4b27b87fa86812d8a53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 302c90d601a6affe56d8a06567ec6ea3071f216e274131f7184185a082e77ebd7b6a23752feb6222a602fbb84828ed6fcbc1511c381728ddf86af26d0c4d4156
|
7
|
+
data.tar.gz: 8a60c0e66d4e6defc8a3b728cc2b4a656ac8c12237a14a96d51447b440049bd0234c4b07fcd29b68fc0cfb5ae8519a9f301d69ef95202a1bde00b73b4c883d8a
|
@@ -14,8 +14,10 @@ class ListComprehension
|
|
14
14
|
@caching = true
|
15
15
|
@version = RUBY_VERSION
|
16
16
|
@c = lambda { |x| # check for cached results
|
17
|
-
|
17
|
+
return [] if x == ''
|
18
|
+
x.concat(' end')if x[-3..-1] != 'end'
|
18
19
|
return @cache[x] if @caching && @cache[x]
|
20
|
+
|
19
21
|
# p "cached: #{@cache[arr].to_s}" if @cache[arr]
|
20
22
|
|
21
23
|
y = x[0..-1] # copy of original call
|
@@ -26,8 +28,10 @@ class ListComprehension
|
|
26
28
|
raise 'please use "x" as block parameter name for now' if x[3..5] != ' x '
|
27
29
|
|
28
30
|
arr = x.split
|
29
|
-
|
30
|
-
|
31
|
+
if !arr.include?('do')
|
32
|
+
arr.insert(5, 'do')
|
33
|
+
end
|
34
|
+
# replace initial semicolon with do if needed for parser
|
31
35
|
if arr[3][-1] == ';' || arr[4][0] == ';' || arr[5][0] == ';' && !arr.include?('do')
|
32
36
|
arr = x.to_s.sub(';', ' do ').split
|
33
37
|
end
|
@@ -42,11 +46,25 @@ class ListComprehension
|
|
42
46
|
|
43
47
|
# check for hash to parse csv's
|
44
48
|
iterable = arr[3]
|
45
|
-
|
49
|
+
return [{}] if iterable == "{}"
|
46
50
|
|
47
|
-
|
51
|
+
mdata = y[3...y.rindex('do')].match(/{.+[=>:].+}/)
|
52
|
+
if mdata && mdata[0].include?(';')
|
53
|
+
# p 'hi'
|
54
|
+
iterable = mdata[0].split(';')[0]
|
55
|
+
# p iterable
|
56
|
+
# p arr.insert(5, "do")
|
57
|
+
end
|
58
|
+
if mdata
|
48
59
|
if instance_eval(mdata[0]).is_a? Hash
|
49
60
|
iterable = mdata[0]
|
61
|
+
p mdata[0]
|
62
|
+
p iterable
|
63
|
+
p arr
|
64
|
+
|
65
|
+
if iterable[-1] == ';'
|
66
|
+
iterable = iterable[0..-1]
|
67
|
+
end
|
50
68
|
end
|
51
69
|
end
|
52
70
|
|
@@ -83,7 +101,6 @@ class ListComprehension
|
|
83
101
|
end
|
84
102
|
else
|
85
103
|
@op = 'map&compact'
|
86
|
-
# p 'map&compact'
|
87
104
|
return instance_eval(iterable).map do |x|
|
88
105
|
instance_eval(map_condition.join(' ')) if instance_eval(if_condition.join(' '))
|
89
106
|
end.compact!
|
@@ -93,8 +110,9 @@ class ListComprehension
|
|
93
110
|
unless list_comp.is_a?(Array) || list_comp.is_a?(Hash)
|
94
111
|
list_comp = [list_comp]
|
95
112
|
end
|
113
|
+
|
114
|
+
list_comp = list_comp == [nil] ? [] : list_comp
|
96
115
|
@cache[arr] = list_comp if @caching
|
97
|
-
list_comp == [nil] ? [] : list_comp
|
98
116
|
}
|
99
117
|
end
|
100
118
|
end
|