Class: Cartos::Google::Sheet::Formulas
- Inherits:
-
Object
- Object
- Cartos::Google::Sheet::Formulas
- Defined in:
- lib/cartos/google/sheet.rb
Instance Method Summary collapse
- #abs(number = nil) ⇒ Object
- #filter(sourceArray, *conditions) ⇒ Object
-
#initialize ⇒ Formulas
constructor
A new instance of Formulas.
- #sum(*numbers) ⇒ Object
- #to_s ⇒ Object
- #unique(array) ⇒ Object
Constructor Details
#initialize ⇒ Formulas
Returns a new instance of Formulas.
6 7 8 |
# File 'lib/cartos/google/sheet.rb', line 6 def initialize @buffer = [] end |
Instance Method Details
#abs(number = nil) ⇒ Object
19 20 21 22 |
# File 'lib/cartos/google/sheet.rb', line 19 def abs(number = nil) @buffer.unshift ["ABS", number] self end |
#filter(sourceArray, *conditions) ⇒ Object
14 15 16 17 |
# File 'lib/cartos/google/sheet.rb', line 14 def filter(sourceArray, *conditions) @buffer.unshift ["FILTER", [sourceArray, conditions]] self end |
#sum(*numbers) ⇒ Object
9 10 11 12 |
# File 'lib/cartos/google/sheet.rb', line 9 def sum(*numbers) @buffer.unshift ["SUM", numbers] self end |
#to_s ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cartos/google/sheet.rb', line 28 def to_s result = @buffer.inject("") do |memo, element| name, *params = *element params = params.flatten.compact if params.empty? memo = "#{name}(#{memo})" else memo = "#{name}(#{params.join(",")})" end memo end "=" + result end |
#unique(array) ⇒ Object
24 25 26 |
# File 'lib/cartos/google/sheet.rb', line 24 def unique(array) @buffer.unshift ["UNIQUE", array] end |