Class: Hash

Inherits:
Object show all
Defined in:
lib/other.rb,
lib/support/orient.rb

Overview

Module

Direct Known Subclasses

OrientSupport::Hash

Instance Method Summary collapse

Instance Method Details

#coerce(arg) ⇒ Object


191
192
193
194
195
196
197
198
# File 'lib/support/orient.rb', line 191

def coerce arg
	if arg.is_a? DateTime
		nil
	else
		super

	end
end

#from_orientObject

converts hash from db to activeorient


240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/other.rb', line 240

def from_orient   # converts hash from db to activeorient
   #puts "here hash.from_orient --> #{self.inspect}"
	if keys.include?("@class" )
		ActiveOrient::Model.orientdb_class( name: self["@class"] ).new self
		# create a dummy class and fill with attributes from result-set
	elsif keys.include?("@type") && self["@type"] == 'd'  
		ActiveOrient::Model.orientdb_class(name: 'query' ).new self
	else
		substitute_hash = Hash.new
		keys.each do |k| 
			orient_k = if  k.to_s.to_i.to_s == k.to_s
									 k.to_i
								 else
									 k.to_sym
								 end

			substitute_hash[orient_k] = self[k].from_orient
		end
		substitute_hash
	end
end

#to_humanObject


187
188
189
# File 'lib/support/orient.rb', line 187

def to_human
	"{ " + self.map{ |k,v| [k.to_s,": ", v.to_orient].join }.join(', ') + " }"
end

#to_orObject

converts a hash to a string appropiate to include in raw queries


263
264
265
# File 'lib/other.rb', line 263

def to_or
	"{ " + to_orient.map{|k,v| "#{k.to_s.to_or}: #{v.to_or}"}.join(',') + "}"
end

#to_orientObject

converts “abc” => anything to :abc => anything converts “nn” => anything to nn => anything


222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/other.rb', line 222

def to_orient   # converts hast from activeorient to db
  substitute_hash =  {} # HashWithIndifferentAccess.new
#		puts "here to hash"
  #keys.each{|k| puts self[k].inspect}
  keys.each do |k| 
	orient_k =  case k
							when Numeric
								k
							when Symbol, String
								k.to_s
							else
								nil
							end
	substitute_hash[orient_k] = self[k].to_orient
end
  substitute_hash
end