Class: Appwrite::Operator
- Inherits:
-
Object
- Object
- Appwrite::Operator
- Defined in:
- lib/appwrite/operator.rb
Class Method Summary collapse
- .array_append(values) ⇒ Object
- .array_diff(values) ⇒ Object
- .array_filter(condition, value = nil) ⇒ Object
- .array_insert(index, value) ⇒ Object
- .array_intersect(values) ⇒ Object
- .array_prepend(values) ⇒ Object
- .array_remove(value) ⇒ Object
- .array_unique ⇒ Object
- .date_add_days(days) ⇒ Object
- .date_set_now ⇒ Object
- .date_sub_days(days) ⇒ Object
- .decrement(value = 1, min = nil) ⇒ Object
- .divide(divisor, min = nil) ⇒ Object
- .increment(value = 1, max = nil) ⇒ Object
- .modulo(divisor) ⇒ Object
- .multiply(factor, max = nil) ⇒ Object
- .power(exponent, max = nil) ⇒ Object
- .string_concat(value) ⇒ Object
- .string_replace(search, replace) ⇒ Object
- .toggle ⇒ Object
Instance Method Summary collapse
-
#initialize(method, values = nil) ⇒ Operator
constructor
A new instance of Operator.
- #to_json(*args) ⇒ Object
- #to_s ⇒ Object
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_unique ⇒ Object
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_now ⇒ Object
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
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
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
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
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
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
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 |
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_s ⇒ Object
35 36 37 |
# File 'lib/appwrite/operator.rb', line 35 def to_s return self.to_json end |