require 'date' module PureCloud class JsonNode attr_accessor :node_type attr_accessor :float attr_accessor :object attr_accessor :boolean attr_accessor :number attr_accessor :value_node attr_accessor :floating_point_number attr_accessor :container_node attr_accessor :missing_node attr_accessor :pojo attr_accessor :integral_number attr_accessor :short attr_accessor :int attr_accessor :long attr_accessor :double attr_accessor :big_decimal attr_accessor :big_integer attr_accessor :textual attr_accessor :binary attr_accessor :array attr_accessor :null # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { :'node_type' => :'nodeType', :'float' => :'float', :'object' => :'object', :'boolean' => :'boolean', :'number' => :'number', :'value_node' => :'valueNode', :'floating_point_number' => :'floatingPointNumber', :'container_node' => :'containerNode', :'missing_node' => :'missingNode', :'pojo' => :'pojo', :'integral_number' => :'integralNumber', :'short' => :'short', :'int' => :'int', :'long' => :'long', :'double' => :'double', :'big_decimal' => :'bigDecimal', :'big_integer' => :'bigInteger', :'textual' => :'textual', :'binary' => :'binary', :'array' => :'array', :'null' => :'null' } end # Attribute type mapping. def self.swagger_types { :'node_type' => :'String', :'float' => :'BOOLEAN', :'object' => :'BOOLEAN', :'boolean' => :'BOOLEAN', :'number' => :'BOOLEAN', :'value_node' => :'BOOLEAN', :'floating_point_number' => :'BOOLEAN', :'container_node' => :'BOOLEAN', :'missing_node' => :'BOOLEAN', :'pojo' => :'BOOLEAN', :'integral_number' => :'BOOLEAN', :'short' => :'BOOLEAN', :'int' => :'BOOLEAN', :'long' => :'BOOLEAN', :'double' => :'BOOLEAN', :'big_decimal' => :'BOOLEAN', :'big_integer' => :'BOOLEAN', :'textual' => :'BOOLEAN', :'binary' => :'BOOLEAN', :'array' => :'BOOLEAN', :'null' => :'BOOLEAN' } end def initialize(attributes = {}) return unless attributes.is_a?(Hash) # convert string to symbol for hash key attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} if attributes[:'nodeType'] self.node_type = attributes[:'nodeType'] end if attributes[:'float'] self.float = attributes[:'float'] else self.float = false end if attributes[:'object'] self.object = attributes[:'object'] else self.object = false end if attributes[:'boolean'] self.boolean = attributes[:'boolean'] else self.boolean = false end if attributes[:'number'] self.number = attributes[:'number'] else self.number = false end if attributes[:'valueNode'] self.value_node = attributes[:'valueNode'] else self.value_node = false end if attributes[:'floatingPointNumber'] self.floating_point_number = attributes[:'floatingPointNumber'] else self.floating_point_number = false end if attributes[:'containerNode'] self.container_node = attributes[:'containerNode'] else self.container_node = false end if attributes[:'missingNode'] self.missing_node = attributes[:'missingNode'] else self.missing_node = false end if attributes[:'pojo'] self.pojo = attributes[:'pojo'] else self.pojo = false end if attributes[:'integralNumber'] self.integral_number = attributes[:'integralNumber'] else self.integral_number = false end if attributes[:'short'] self.short = attributes[:'short'] else self.short = false end if attributes[:'int'] self.int = attributes[:'int'] else self.int = false end if attributes[:'long'] self.long = attributes[:'long'] else self.long = false end if attributes[:'double'] self.double = attributes[:'double'] else self.double = false end if attributes[:'bigDecimal'] self.big_decimal = attributes[:'bigDecimal'] else self.big_decimal = false end if attributes[:'bigInteger'] self.big_integer = attributes[:'bigInteger'] else self.big_integer = false end if attributes[:'textual'] self.textual = attributes[:'textual'] else self.textual = false end if attributes[:'binary'] self.binary = attributes[:'binary'] else self.binary = false end if attributes[:'array'] self.array = attributes[:'array'] else self.array = false end if attributes[:'null'] self.null = attributes[:'null'] else self.null = false end end # Custom attribute writer method checking allowed values (enum). def node_type=(node_type) allowed_values = ["ARRAY", "BINARY", "BOOLEAN", "MISSING", "NULL", "NUMBER", "OBJECT", "POJO", "STRING"] if node_type && !allowed_values.include?(node_type) fail "invalid value for 'node_type', must be one of #{allowed_values}" end @node_type = node_type end # Check equality by comparing each attribute. def ==(o) return true if self.equal?(o) self.class == o.class && node_type == o.node_type && float == o.float && object == o.object && boolean == o.boolean && number == o.number && value_node == o.value_node && floating_point_number == o.floating_point_number && container_node == o.container_node && missing_node == o.missing_node && pojo == o.pojo && integral_number == o.integral_number && short == o.short && int == o.int && long == o.long && double == o.double && big_decimal == o.big_decimal && big_integer == o.big_integer && textual == o.textual && binary == o.binary && array == o.array && null == o.null end # @see the `==` method def eql?(o) self == o end # Calculate hash code according to all attributes. def hash [node_type, float, object, boolean, number, value_node, floating_point_number, container_node, missing_node, pojo, integral_number, short, int, long, double, big_decimal, big_integer, textual, binary, array, null].hash end # build the object from hash def build_from_hash(attributes) return nil unless attributes.is_a?(Hash) self.class.swagger_types.each_pair do |key, type| if type =~ /^Array<(.*)>/i if attributes[self.class.attribute_map[key]].is_a?(Array) self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } ) else #TODO show warning in debug mode end elsif !attributes[self.class.attribute_map[key]].nil? self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) else # data not found in attributes(hash), not an issue as the data can be optional end end self end def _deserialize(type, value) case type.to_sym when :DateTime DateTime.parse(value) when :Date Date.parse(value) when :String value.to_s when :Integer value.to_i when :Float value.to_f when :BOOLEAN if value =~ /^(true|t|yes|y|1)$/i true else false end when /\AArray<(?.+)>\z/ inner_type = Regexp.last_match[:inner_type] value.map { |v| _deserialize(inner_type, v) } when /\AHash<(?.+), (?.+)>\z/ k_type = Regexp.last_match[:k_type] v_type = Regexp.last_match[:v_type] {}.tap do |hash| value.each do |k, v| hash[_deserialize(k_type, k)] = _deserialize(v_type, v) end end else # model _model = Object.const_get("PureCloud").const_get(type).new _model.build_from_hash(value) end end def to_s to_hash.to_s end # to_body is an alias to to_body (backward compatibility)) def to_body to_hash end # return the object in the form of hash def to_hash hash = {} self.class.attribute_map.each_pair do |attr, param| value = self.send(attr) next if value.nil? hash[param] = _to_hash(value) end hash end # Method to output non-array value in the form of hash # For object, use to_hash. Otherwise, just return the value def _to_hash(value) if value.is_a?(Array) value.compact.map{ |v| _to_hash(v) } elsif value.is_a?(Hash) {}.tap do |hash| value.each { |k, v| hash[k] = _to_hash(v) } end elsif value.respond_to? :to_hash value.to_hash else value end end end end