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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4ebae76600b8d182956b7c1f6a0d98617cb7aeb
4
- data.tar.gz: 07751fc9af519871db9f60f6011b8de21ee0e6f8
3
+ metadata.gz: f1b2c421597403690e3738e1f56d63952aee2408
4
+ data.tar.gz: 3fc17ec74fc2d294220e7cf3b319d8cafe67babf
5
5
  SHA512:
6
- metadata.gz: 46b666e419461ce012bf8e2f84e2c6b97996943c4d41590c3260e10bbf3de827b4ca6e96caa10f99d16afa80785fea8c6179dc36b0e7f3c58b1a3886f1853daf
7
- data.tar.gz: e694dff8476a31eea15131fadb9fa44ddf8d77839ce3ab5e525d40a4ba4307d97ebbfa485a4b9bb4847a05663cbe2970db576d92ab52d21c327904f4f6df97d4
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',
@@ -89,3 +89,7 @@ require_relative 'excel_functions/mmult'
89
89
  require_relative 'excel_functions/rank'
90
90
 
91
91
  require_relative 'excel_functions/isnumber'
92
+
93
+ require_relative 'excel_functions/len'
94
+
95
+ require_relative 'excel_functions/substitute'
@@ -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
- case a
12
- when String
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
 
@@ -0,0 +1,8 @@
1
+ module ExcelFunctions
2
+
3
+ def len(a)
4
+ return a if a.is_a?(Symbol)
5
+ a.to_s.length
6
+ end
7
+
8
+ end
@@ -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
- case a
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.21
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-19 00:00:00.000000000 Z
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