excel_to_code 0.1.21 → 0.1.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/src/compile/ruby/map_formulae_to_ruby.rb +2 -0
- data/src/excel/excel_functions.rb +4 -0
- data/src/excel/excel_functions/excel_equal.rb +2 -6
- data/src/excel/excel_functions/len.rb +8 -0
- data/src/excel/excel_functions/not_equal.rb +2 -9
- data/src/excel/excel_functions/substitute.rb +41 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1b2c421597403690e3738e1f56d63952aee2408
|
4
|
+
data.tar.gz: 3fc17ec74fc2d294220e7cf3b319d8cafe67babf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f52431b3047ba767b58f22cd02e5cffc90e4a1eadd207d8dcafe3b00877ea3fc7cfe557f1fc6d1785372bcf7c323fa406af3c01e049a7e891059cb7b60a3cfd4
|
7
|
+
data.tar.gz: 957cf0e0ff469aeba06b08c97013b093f51d5ed8e5a2308e079293a0be2b57c3047f16168418fe5e532911733be2b6f115fd4e4137efd39d70bdd52a08ba716f
|
@@ -34,6 +34,7 @@ class MapFormulaeToRuby < MapValuesToRuby
|
|
34
34
|
'ISNUMBER' => 'isnumber',
|
35
35
|
'LARGE' => 'large',
|
36
36
|
'LEFT' => 'left',
|
37
|
+
'LEN' => 'len',
|
37
38
|
'LOG' => 'log',
|
38
39
|
'MATCH' => 'excel_match',
|
39
40
|
'MAX' => 'max',
|
@@ -49,6 +50,7 @@ class MapFormulaeToRuby < MapValuesToRuby
|
|
49
50
|
'ROUND' => 'round',
|
50
51
|
'ROUNDDOWN' => 'rounddown',
|
51
52
|
'ROUNDUP' => 'roundup',
|
53
|
+
'SUBSTITUTE' => 'substitute',
|
52
54
|
'SUBTOTAL' => 'subtotal',
|
53
55
|
'SUM' => 'sum',
|
54
56
|
'SUMIF' => 'sumif',
|
@@ -8,12 +8,8 @@ module ExcelFunctions
|
|
8
8
|
return a if a.is_a?(Symbol)
|
9
9
|
return b if b.is_a?(Symbol)
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
a.downcase == b.downcase
|
14
|
-
else
|
15
|
-
a == b
|
16
|
-
end
|
11
|
+
return a.downcase == b.downcase if a.is_a?(String) && b.is_a?(String)
|
12
|
+
a == b
|
17
13
|
|
18
14
|
end
|
19
15
|
|
@@ -3,17 +3,10 @@ require_relative 'apply_to_range'
|
|
3
3
|
module ExcelFunctions
|
4
4
|
|
5
5
|
def not_equal?(a,b)
|
6
|
-
# return apply_to_range(a,b) { |a,b| not_equal?(a,b) } if a.is_a?(Array) || b.is_a?(Array)
|
7
|
-
|
8
6
|
return a if a.is_a?(Symbol)
|
9
7
|
return b if b.is_a?(Symbol)
|
10
|
-
|
11
|
-
|
12
|
-
when String
|
13
|
-
a.downcase != b.downcase
|
14
|
-
else
|
15
|
-
a != b
|
16
|
-
end
|
8
|
+
return a.downcase != b.downcase if a.is_a?(String) && b.is_a?(String)
|
9
|
+
a != b
|
17
10
|
end
|
18
11
|
|
19
12
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ExcelFunctions
|
2
|
+
|
3
|
+
def substitute(text, old_text, new_text, instance_num = :any)
|
4
|
+
# Check for errors
|
5
|
+
return text if text.is_a?(Symbol)
|
6
|
+
return old_text if old_text.is_a?(Symbol)
|
7
|
+
return new_text if new_text.is_a?(Symbol)
|
8
|
+
# Nils get turned into blanks
|
9
|
+
text ||= ""
|
10
|
+
new_text ||= ""
|
11
|
+
old_text ||= ""
|
12
|
+
return text if old_text == ""
|
13
|
+
# Booleans get made into text, but need to be TRUE not true
|
14
|
+
text = text.to_s.upcase if text.is_a?(TrueClass) || text.is_a?(FalseClass)
|
15
|
+
old_text = old_text.to_s.upcase if old_text.is_a?(TrueClass) || old_text.is_a?(FalseClass)
|
16
|
+
new_text = new_text.to_s.upcase if new_text.is_a?(TrueClass) || new_text.is_a?(FalseClass)
|
17
|
+
# Other items get turned into text
|
18
|
+
text = text.to_s
|
19
|
+
old_text = old_text.to_s
|
20
|
+
new_text = new_text.to_s
|
21
|
+
# Now split based on whether instance_num is passed
|
22
|
+
if instance_num == :any
|
23
|
+
# The easy case
|
24
|
+
text.gsub(old_text, new_text)
|
25
|
+
else
|
26
|
+
# The harder case
|
27
|
+
return instance_num if instance_num.is_a?(Symbol)
|
28
|
+
return :value unless instance_num.to_i > 0
|
29
|
+
instances_found = 0
|
30
|
+
text.gsub(old_text) do |match|
|
31
|
+
instances_found += 1
|
32
|
+
if instances_found == instance_num
|
33
|
+
new_text
|
34
|
+
else
|
35
|
+
old_text
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: excel_to_code
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Counsell, Green on Black Ltd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubypeg
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- src/excel/excel_functions/isnumber.rb
|
141
141
|
- src/excel/excel_functions/large.rb
|
142
142
|
- src/excel/excel_functions/left.rb
|
143
|
+
- src/excel/excel_functions/len.rb
|
143
144
|
- src/excel/excel_functions/less_than.rb
|
144
145
|
- src/excel/excel_functions/less_than_or_equal.rb
|
145
146
|
- src/excel/excel_functions/log.rb
|
@@ -163,6 +164,7 @@ files:
|
|
163
164
|
- src/excel/excel_functions/rounddown.rb
|
164
165
|
- src/excel/excel_functions/roundup.rb
|
165
166
|
- src/excel/excel_functions/string_join.rb
|
167
|
+
- src/excel/excel_functions/substitute.rb
|
166
168
|
- src/excel/excel_functions/subtotal.rb
|
167
169
|
- src/excel/excel_functions/subtract.rb
|
168
170
|
- src/excel/excel_functions/sum.rb
|
@@ -263,3 +265,4 @@ specification_version: 4
|
|
263
265
|
summary: Converts .xlxs files into pure ruby 1.9 code or pure C code so that they
|
264
266
|
can be executed without excel
|
265
267
|
test_files: []
|
268
|
+
has_rdoc: false
|