yzz 2.0.5 → 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -12
- data/lib/yzz.rb +6 -0
- data/lib/yzz/side.rb +18 -6
- data/lib/yzz/side_pair.rb +7 -1
- data/lib/yzz/version.rb +1 -1
- data/test/yzz_test.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71afce9e8205663f471fc06f91794c8431b427f0
|
4
|
+
data.tar.gz: bd85a78e18579012e0fca1fc9dd0226fd0fecb8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1985109e51e93ab03df13eb2800900b4a2306466cbf5a65a0f0459b7b18b6c41e37b3843af073acaf030f782c5937b0f02f67cdd5d96e84e2e0121047baccb5
|
7
|
+
data.tar.gz: 7ec0dd897ac19354c8a19e11a99205661b9691cccfd8ae53fa92bc61e500058140b842578a858e1c1477d3e122007d83bd5ed45b7b9fb8878aa53dfa54679baf
|
data/README.md
CHANGED
@@ -1,25 +1,65 @@
|
|
1
|
-
# Yzz
|
1
|
+
# Yzz
|
2
2
|
|
3
|
-
|
3
|
+
`Yzz` is a domain model of Ted Nelson's Zz structures.
|
4
4
|
|
5
|
-
##
|
5
|
+
## Usage
|
6
6
|
|
7
|
-
|
7
|
+
The following usage example takes use of `y_support/name_magic` features.
|
8
|
+
Please install [y_support gem] before trying it.
|
9
|
+
```ruby
|
10
|
+
require 'yzz'
|
11
|
+
require 'y_support/name_magic'
|
8
12
|
|
9
|
-
|
13
|
+
# Let's establish a new class and imbue it with Yzz quality.
|
14
|
+
#
|
15
|
+
class Cell
|
16
|
+
include Yzz, NameMagic
|
17
|
+
def to_s
|
18
|
+
name ? name.to_s : "#<Cell: #{connections.size} conn.>"
|
19
|
+
end
|
20
|
+
end
|
10
21
|
|
11
|
-
|
22
|
+
# Let's create 6 new cells.
|
23
|
+
A1, A2, A3, B1, B2, B3 = 6.times.map { Cell.new }
|
12
24
|
|
13
|
-
|
25
|
+
# And let's connect them along :x and :y dimensions:
|
26
|
+
A1.along( :x ) >> A2 >> A3
|
27
|
+
B1.along( :x ) >> B2 >> B3
|
28
|
+
A1.along( :y ) >> B1
|
29
|
+
A2.along( :y ) >> B2
|
30
|
+
A3.along( :y ) >> B3
|
14
31
|
|
15
|
-
|
32
|
+
# The Zz structure that we have created looks like this:
|
33
|
+
#
|
34
|
+
# a1 --> a2 --> a3
|
35
|
+
# | | |
|
36
|
+
# | | |
|
37
|
+
# v v v
|
38
|
+
# b1 --> b2 --> b3
|
39
|
+
#
|
40
|
+
# The above structure is a little bit like a small spreadsheet 3×2.
|
16
41
|
|
17
|
-
|
42
|
+
# The structure can be investigated:
|
43
|
+
A1.neighbors # gives all the neighbors of A1
|
44
|
+
#=> [A2, B1]
|
45
|
+
A1.towards A2 # returns all the sides of A1 facing A2
|
46
|
+
#=> [#<Yzz::Side: A1 along x, posward>]
|
47
|
+
A1.tw A2 # more concise way of showing the sides facing A2
|
48
|
+
#=> x->
|
49
|
+
A1.tw B1
|
50
|
+
#=> y->
|
18
51
|
|
19
|
-
|
52
|
+
# Of course, more complicated Zz structures can be created. See the [online
|
53
|
+
# presentation at xanadu.com for more](http://xanadu.com/zigzag/). For a small
|
54
|
+
# example here, let's create 2 diagonal connections:
|
20
55
|
|
21
|
-
|
22
|
-
|
56
|
+
A1.along( :diagonal ) >> B2
|
57
|
+
A2.along( :diagonal ) >> B3
|
58
|
+
A1.tw B2
|
59
|
+
#=> diagonal->
|
60
|
+
A1.neighbors
|
61
|
+
#=> [A2, B1, B2]
|
62
|
+
```
|
23
63
|
|
24
64
|
## Contributing
|
25
65
|
|
data/lib/yzz.rb
CHANGED
@@ -67,6 +67,12 @@ module Yzz
|
|
67
67
|
connectivity.select { |side| side.neighbor == other }
|
68
68
|
end
|
69
69
|
|
70
|
+
# Prints the labels of the sides facing towards a given zz object.
|
71
|
+
#
|
72
|
+
def tw other
|
73
|
+
puts towards( other ).map &:label
|
74
|
+
end
|
75
|
+
|
70
76
|
# Short string describing the object.
|
71
77
|
#
|
72
78
|
def to_s
|
data/lib/yzz/side.rb
CHANGED
@@ -66,12 +66,6 @@ class Yzz::Side
|
|
66
66
|
end
|
67
67
|
alias * crossover
|
68
68
|
|
69
|
-
# Returns the string briefly describing the instance.
|
70
|
-
#
|
71
|
-
def to_s
|
72
|
-
"#<YTed::Zz::Side: #{direction} side of #{zz} along #{dimension}>"
|
73
|
-
end
|
74
|
-
|
75
69
|
# Given a zz object (named argument :of), returns its side along same
|
76
70
|
# dimension, in the direction same as self.
|
77
71
|
#
|
@@ -94,6 +88,24 @@ class Yzz::Side
|
|
94
88
|
end
|
95
89
|
end
|
96
90
|
|
91
|
+
# Returns the "side label" string.
|
92
|
+
#
|
93
|
+
def label
|
94
|
+
direction == :posward ? "#{dimension}->" : "<-#{dimension}"
|
95
|
+
end
|
96
|
+
|
97
|
+
# Returns the string briefly describing the instance.
|
98
|
+
#
|
99
|
+
def to_s
|
100
|
+
"#<Yzz::Side: #{zz} along #{dimension}, #{direction}>"
|
101
|
+
end
|
102
|
+
|
103
|
+
# Inspect string of the instance.
|
104
|
+
#
|
105
|
+
def inspect
|
106
|
+
to_s
|
107
|
+
end
|
108
|
+
|
97
109
|
protected
|
98
110
|
|
99
111
|
# Sets neighbor carelessly, returning the old neighbor.
|
data/lib/yzz/side_pair.rb
CHANGED
@@ -44,6 +44,12 @@ class Yzz::SidePair
|
|
44
44
|
# Returns the string briefly describing the instance.
|
45
45
|
#
|
46
46
|
def to_s
|
47
|
-
"#<
|
47
|
+
"#<Yzz::SidePair: #{zz} along #{dimension}>"
|
48
|
+
end
|
49
|
+
|
50
|
+
# Instance inspect string.
|
51
|
+
#
|
52
|
+
def inspect
|
53
|
+
to_s
|
48
54
|
end
|
49
55
|
end # class YTed::Zz::SidePair
|
data/lib/yzz/version.rb
CHANGED
data/test/yzz_test.rb
CHANGED