Class: Appwrite::Operator

Inherits:
Object
  • Object
show all
Defined in:
lib/appwrite/operator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, values = nil) ⇒ Operator

Returns a new instance of Operator.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/appwrite/operator.rb', line 17

def initialize(method, values = nil)
    @method = method

    if values != nil
        if values.is_a?(Array)
            @values = values
        else
            @values = [values]
        end
    end
end

Class Method Details

.array_append(values) ⇒ Object



87
88
89
# File 'lib/appwrite/operator.rb', line 87

def array_append(values)
    return Operator.new("arrayAppend", values).to_s
end

.array_diff(values) ⇒ Object



111
112
113
# File 'lib/appwrite/operator.rb', line 111

def array_diff(values)
    return Operator.new("arrayDiff", values).to_s
end

.array_filter(condition, value = nil) ⇒ Object



115
116
117
118
# File 'lib/appwrite/operator.rb', line 115

def array_filter(condition, value = nil)
    values = [condition, value]
    return Operator.new("arrayFilter", values).to_s
end

.array_insert(index, value) ⇒ Object



95
96
97
# File 'lib/appwrite/operator.rb', line 95

def array_insert(index, value)
    return Operator.new("arrayInsert", [index, value]).to_s
end

.array_intersect(values) ⇒ Object



107
108
109
# File 'lib/appwrite/operator.rb', line 107

def array_intersect(values)
    return Operator.new("arrayIntersect", values).to_s
end

.array_prepend(values) ⇒ Object



91
92
93
# File 'lib/appwrite/operator.rb', line 91

def array_prepend(values)
    return Operator.new("arrayPrepend", values).to_s
end

.array_remove(value) ⇒ Object



99
100
101
# File 'lib/appwrite/operator.rb', line 99

def array_remove(value)
    return Operator.new("arrayRemove", [value]).to_s
end

.array_uniqueObject



103
104
105
# File 'lib/appwrite/operator.rb', line 103

def array_unique()
    return Operator.new("arrayUnique", []).to_s
end

.date_add_days(days) ⇒ Object



132
133
134
# File 'lib/appwrite/operator.rb', line 132

def date_add_days(days)
    return Operator.new("dateAddDays", [days]).to_s
end

.date_set_nowObject



140
141
142
# File 'lib/appwrite/operator.rb', line 140

def date_set_now()
    return Operator.new("dateSetNow", []).to_s
end

.date_sub_days(days) ⇒ Object



136
137
138
# File 'lib/appwrite/operator.rb', line 136

def date_sub_days(days)
    return Operator.new("dateSubDays", [days]).to_s
end

.decrement(value = 1, min = nil) ⇒ Object

Raises:

  • (ArgumentError)


48
49
50
51
52
53
54
# File 'lib/appwrite/operator.rb', line 48

def decrement(value = 1, min = nil)
    raise ArgumentError, "Value cannot be NaN or Infinity" if value.respond_to?(:nan?) && (value.nan? || value.infinite?)
    raise ArgumentError, "Min cannot be NaN or Infinity" if min != nil && min.respond_to?(:nan?) && (min.nan? || min.infinite?)
    values = [value]
    values << min if min != nil
    return Operator.new("decrement", values).to_s
end

.divide(divisor, min = nil) ⇒ Object

Raises:

  • (ArgumentError)


64
65
66
67
68
69
70
71
# File 'lib/appwrite/operator.rb', line 64

def divide(divisor, min = nil)
    raise ArgumentError, "Divisor cannot be NaN or Infinity" if divisor.respond_to?(:nan?) && (divisor.nan? || divisor.infinite?)
    raise ArgumentError, "Min cannot be NaN or Infinity" if min != nil && min.respond_to?(:nan?) && (min.nan? || min.infinite?)
    raise ArgumentError, "Divisor cannot be zero" if divisor == 0 || divisor == 0.0
    values = [divisor]
    values << min if min != nil
    return Operator.new("divide", values).to_s
end

.increment(value = 1, max = nil) ⇒ Object

Raises:

  • (ArgumentError)


40
41
42
43
44
45
46
# File 'lib/appwrite/operator.rb', line 40

def increment(value = 1, max = nil)
    raise ArgumentError, "Value cannot be NaN or Infinity" if value.respond_to?(:nan?) && (value.nan? || value.infinite?)
    raise ArgumentError, "Max cannot be NaN or Infinity" if max != nil && max.respond_to?(:nan?) && (max.nan? || max.infinite?)
    values = [value]
    values << max if max != nil
    return Operator.new("increment", values).to_s
end

.modulo(divisor) ⇒ Object

Raises:

  • (ArgumentError)


73
74
75
76
77
# File 'lib/appwrite/operator.rb', line 73

def modulo(divisor)
    raise ArgumentError, "Divisor cannot be NaN or Infinity" if divisor.respond_to?(:nan?) && (divisor.nan? || divisor.infinite?)
    raise ArgumentError, "Divisor cannot be zero" if divisor == 0 || divisor == 0.0
    return Operator.new("modulo", [divisor]).to_s
end

.multiply(factor, max = nil) ⇒ Object

Raises:

  • (ArgumentError)


56
57
58
59
60
61
62
# File 'lib/appwrite/operator.rb', line 56

def multiply(factor, max = nil)
    raise ArgumentError, "Factor cannot be NaN or Infinity" if factor.respond_to?(:nan?) && (factor.nan? || factor.infinite?)
    raise ArgumentError, "Max cannot be NaN or Infinity" if max != nil && max.respond_to?(:nan?) && (max.nan? || max.infinite?)
    values = [factor]
    values << max if max != nil
    return Operator.new("multiply", values).to_s
end

.power(exponent, max = nil) ⇒ Object

Raises:

  • (ArgumentError)


79
80
81
82
83
84
85
# File 'lib/appwrite/operator.rb', line 79

def power(exponent, max = nil)
    raise ArgumentError, "Exponent cannot be NaN or Infinity" if exponent.respond_to?(:nan?) && (exponent.nan? || exponent.infinite?)
    raise ArgumentError, "Max cannot be NaN or Infinity" if max != nil && max.respond_to?(:nan?) && (max.nan? || max.infinite?)
    values = [exponent]
    values << max if max != nil
    return Operator.new("power", values).to_s
end

.string_concat(value) ⇒ Object



120
121
122
# File 'lib/appwrite/operator.rb', line 120

def string_concat(value)
    return Operator.new("stringConcat", [value]).to_s
end

.string_replace(search, replace) ⇒ Object



124
125
126
# File 'lib/appwrite/operator.rb', line 124

def string_replace(search, replace)
    return Operator.new("stringReplace", [search, replace]).to_s
end

.toggleObject



128
129
130
# File 'lib/appwrite/operator.rb', line 128

def toggle()
    return Operator.new("toggle", []).to_s
end

Instance Method Details

#to_json(*args) ⇒ Object



29
30
31
32
33
# File 'lib/appwrite/operator.rb', line 29

def to_json(*args)
    result = { method: @method }
    result[:values] = @values unless @values.nil?
    result.to_json(*args)
end

#to_sObject



35
36
37
# File 'lib/appwrite/operator.rb', line 35

def to_s
    return self.to_json
end