excel_functions 0.0.2 → 0.0.3

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.
data/README.md CHANGED
@@ -25,7 +25,7 @@ This gem can be used in 2 ways.
25
25
  2. Use the `Excel.<function>` style anywhere.
26
26
 
27
27
  #TODO
28
- - more docs about the functions themselves, for now, you can take a look at the code
28
+ - more docs about the functions themselves, for now, you can take a look at the code, or the [Yard Documentation](http://rubydoc.info/gems/excel_functions/)
29
29
 
30
30
  ## Contributing
31
31
 
@@ -1,24 +1,30 @@
1
1
  #file containing the financial functions
2
2
  module ExcelFunctions
3
- # attempt to implement http://office.microsoft.com/en-sg/excel-help/npv-HP005209199.aspx
3
+ #Calculates the net present value of an investment by using a discount rate and a series of future payments (negative values) and income (positive values).
4
+ # @param rate is the rate of discount over the length of one period.
5
+ # @param *values are 1 to 29 arguments representing the payments and income.
6
+ # @return net present value of an investment
7
+ # @see http://office.microsoft.com/en-sg/excel-help/npv-HP005209199.aspx Specification
4
8
  def npv(rate,*values)
5
9
  #If n is the number of cash flows in the list of values, the formula for NPV is:
6
10
  # sum upto n (values[i]/(1+rate)^i)
7
11
  values.each_with_index.inject(0){|sum,(val, index)| sum + val/((1.0+rate)**(index+1))}
8
12
  end
9
13
 
10
- #http://office.microsoft.com/en-sg/excel-help/pmt-HP005209215.aspx
11
14
  #Calculates the payment for a loan based on constant payments and a constant interest rate.
12
- # Rate is the interest rate for the loan.
13
- # Nper is the total number of payments for the loan.
14
- # Pv is the present value, or the total amount that a series of future payments is worth now; also known as the principal.
15
- # Fv is the future value, or a cash balance you want to attain after the last payment is made. If fv is omitted, it is assumed to be 0 (zero), that is, the future value of a loan is 0.
16
- # Type is the number 0 (zero) or 1 and indicates when payments are due.
17
- # Set type equal to If payments are due
18
- # 0 or omitted At the end of the period
19
- # 1 At the beginning of the period
20
- # full formula at http://www.getobjects.com/Components/Finance/TVM/formulas.html
21
- #first 3 params at http://answers.yahoo.com/question/index?qid=20080822070859AAY94ZT
15
+ # @param rate is the interest rate for the loan.
16
+ # @param nper is the total number of payments for the loan.
17
+ # @param pv is the present value, or the total amount that a series of future payments is worth now; also known as the principal.
18
+ # @param fv is the future value, or a cash balance you want to attain after the last payment is made. If fv is omitted, it is assumed to be 0 (zero), that is, the future value of a loan is 0.
19
+ # @param type is the number 0 (zero) or 1 and indicates when payments are due.
20
+ #
21
+ # Set type equal to
22
+ # 0 or omitted If payments are due At the end of the period or
23
+ # 1 If payments are due At the beginning of the period
24
+ # @return [Float] payment for a loan based on the inputs
25
+ # @see http://office.microsoft.com/en-sg/excel-help/pmt-HP005209215.aspx Specification
26
+ # @see http://answers.yahoo.com/question/index?qid=20080822070859AAY94ZT formula using first 3 params
27
+ # @see http://www.getobjects.com/Components/Finance/TVM/formulas.html Full Formula
22
28
  def pmt(rate,nper,pv,fv =0,type = 0)
23
29
  #- pv/((1 - (1 / (1 + rate)**nper )) / rate)
24
30
  pv = -pv
@@ -1,23 +1,30 @@
1
1
  #file containing the lookup based functions
2
2
  module ExcelFunctions
3
- #attempt to implement http://www.techonthenet.com/excel/formulas/lookup.php
3
+ #The LOOKUP function searches for the value in the lookup_range and returns the value from the same position in the result_range.
4
+ #If this parameter is omitted, the LOOKUP function will return the first column of data.
5
+ #In Syntax #2, the LOOKUP function searches for the value in the first row or column of the array and returns the corresponding value in the last row or column of the array.
6
+ #@param value the value to be searched for
7
+ #@param [Array] lookup_array the array in which the value is looked for, and possibly the result is fetched from
8
+ #@param [Array] output_array If given, the result is fetched from this array
9
+ # @return Returns the value in the output_array or the last column of the lookup_array from the same position in the result_range
10
+ # @return If the LOOKUP function can not find an exact match, it chooses the largest value in the lookup_range that is less than or equal to the value.
11
+ # @return If the value is smaller than all of the values in the lookup_range, then the LOOKUP function will return #N/A(nil in our case).
12
+ # @return If the values in the LOOKUP_range are not sorted in ascending order, the LOOKUP function will return the incorrect value (raise error in our case).
13
+ # @see http://www.techonthenet.com/excel/formulas/lookup.php Specification
4
14
  def lookup(value, lookup_array, output_array = nil)
5
- #The LOOKUP function searches for the value in the lookup_range and returns the value from the same position in the result_range. If this parameter is omitted, the LOOKUP function will return the first column of data.
6
- #In Syntax #2, the LOOKUP function searches for the value in the first row or column of the array and returns the corresponding value in the last row or column of the array.
7
15
  #combining both syntaxes here by taking 1st col of lookup_array to lookup
8
16
  # and the output_array or the last column of the lookup_array to output
9
17
  output_array = output_array || lookup_array.map{|arr| Array(arr)[-1]}
10
18
 
11
19
  lookup_array = lookup_array.map{|arr| Array(arr)[0]}
12
20
 
13
- #If the values in the LOOKUP_range are not sorted in ascending order, the LOOKUP function will return the incorrect value.
21
+
14
22
  raise "lookup_array must be sorted" unless lookup_array.sort == lookup_array #better way to check sorted?
15
23
 
16
24
  index = lookup_array.find_index(value)
17
25
  return output_array[index] if index
18
26
 
19
- # If the LOOKUP function can not find an exact match, it chooses the largest value in the lookup_range that is less than or equal to the value.
20
- # If the value is smaller than all of the values in the lookup_range, then the LOOKUP function will return #N/A.
27
+
21
28
  first_greater_index = lookup_array.find_index{|look| look > value} || lookup_array.count
22
29
  less_than_index = first_greater_index - 1
23
30
  less_than_index >=0 ? output_array[less_than_index] : nil
@@ -1,3 +1,3 @@
1
1
  module ExcelFunctions
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,10 +1,13 @@
1
1
  require "excel_functions/version"
2
2
  require "excel_functions/financial"
3
3
  require "excel_functions/lookup"
4
+
5
+ #module to be included in a client class
4
6
  module ExcelFunctions
5
7
 
6
8
  end
7
9
 
10
+ #class which provides all the methods as class methods
8
11
  class Excel
9
12
  extend ExcelFunctions
10
13
  end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excel_functions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Karthik T
@@ -13,6 +14,7 @@ dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rake
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: rspec
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ! '>='
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
@@ -74,26 +81,28 @@ files:
74
81
  homepage: https://github.com/ktaragorn/excel_functions
75
82
  licenses:
76
83
  - MIT
77
- metadata: {}
78
84
  post_install_message:
79
85
  rdoc_options: []
80
86
  require_paths:
81
87
  - lib
82
88
  required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
83
90
  requirements:
84
91
  - - ! '>='
85
92
  - !ruby/object:Gem::Version
86
93
  version: '0'
87
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
88
96
  requirements:
89
97
  - - ! '>='
90
98
  - !ruby/object:Gem::Version
91
99
  version: '0'
92
100
  requirements: []
93
101
  rubyforge_project:
94
- rubygems_version: 2.0.5
102
+ rubygems_version: 1.8.23
95
103
  signing_key:
96
- specification_version: 4
104
+ specification_version: 3
97
105
  summary: This gem can be used if you need to reverse engineer any excel spreadsheets.
98
106
  test_files:
99
107
  - spec/excelfunctions_spec.rb
108
+ has_rdoc:
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OTg4NmNlZDk3MmNhODRhYzZkM2IyOTc1NjAxZTU3MjQ2MzNhYTIzYQ==
5
- data.tar.gz: !binary |-
6
- MTNjYjhkNmJiMThlYWIwYTU3N2U3ZTBiYTBlZGNhZDI2MWI2NmVlOA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YzUzNTE4ZDNjZGZmN2U5ZjAxZjFlN2I2ZThkZWIyYzFlZjhhOGU5YTdjOTIw
10
- NTg4YTkxYjZhYzQ3OGEwZDAxMGQzN2MxZDk4NTE2NTFmYjFjNTRhNDUxNTU5
11
- NTlkZDhhZGEzNmY1ZTYwMzM3ZDMzNzA2ODU3NjllNDYzNTQzYTk=
12
- data.tar.gz: !binary |-
13
- MTQxZGI5YzZlOGE2ZjMxYzRjYWFmODUxMDlmZWI0NTBmMzNlOGYyN2ZjMmZi
14
- MGIzZGY1NTM0YmM4NTQxMmUzNTZhMWQyZTFiYjdlMzhhYjg2Y2Y2MGE0NWIw
15
- NjJjNTFkOWVlZTZjMzk0M2M0MzI5YjAxYTYzOWU2YzkwNzUyYjI=