Class: Fathom::Edge

Inherits:
Object
  • Object
show all
Extended by:
Plugins
Defined in:
lib/fathom/data/edge.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plugins

plugin, plugins

Constructor Details

#initialize(attributes = {}) ⇒ Edge

Returns a new instance of Edge.



35
36
37
38
39
# File 'lib/fathom/data/edge.rb', line 35

def initialize(attributes={})
  attributes[:parent] = Variable.infer(attributes[:parent])
  attributes[:child] = Variable.infer(attributes[:child])
  @attributes = attributes
end

Class Method Details

.infer(obj, optional_child = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fathom/data/edge.rb', line 8

def infer(obj, optional_child=nil)
  return new(:parent => Variable.infer(obj), :child => Variable.infer(optional_child)) if optional_child
  
  case obj
  when Edge
    obj
  when Array
    new(:parent => Variable.infer(obj[0]), :child => Variable.infer(obj[1]))
  when Hash
    new(obj)
  end
end

Instance Method Details

#child=(obj) ⇒ Object



48
49
50
# File 'lib/fathom/data/edge.rb', line 48

def child=(obj)
  send(self.class.attributes_proxy)[:child] = Variable.infer(obj)
end

#eql(other) ⇒ Object Also known as: ==



52
53
54
55
# File 'lib/fathom/data/edge.rb', line 52

def eql(other)
  return false unless other.is_a?(Edge)
  self.parent == other.parent and self.child == other.child
end

#parent=(obj) ⇒ Object

Override setters on parent and child to ensure Variables =



44
45
46
# File 'lib/fathom/data/edge.rb', line 44

def parent=(obj)
  send(self.class.attributes_proxy)[:parent] = Variable.infer(obj)
end