Class: Extract::ExcelFormulas
Class Method Summary collapse
Instance Method Summary collapse
- #combin(n, k) ⇒ Object
- #double(i) ⇒ Object
- #if(c, a, b) ⇒ Object
- #max(*args) ⇒ Object
- #sqrt(num) ⇒ Object
- #sum(*args) ⇒ Object
- #vlookup(lookup_val, range, col_num, *junk) ⇒ Object
Class Method Details
.method_missing(sym, *args, &b) ⇒ Object
39 40 41 |
# File 'lib/extract/excel_formulas.rb', line 39 def method_missing(sym,*args,&b) new.send(sym,*args,&b) end |
Instance Method Details
#combin(n, k) ⇒ Object
33 34 35 36 |
# File 'lib/extract/excel_formulas.rb', line 33 def combin(n,k) #puts "combin #{n} #{k}" n.fact / (k.fact * (n-k).fact) end |
#double(i) ⇒ Object
3 4 5 |
# File 'lib/extract/excel_formulas.rb', line 3 def double(i) i * 2 end |
#if(c, a, b) ⇒ Object
9 10 11 12 13 |
# File 'lib/extract/excel_formulas.rb', line 9 def if(c,a,b) res = c ? a : b #puts [c,a,b].inspect res end |
#max(*args) ⇒ Object
14 15 16 |
# File 'lib/extract/excel_formulas.rb', line 14 def max(*args) args.flatten.select { |x| x }.sort.reverse.first end |
#sqrt(num) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/extract/excel_formulas.rb', line 25 def sqrt(num) if num.present? (num.to_f) ** 0.5 else nil end end |
#sum(*args) ⇒ Object
6 7 8 |
# File 'lib/extract/excel_formulas.rb', line 6 def sum(*args) args.flatten.inject(0) { |s,i| s + (i || 0) } end |
#vlookup(lookup_val, range, col_num, *junk) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/extract/excel_formulas.rb', line 17 def vlookup(lookup_val,range,col_num,*junk) range.each do |row| if row[0] == lookup_val return row[col_num-1] end end nil end |