-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathFactoryExample.rb.html
147 lines (135 loc) · 7.64 KB
/
FactoryExample.rb.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>FactoryExample.rb</title>
<meta name="generator" content="emacs 24.1.1; htmlfontify 0.21" />
<style type="text/css"><!--
body { font-family: Ubuntu Mono; font-stretch: normal; font-weight: 500; font-style: normal; color: #000000; background: #ffffff; font-size: 13pt; text-decoration: none; }
span.default { font-family: Ubuntu Mono; font-stretch: normal; font-weight: 500; font-style: normal; color: #000000; background: #ffffff; font-size: 13pt; text-decoration: none; }
span.default a { font-family: Ubuntu Mono; font-stretch: normal; font-weight: 500; font-style: normal; color: #000000; background: #ffffff; font-size: 13pt; text-decoration: underline; }
span.string { color: #8b2252; font-family: Ubuntu Mono; font-stretch: normal; font-weight: 500; font-style: normal; background: #ffffff; font-size: 13pt; text-decoration: none; }
span.string a { color: #8b2252; font-family: Ubuntu Mono; font-stretch: normal; font-weight: 500; font-style: normal; background: #ffffff; font-size: 13pt; text-decoration: underline; }
span.variable-name { color: #a0522d; font-family: Ubuntu Mono; font-stretch: normal; font-weight: 500; font-style: normal; background: #ffffff; font-size: 13pt; text-decoration: none; }
span.variable-name a { color: #a0522d; font-family: Ubuntu Mono; font-stretch: normal; font-weight: 500; font-style: normal; background: #ffffff; font-size: 13pt; text-decoration: underline; }
span.function-name { color: #0000ff; font-family: Ubuntu Mono; font-stretch: normal; font-weight: 500; font-style: normal; background: #ffffff; font-size: 13pt; text-decoration: none; }
span.function-name a { color: #0000ff; font-family: Ubuntu Mono; font-stretch: normal; font-weight: 500; font-style: normal; background: #ffffff; font-size: 13pt; text-decoration: underline; }
span.type { color: #228b22; font-family: Ubuntu Mono; font-stretch: normal; font-weight: 500; font-style: normal; background: #ffffff; font-size: 13pt; text-decoration: none; }
span.type a { color: #228b22; font-family: Ubuntu Mono; font-stretch: normal; font-weight: 500; font-style: normal; background: #ffffff; font-size: 13pt; text-decoration: underline; }
span.keyword { color: #a020f0; font-family: Ubuntu Mono; font-stretch: normal; font-weight: 500; font-style: normal; background: #ffffff; font-size: 13pt; text-decoration: none; }
span.keyword a { color: #a020f0; font-family: Ubuntu Mono; font-stretch: normal; font-weight: 500; font-style: normal; background: #ffffff; font-size: 13pt; text-decoration: underline; }
--></style>
<script type="text/javascript"><!--
// this function is needed to work around
// a bug in IE related to element attributes
function hasClass(obj)
{
var result = false;
if (obj.getAttributeNode("class") != null)
{
result = obj.getAttributeNode("class").value;
}
return result;
}
function stripe(id)
{
// the flag we'll use to keep track of
// whether the current row is odd or even
var even = false;
// if arguments are provided to specify the colors
// of the even & odd rows, then use the them;
// otherwise use the following defaults:
var evenColor = arguments[1] ? arguments[1] : "#fff";
var oddColor = arguments[2] ? arguments[2] : "#ddd";
// obtain a reference to the desired table
// if no such table exists, abort
var table = document.getElementById(id);
if (! table) { return; }
// by definition, tables can have more than one tbody
// element, so we'll have to get the list of child
// <tbody>s
var tbodies = table.getElementsByTagName("tbody");
// and iterate through them...
for (var h = 0; h < tbodies.length; h++)
{
// find all the <tr> elements...
var trs = tbodies[h].getElementsByTagName("tr");
// ... and iterate through them
for (var i = 0; i < trs.length; i++)
{
// avoid rows that have a class attribute
// or backgroundColor style
if (! hasClass(trs[i]) &&
! trs[i].style.backgroundColor)
{
// get all the cells in this row...
var tds = trs[i].getElementsByTagName("td");
// and iterate through them...
for (var j = 0; j < tds.length; j++)
{
var mytd = tds[j];
// avoid cells that have a class attribute
// or backgroundColor style
if (! hasClass(mytd) &&
! mytd.style.backgroundColor)
{
mytd.style.backgroundColor =
even ? evenColor : oddColor;
}
}
}
// flip from odd to even, or vice-versa
even = ! even;
}
}
}
function toggle_invis( name )
{
var filter =
{ acceptNode:
function( node )
{ var classname = node.id;
if( classname )
{ var classbase = classname.substr( 0, name.length );
if( classbase == name ) { return NodeFilter.FILTER_ACCEPT; } }
return NodeFilter.FILTER_SKIP; } };
var walker = document.createTreeWalker( document.body ,
NodeFilter.SHOW_ELEMENT ,
filter ,
false );
while( walker.nextNode() )
{
var e = walker.currentNode;
if( e.style.display == "none" ) { e.style.display = "inline"; }
else { e.style.display = "none"; }
}
}
--> </script>
</head>
<body onload="stripe('index'); return true;">
<pre><span class="keyword">class</span> <span class="type">CommandFactory</span>
<span class="keyword">def</span> <span class="function-name">initialize</span>(context)
<span class="variable-name">@context</span> = context
<span class="keyword">end</span>
<span class="keyword">def</span> <span class="function-name">create_command</span>(name)
<span class="keyword">if</span> (name == <span class="string">"Paste"</span>)
<span class="keyword">return</span> <span class="type">PasteCommand</span>.new(<span class="variable-name">@context</span>)
<span class="keyword">else</span> <span class="keyword">if</span> (name == <span class="string">"Cut"</span>)
<span class="keyword">return</span> <span class="type">CutCommand</span>.new(<span class="variable-name">@context</span>)
<span class="keyword">else</span>
<span class="keyword">throw</span> (<span class="string">"Could Not Construct "</span>+name)
<span class="keyword">end</span>
<span class="keyword">end</span>
<span class="keyword">end</span>
<span class="keyword">class</span> <span class="type">PasteCommand</span>
<span class="keyword">def</span> <span class="function-name">initialize</span>(context)
<span class="keyword">end</span>
<span class="keyword">end</span>
<span class="keyword">class</span> <span class="type">CutCommand</span>
<span class="keyword">def</span> <span class="function-name">initialize</span>(context)
<span class="keyword">end</span>
<span class="keyword">en</span><span class="keyword">d</span>
</pre>
</body>
</html>