ruby_list_comprehension 0.0.9 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92a6a05f9854d7424aa30297fddcdcf38a41d8907158ce1ea307e0b67e9c5a46
4
- data.tar.gz: ef703fa9300a220a78d384809edd66b6084446f5ce63d438f90ee6e437528bfa
3
+ metadata.gz: d2d35273a3ae0a52a219848adb715d96ca5f13dbd0eb500c4ae80ea2cc151977
4
+ data.tar.gz: b5ddeb3771d13d9c314f0bc7588db1d918b79396fe32e4b27b87fa86812d8a53
5
5
  SHA512:
6
- metadata.gz: 958de729eb7b43f1c9c143bb21a7b70050c6ebf547ccce53db30046f9425e87603fb321a198e553f1da182cb28557e7039fb0db5e6bebd7c1a80fa2587828571
7
- data.tar.gz: da4861c121ba2782023036b2c4c232ee5258273b6ba7d9e29b6a6e3d2f5c41e60480b27e7e97886527aa82eef62ccd64a71267fbb24f507ce67d15b9a0fcfa68
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
- # check for semicolon instead of do, for now I replace to do
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
- mdata = y[3...y.rindex('do')].match(/{.+[=>:].+}/)
49
+ return [{}] if iterable == "{}"
46
50
 
47
- if !mdata.nil?
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_list_comprehension
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Michael