excel_to_code 0.3.16 → 0.3.17

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: 17eac22412740a67afd06333f437ce950c03c32d
4
- data.tar.gz: 1117fdcb2343478712dc0a72649c429d1b9dc8dd
3
+ metadata.gz: a6c7853f4e0ce66da8f073d561bbd0dabd2a390d
4
+ data.tar.gz: b9e44bda2488d15ede19254374a9b19fb1320762
5
5
  SHA512:
6
- metadata.gz: 5023ee51c9f7a3909c7768ca58da98c368e3bec955a50e67c33df96387e2052e8c3c734f062c894b9102629509582232c7c08d62fd21b9fe718d1f678d6558fa
7
- data.tar.gz: e34fd8293696f90562080eeb0f07db35a131d4132883baf62a5edf57f2fa37e36a699a16d355899e27c65c0a13dc262e143e30917593aed1a358868cc6108783
6
+ metadata.gz: aed1ca40db11c54a816035989e1f68427028dbd2ed3c7328e134efa225842b52c72e6db1df32090d75a45da8d95caa29102b52a028d413ff397ecd946d4dfed9
7
+ data.tar.gz: 87131c81c57f7d7705833b0f18f14e797fb553c304367f47c688c1c6593feaebd9589e278fbb92792add54442cdfa833508187ff090fd60169754f9332c0486a
@@ -1051,6 +1051,7 @@ class ExcelToX
1051
1051
  raise
1052
1052
  end
1053
1053
  end
1054
+
1054
1055
 
1055
1056
  @named_references.each do |ref, ast|
1056
1057
  inline_replacer.current_sheet_name = ref.is_a?(Array) ? [ref.first] : []
Binary file
@@ -85,6 +85,7 @@ static ExcelValue min(int number_of_arguments, ExcelValue *arguments);
85
85
  static ExcelValue mmult(ExcelValue a_v, ExcelValue b_v);
86
86
  static ExcelValue mod(ExcelValue a_v, ExcelValue b_v);
87
87
  static ExcelValue negative(ExcelValue a_v);
88
+ static ExcelValue number_or_zero(ExcelValue maybe_number_v);
88
89
  static ExcelValue npv(ExcelValue rate, int number_of_arguments, ExcelValue *arguments);
89
90
  static ExcelValue pmt(ExcelValue rate_v, ExcelValue number_of_periods_v, ExcelValue present_value_v);
90
91
  static ExcelValue pmt_4(ExcelValue rate_v, ExcelValue number_of_periods_v, ExcelValue present_value_v, ExcelValue final_value_v);
@@ -341,6 +342,16 @@ static ExcelValue ensure_is_number(ExcelValue maybe_number_v) {
341
342
  return EXCEL_NUMBER(maybe_number);
342
343
  }
343
344
 
345
+ static ExcelValue number_or_zero(ExcelValue maybe_number_v) {
346
+ if(maybe_number_v.type == ExcelNumber) {
347
+ return maybe_number_v;
348
+ }
349
+ if(maybe_number_v.type == ExcelError) {
350
+ return maybe_number_v;
351
+ }
352
+ return ZERO;
353
+ }
354
+
344
355
  static ExcelValue excel_log(ExcelValue number) {
345
356
  return excel_log_2(number, TEN);
346
357
  }
@@ -955,7 +955,17 @@ int test_functions() {
955
955
  assert(ensure_is_number(EXCEL_STRING("1.3")).number == 1.3);
956
956
  assert(ensure_is_number(EXCEL_STRING("BASDASD")).type == ExcelError);
957
957
  assert(ensure_is_number(DIV0).type == ExcelError);
958
-
958
+
959
+ // Tests ther NUMBER_OR_ZERO function
960
+ assert_equal(ZERO, number_or_zero(ZERO), "number_or_zero 0");
961
+ assert_equal(ONE, number_or_zero(ONE), "number_or_zero 1");
962
+ assert_equal(VALUE, number_or_zero(VALUE), "number_or_zero :error");
963
+ assert_equal(ZERO, number_or_zero(TRUE), "number_or_zero true");
964
+ assert_equal(ZERO, number_or_zero(FALSE), "number_or_zero false");
965
+ assert_equal(ZERO, number_or_zero(BLANK), "number_or_zero blank");
966
+ assert_equal(ZERO, number_or_zero(EXCEL_STRING("1.3")), "number_or_zero '1.3'");
967
+ assert_equal(ZERO, number_or_zero(EXCEL_STRING("Aasdfadsf")), "number_or_zero 'Asdfad'");
968
+
959
969
  // RIGHT(string,[characters])
960
970
  // ... should return the right n characters from a string
961
971
  assert(strcmp(right_1(EXCEL_STRING("ONE")).string,"E") == 0);
@@ -69,6 +69,7 @@ class MapFormulaeToC < MapValuesToC
69
69
  :'MMULT' => 'mmult',
70
70
  :'MOD' => 'mod',
71
71
  :'NPV' => 'npv',
72
+ :'NUMBER_OR_ZERO' => 'number_or_zero',
72
73
  :'PMT3' => 'pmt',
73
74
  :'PMT4' => 'pmt_4',
74
75
  :'PMT5' => 'pmt_5',
@@ -55,6 +55,7 @@ class MapFormulaeToRuby < MapValuesToRuby
55
55
  :'MMULT' => 'mmult',
56
56
  :'MOD' => 'mod',
57
57
  :'NPV' => 'npv',
58
+ :'NUMBER_OR_ZERO' => 'number_or_zero',
58
59
  :'PI' => 'pi',
59
60
  :'PMT' => 'pmt',
60
61
  :'POWER' => 'power',
@@ -121,3 +121,5 @@ require_relative 'excel_functions/iserror'
121
121
  require_relative 'excel_functions/char'
122
122
 
123
123
  require_relative 'excel_functions/address'
124
+
125
+ require_relative 'excel_functions/number_or_zero'
@@ -21,7 +21,7 @@ module ExcelFunctions
21
21
  when Numeric
22
22
  return a
23
23
  when Array
24
- return a[0][0]
24
+ return number_argument(a[0][0])
25
25
  else
26
26
  return :value
27
27
  end
@@ -0,0 +1,9 @@
1
+ module ExcelFunctions
2
+
3
+ def number_or_zero(a)
4
+ return a if a.is_a?(Symbol)
5
+ return a if a.is_a?(Numeric)
6
+ 0
7
+ end
8
+
9
+ end
@@ -1,5 +1,5 @@
1
1
  class ExcelToCode
2
- def self.version() "0.3.16" end
2
+ def self.version() "0.3.17" end
3
3
  end
4
4
 
5
5
  require_relative 'commands'
@@ -97,6 +97,11 @@ class MapFormulaeToValues
97
97
  return ast if ast[0] == :function && ast[1] == :ENSURE_IS_NUMBER
98
98
  [:function, :ENSURE_IS_NUMBER, ast]
99
99
  end
100
+
101
+ def number_or_zero(ast)
102
+ return ast if ast[0] == :function && ast[1] == :NUMBER_OR_ZERO
103
+ [:function, :NUMBER_OR_ZERO, ast]
104
+ end
100
105
 
101
106
  def comparison(ast)
102
107
  left, operator, right = ast[1], ast[2], ast[3]
@@ -336,12 +341,12 @@ class MapFormulaeToValues
336
341
  # FIXME: Will I be haunted by this? What if doing a sum of something that isn't a number
337
342
  # and so what is expected is a VALUE error?. YES. This doesn't work well.
338
343
  elsif ast.length == 3 && [:cell, :sheet_reference].include?(ast[2].first)
339
- new_ast = n(ast[2])
344
+ new_ast = number_or_zero(ast[2])
340
345
  if new_ast != ast
341
346
  @replacements_made_in_the_last_pass += 1
342
347
  ast.replace(new_ast)
343
348
  end
344
- elsif ast.length == 3 && ast[2][0] == :function && ast[2][1] == :ENSURE_IS_NUMBER
349
+ elsif ast.length == 3 && ast[2][0] == :function && ast[2][1] == :NUMBER_OR_ZERO
345
350
  new_ast = ast[2]
346
351
  if new_ast != ast
347
352
  @replacements_made_in_the_last_pass += 1
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.3.16
4
+ version: 0.3.17
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: 2015-05-12 00:00:00.000000000 Z
11
+ date: 2015-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubypeg
@@ -197,6 +197,7 @@ files:
197
197
  - src/excel/excel_functions/not_equal.rb
198
198
  - src/excel/excel_functions/npv.rb
199
199
  - src/excel/excel_functions/number_argument.rb
200
+ - src/excel/excel_functions/number_or_zero.rb
200
201
  - src/excel/excel_functions/pi.rb
201
202
  - src/excel/excel_functions/pmt.rb
202
203
  - src/excel/excel_functions/power.rb