Module: Yzz

Defined in:
lib/yzz.rb,
lib/yzz/version.rb

Overview

Module Yzz is a mixin that provides qualities of a ZZ structure cell to its includers.

A ZZ structure consists of ZZ objects, which exist in multiple dimensions. ZZ objects may be connected by directed edges – connections. Connected objects are called neighbors. Each connection belongs to exactly one dimension. A ZZ object is considered as having two sides in each dimension: posward side and negward side. A connection always points away from the posward side, and towards the negward side of the neighbor. In each dimension, a ZZ object can have at most one posward and one negward neighbor. The relation is bijective: If B is the posward neighbor of A along dimension X, then A is a negward neighbor of B along X, and vice-versa. There is no limitation as to what objects can be connected. Circles are allowed. A ZZ object can even be connected to itself, forming a loop.

To this basic definition, Ted Nelson adds a bunch of additional terminology. A rank is a series of ZZ objects connected along the same dimension. A rank viewed horizontally is referred to as row. A rank viewed vertically is referred to as column. Ted Nelson’s terms related not to the ZZ structure itself, but rather to the proposed user interface (such as cursor, view…) are not implemented in yzz, but rather in y_nelson gem.

Defined Under Namespace

Classes: Side, SidePair

Constant Summary collapse

VERSION =
"2.0.11"

Instance Method Summary collapse

Instance Method Details

#along(dimension) ⇒ Object

Returns a SidePair instance along the requested dimension.



43
44
45
# File 'lib/yzz.rb', line 43

def along dimension
  @zz_dimensions[ dimension ]
end

#connectionsObject Also known as: connectivity

Returns all sides actually connected to a zz object.



49
50
51
52
# File 'lib/yzz.rb', line 49

def connections
  @zz_dimensions.map { |_, pair| [ pair.negward, pair.posward ] }
    .reduce( [], :+ ).select { |side| side.neighbor.is_a_zz? }
end

#initialize(*args) ⇒ Object

Adds initialization of the @zz_dimensions hash to #initialize.



33
34
35
36
37
38
39
# File 'lib/yzz.rb', line 33

def initialize *args
  @zz_dimensions = Hash.new { |, missing_dimension|
    [ missing_dimension ] = Yzz::SidePair
      .new( zz: self, dimension: missing_dimension )
  } # initialize the @zz_dimensions hash
  super # and proceed as usual
end

#inspectObject

Inspect string of the object.



83
84
85
# File 'lib/yzz.rb', line 83

def inspect
  to_s
end

#neighborsObject

Returns all neighbors of a zz object.



57
58
59
# File 'lib/yzz.rb', line 57

def neighbors
  connections.map &:neighbor
end

#to_sObject

Short string describing the object.



77
78
79
# File 'lib/yzz.rb', line 77

def to_s
  "#<Yzz, #{connections.size} conn.>"
end

#towards(other) ⇒ Object

Returns all sides facing another zz object supplied as argument. (Note that this can be more than 1 side: object A can be connected to B along more than 1 dimension.



65
66
67
# File 'lib/yzz.rb', line 65

def towards other
  connectivity.select { |side| side.neighbor == other }
end

#tw(other) ⇒ Object

Prints the labels of the sides facing towards a given zz object.



71
72
73
# File 'lib/yzz.rb', line 71

def tw other
  puts towards( other ).map &:label
end