class Hash
Public Instance Methods
from_orient()
click to toggle source
converts hash from db to activeorient
# 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_human()
click to toggle source
# File lib/support/orient.rb, line 293 def to_human "{ " + self.map{ |k,v| [k.to_s,": ", v.to_orient].join }.join(', ') + " }" end
to_or()
click to toggle source
converts a hash to a string appropiate to include in raw queries
# File lib/other.rb, line 317 def to_or "{ " + to_orient.map{|k,v| "#{k.to_or}: #{v.to_or}"}.join(',') + "}" end
to_orient()
click to toggle source
converts :abc => {anything} to “abc” => {anything}
converts nn => {anything} to nn => {anything}
leaves “abc” => {anything} untouched
# 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