Class: Cartos::Google::Sheet::Formulas

Inherits:
Object
  • Object
show all
Defined in:
lib/cartos/google/sheet.rb

Instance Method Summary collapse

Constructor Details

#initializeFormulas

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_sObject



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