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



188
189
190
191
192
193
194
195
# File 'lib/support/orient.rb', line 188

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

  end
end

#from_orientObject

converts hash from db to activeorient



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/other.rb', line 234

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
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



184
185
186
# File 'lib/support/orient.rb', line 184

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



254
255
256
# File 'lib/other.rb', line 254

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



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/other.rb', line 216

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