Class: Picatrix::Pacman

Inherits:
Object
  • Object
show all
Defined in:
lib/picatrix/pacman.rb

Overview

eats dots :) and gives you back nodes and edges

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ Pacman

Returns a new instance of Pacman.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/picatrix/pacman.rb', line 7

def initialize(file_name)
  hash = TransformToHash.new.apply(
    DigraphParser.new.parse(
      File.read(file_name)
    )
  ).flat_map(&:entries).
  group_by(&:first).
  map {|k,v| Hash[k, v.map(&:last)]}.
  reduce({}, :merge)

  @nodes = hash[:node].reduce({}, :merge)
  @edges = hash[:edge]
end

Instance Attribute Details

#edgesObject

Returns the value of attribute edges.



5
6
7
# File 'lib/picatrix/pacman.rb', line 5

def edges
  @edges
end

#nodesObject

Returns the value of attribute nodes.



5
6
7
# File 'lib/picatrix/pacman.rb', line 5

def nodes
  @nodes
end

Instance Method Details

#graph_hashObject



21
22
23
24
25
26
# File 'lib/picatrix/pacman.rb', line 21

def graph_hash
  {
    node: nodes,
    edge: edges
  }
end