Class: Picatrix::Pacman
- Inherits:
-
Object
- Object
- Picatrix::Pacman
- Defined in:
- lib/picatrix/pacman.rb
Overview
eats dots :) and gives you back nodes and edges
Instance Attribute Summary collapse
-
#edges ⇒ Object
Returns the value of attribute edges.
-
#nodes ⇒ Object
Returns the value of attribute nodes.
Instance Method Summary collapse
- #graph_hash ⇒ Object
-
#initialize(file_name) ⇒ Pacman
constructor
A new instance of Pacman.
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
#edges ⇒ Object
Returns the value of attribute edges.
5 6 7 |
# File 'lib/picatrix/pacman.rb', line 5 def edges @edges end |
#nodes ⇒ Object
Returns the value of attribute nodes.
5 6 7 |
# File 'lib/picatrix/pacman.rb', line 5 def nodes @nodes end |
Instance Method Details
#graph_hash ⇒ Object
21 22 23 24 25 26 |
# File 'lib/picatrix/pacman.rb', line 21 def graph_hash { node: nodes, edge: edges } end |