Class: Neography::PropertyContainer

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/neography/property_container.rb

Direct Known Subclasses

Node, Relationship

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) ⇒ PropertyContainer


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/neography/property_container.rb', line 5

def initialize(hash=nil)
  @table = {}
  unless hash.nil?
    if hash["self"] # coming from REST API
      @neo_id = hash["self"].split('/').last
      data = hash["data"]
    elsif hash.is_a? Neography::Node # is already a Neography::Node
      @neo_id = hash.neo_id
      data = Hash[*hash.attributes.collect{|x| [x.to_sym, hash.send(x)]}.flatten]
    elsif hash["data"] # coming from CYPHER
      @neo_id = hash["data"].first.first["self"].split('/').last
      data = hash["data"].first.first["data"]
    end
  else
    data = []
  end
  unless data.nil?
    for k,v in data
      new_ostruct_member(k.to_sym, v)
    end
  end
end

Instance Attribute Details

#neo_idObject (readonly)

Returns the value of attribute neo_id


3
4
5
# File 'lib/neography/property_container.rb', line 3

def neo_id
  @neo_id
end