|
| 1 | +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. |
| 2 | + |
| 3 | +require "date" |
| 4 | +require "time" |
| 5 | + |
| 6 | +module Algolia |
| 7 | + module Abtesting |
| 8 | + class ScheduleABTestResponse |
| 9 | + # Unique scheduled A/B test identifier. |
| 10 | + attr_accessor :ab_test_schedule_id |
| 11 | + |
| 12 | + # Attribute mapping from ruby-style variable name to JSON key. |
| 13 | + def self.attribute_map |
| 14 | + { |
| 15 | + :ab_test_schedule_id => :abTestScheduleID |
| 16 | + } |
| 17 | + end |
| 18 | + |
| 19 | + # Returns all the JSON keys this model knows about |
| 20 | + def self.acceptable_attributes |
| 21 | + attribute_map.values |
| 22 | + end |
| 23 | + |
| 24 | + # Attribute type mapping. |
| 25 | + def self.types_mapping |
| 26 | + { |
| 27 | + :ab_test_schedule_id => :"Integer" |
| 28 | + } |
| 29 | + end |
| 30 | + |
| 31 | + # List of attributes with nullable: true |
| 32 | + def self.openapi_nullable |
| 33 | + Set.new( |
| 34 | + [] |
| 35 | + ) |
| 36 | + end |
| 37 | + |
| 38 | + # Initializes the object |
| 39 | + # @param [Hash] attributes Model attributes in the form of hash |
| 40 | + def initialize(attributes = {}) |
| 41 | + if (!attributes.is_a?(Hash)) |
| 42 | + raise( |
| 43 | + ArgumentError, |
| 44 | + "The input argument (attributes) must be a hash in `Algolia::ScheduleABTestResponse` initialize method" |
| 45 | + ) |
| 46 | + end |
| 47 | + |
| 48 | + # check to see if the attribute exists and convert string to symbol for hash key |
| 49 | + attributes = attributes.each_with_object({}) { |(k, v), h| |
| 50 | + if (!self.class.attribute_map.key?(k.to_sym)) |
| 51 | + raise( |
| 52 | + ArgumentError, |
| 53 | + "`#{k}` is not a valid attribute in `Algolia::ScheduleABTestResponse`. Please check the name to make sure it's valid. List of attributes: " + |
| 54 | + self.class.attribute_map.keys.inspect |
| 55 | + ) |
| 56 | + end |
| 57 | + |
| 58 | + h[k.to_sym] = v |
| 59 | + } |
| 60 | + |
| 61 | + if attributes.key?(:ab_test_schedule_id) |
| 62 | + self.ab_test_schedule_id = attributes[:ab_test_schedule_id] |
| 63 | + else |
| 64 | + self.ab_test_schedule_id = nil |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + # Checks equality by comparing each attribute. |
| 69 | + # @param [Object] Object to be compared |
| 70 | + def ==(other) |
| 71 | + return true if self.equal?(other) |
| 72 | + self.class == other.class && |
| 73 | + ab_test_schedule_id == other.ab_test_schedule_id |
| 74 | + end |
| 75 | + |
| 76 | + # @see the `==` method |
| 77 | + # @param [Object] Object to be compared |
| 78 | + def eql?(other) |
| 79 | + self == other |
| 80 | + end |
| 81 | + |
| 82 | + # Calculates hash code according to all attributes. |
| 83 | + # @return [Integer] Hash code |
| 84 | + def hash |
| 85 | + [ab_test_schedule_id].hash |
| 86 | + end |
| 87 | + |
| 88 | + # Builds the object from hash |
| 89 | + # @param [Hash] attributes Model attributes in the form of hash |
| 90 | + # @return [Object] Returns the model itself |
| 91 | + def self.build_from_hash(attributes) |
| 92 | + return nil unless attributes.is_a?(Hash) |
| 93 | + attributes = attributes.transform_keys(&:to_sym) |
| 94 | + transformed_hash = {} |
| 95 | + types_mapping.each_pair do |key, type| |
| 96 | + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? |
| 97 | + transformed_hash[key.to_sym] = nil |
| 98 | + elsif type =~ /\AArray<(.*)>/i |
| 99 | + # check to ensure the input is an array given that the attribute |
| 100 | + # is documented as an array but the input is not |
| 101 | + if attributes[attribute_map[key]].is_a?(Array) |
| 102 | + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| |
| 103 | + _deserialize(::Regexp.last_match(1), v) |
| 104 | + } |
| 105 | + end |
| 106 | + elsif !attributes[attribute_map[key]].nil? |
| 107 | + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) |
| 108 | + end |
| 109 | + end |
| 110 | + |
| 111 | + new(transformed_hash) |
| 112 | + end |
| 113 | + |
| 114 | + # Deserializes the data based on type |
| 115 | + # @param string type Data type |
| 116 | + # @param string value Value to be deserialized |
| 117 | + # @return [Object] Deserialized data |
| 118 | + def self._deserialize(type, value) |
| 119 | + case type.to_sym |
| 120 | + when :Time |
| 121 | + Time.parse(value) |
| 122 | + when :Date |
| 123 | + Date.parse(value) |
| 124 | + when :String |
| 125 | + value.to_s |
| 126 | + when :Integer |
| 127 | + value.to_i |
| 128 | + when :Float |
| 129 | + value.to_f |
| 130 | + when :Boolean |
| 131 | + if value.to_s =~ /\A(true|t|yes|y|1)\z/i |
| 132 | + true |
| 133 | + else |
| 134 | + false |
| 135 | + end |
| 136 | + |
| 137 | + when :Object |
| 138 | + # generic object (usually a Hash), return directly |
| 139 | + value |
| 140 | + when /\AArray<(?<inner_type>.+)>\z/ |
| 141 | + inner_type = Regexp.last_match[:inner_type] |
| 142 | + value.map { |v| _deserialize(inner_type, v) } |
| 143 | + when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/ |
| 144 | + k_type = Regexp.last_match[:k_type] |
| 145 | + v_type = Regexp.last_match[:v_type] |
| 146 | + {}.tap do |hash| |
| 147 | + value.each do |k, v| |
| 148 | + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) |
| 149 | + end |
| 150 | + end |
| 151 | + # model |
| 152 | + else |
| 153 | + # models (e.g. Pet) or oneOf |
| 154 | + klass = Algolia::Abtesting.const_get(type) |
| 155 | + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass |
| 156 | + .build_from_hash(value) |
| 157 | + end |
| 158 | + end |
| 159 | + |
| 160 | + # Returns the string representation of the object |
| 161 | + # @return [String] String presentation of the object |
| 162 | + def to_s |
| 163 | + to_hash.to_s |
| 164 | + end |
| 165 | + |
| 166 | + # to_body is an alias to to_hash (backward compatibility) |
| 167 | + # @return [Hash] Returns the object in the form of hash |
| 168 | + def to_body |
| 169 | + to_hash |
| 170 | + end |
| 171 | + |
| 172 | + def to_json(*_args) |
| 173 | + to_hash.to_json |
| 174 | + end |
| 175 | + |
| 176 | + # Returns the object in the form of hash |
| 177 | + # @return [Hash] Returns the object in the form of hash |
| 178 | + def to_hash |
| 179 | + hash = {} |
| 180 | + self.class.attribute_map.each_pair do |attr, param| |
| 181 | + value = send(attr) |
| 182 | + if value.nil? |
| 183 | + is_nullable = self.class.openapi_nullable.include?(attr) |
| 184 | + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) |
| 185 | + end |
| 186 | + |
| 187 | + hash[param] = _to_hash(value) |
| 188 | + end |
| 189 | + |
| 190 | + hash |
| 191 | + end |
| 192 | + |
| 193 | + # Outputs non-array value in the form of hash |
| 194 | + # For object, use to_hash. Otherwise, just return the value |
| 195 | + # @param [Object] value Any valid value |
| 196 | + # @return [Hash] Returns the value in the form of hash |
| 197 | + def _to_hash(value) |
| 198 | + if value.is_a?(Array) |
| 199 | + value.compact.map { |v| _to_hash(v) } |
| 200 | + elsif value.is_a?(Hash) |
| 201 | + {}.tap do |hash| |
| 202 | + value.each { |k, v| hash[k] = _to_hash(v) } |
| 203 | + end |
| 204 | + elsif value.respond_to?(:to_hash) |
| 205 | + value.to_hash |
| 206 | + else |
| 207 | + value |
| 208 | + end |
| 209 | + end |
| 210 | + |
| 211 | + end |
| 212 | + |
| 213 | + end |
| 214 | +end |
0 commit comments