Class: Hash

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

Overview

Module

Direct Known Subclasses

OrientSupport::Hash

Instance Method Summary collapse

Instance Method Details

#from_orientObject

converts hash from db to activeorient



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/other.rb', line 295

def from_orient  
   #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
		# populate the hash by converting keys: stings to symbols, values: proprocess through :from_orient
		map do |k,v| 
			orient_k = if  k.to_s.to_i.to_s == k.to_s
									 k.to_i
								 else
									 k.to_sym
								 end

			[orient_k, v.from_orient]
		end.to_h
	end
end

#to_humanObject



293
294
295
# File 'lib/support/orient.rb', line 293

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



317
318
319
# File 'lib/other.rb', line 317

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

#to_orientObject

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

converts nn => anything to nn => anything

leaves “abc” => anything untouched



278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/other.rb', line 278

def to_orient   # converts hast from activeorient to db
  map do | k, v|
	orient_k =  case k
							when Numeric
								k
							when Symbol, String
								k.to_s
							else
								raise "not supported key: #[k} -- must a sting, symbol or number"
							end
	[orient_k, v.to_orient]
end.to_h
end