NGSLib-RFile 0.5

Sign up to get free protection for your applications and to get access to all the features.
data/docs/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ Copyright (c) 2006, Christopher Maujean and project contributors
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+ * Neither the name of the NGSLib nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9
+
10
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,111 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: NGSLib</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">NGSLib</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/rfile/lib/rfile_rb.html">
59
+ rfile/lib/rfile.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ </table>
66
+ </div>
67
+ <!-- banner header -->
68
+
69
+ <div id="bodyContent">
70
+
71
+
72
+
73
+ <div id="contextContent">
74
+
75
+
76
+
77
+ </div>
78
+
79
+
80
+ </div>
81
+
82
+
83
+ <!-- if includes -->
84
+
85
+ <div id="section">
86
+
87
+ <div id="class-list">
88
+ <h3 class="section-bar">Classes and Modules</h3>
89
+
90
+ Class <a href="NGSLib/RFile.html" class="link">NGSLib::RFile</a><br />
91
+
92
+ </div>
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+ <!-- if method_list -->
101
+
102
+
103
+ </div>
104
+
105
+
106
+ <div id="validator-badges">
107
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
108
+ </div>
109
+
110
+ </body>
111
+ </html>
@@ -0,0 +1,212 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: NGSLib::RFile</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">NGSLib::RFile</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../files/rfile/lib/rfile_rb.html">
59
+ rfile/lib/rfile.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ Object
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+ <div id="description">
82
+ <p>
83
+ This class is a line oriented &quot;file&quot; object that operates without
84
+ keeping the file in memory. Enumerable is mixed in, so see Enumerable for
85
+ more information.
86
+ </p>
87
+
88
+ </div>
89
+
90
+
91
+ </div>
92
+
93
+ <div id="method-list">
94
+ <h3 class="section-bar">Methods</h3>
95
+
96
+ <div class="name-list">
97
+ <a href="#M000009">each</a>&nbsp;&nbsp;
98
+ <a href="#M000008">line</a>&nbsp;&nbsp;
99
+ <a href="#M000006">new</a>&nbsp;&nbsp;
100
+ <a href="#M000007">randomline</a>&nbsp;&nbsp;
101
+ </div>
102
+ </div>
103
+
104
+ </div>
105
+
106
+
107
+ <!-- if includes -->
108
+ <div id="includes">
109
+ <h3 class="section-bar">Included Modules</h3>
110
+
111
+ <div id="includes-list">
112
+ <span class="include-name">Enumerable</span>
113
+ </div>
114
+ </div>
115
+
116
+ <div id="section">
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+ <!-- if method_list -->
126
+ <div id="methods">
127
+ <h3 class="section-bar">Public Class methods</h3>
128
+
129
+ <div id="method-M000006" class="method-detail">
130
+ <a name="M000006"></a>
131
+
132
+ <div class="method-heading">
133
+ <a href="RFile.src/M000006.html" target="Code" class="method-signature"
134
+ onclick="popupCode('RFile.src/M000006.html');return false;">
135
+ <span class="method-name">new</span><span class="method-args">(filename)</span>
136
+ </a>
137
+ </div>
138
+
139
+ <div class="method-description">
140
+ <p>
141
+ indexes the file.
142
+ </p>
143
+ </div>
144
+ </div>
145
+
146
+ <h3 class="section-bar">Public Instance methods</h3>
147
+
148
+ <div id="method-M000009" class="method-detail">
149
+ <a name="M000009"></a>
150
+
151
+ <div class="method-heading">
152
+ <a href="RFile.src/M000009.html" target="Code" class="method-signature"
153
+ onclick="popupCode('RFile.src/M000009.html');return false;">
154
+ <span class="method-name">each</span><span class="method-args">() {|line(i) unless entry.nil?| ...}</span>
155
+ </a>
156
+ </div>
157
+
158
+ <div class="method-description">
159
+ <p>
160
+ yields each line in the file, in turn. currently io intensive as it will
161
+ open and close the file for each line. but thats the price you pay.
162
+ </p>
163
+ </div>
164
+ </div>
165
+
166
+ <div id="method-M000008" class="method-detail">
167
+ <a name="M000008"></a>
168
+
169
+ <div class="method-heading">
170
+ <a href="RFile.src/M000008.html" target="Code" class="method-signature"
171
+ onclick="popupCode('RFile.src/M000008.html');return false;">
172
+ <span class="method-name">line</span><span class="method-args">(num)</span>
173
+ </a>
174
+ </div>
175
+
176
+ <div class="method-description">
177
+ <p>
178
+ returns the line at num
179
+ </p>
180
+ </div>
181
+ </div>
182
+
183
+ <div id="method-M000007" class="method-detail">
184
+ <a name="M000007"></a>
185
+
186
+ <div class="method-heading">
187
+ <a href="RFile.src/M000007.html" target="Code" class="method-signature"
188
+ onclick="popupCode('RFile.src/M000007.html');return false;">
189
+ <span class="method-name">randomline</span><span class="method-args">()</span>
190
+ </a>
191
+ </div>
192
+
193
+ <div class="method-description">
194
+ <p>
195
+ returns a random line from the file, deleting its index
196
+ </p>
197
+ </div>
198
+ </div>
199
+
200
+
201
+ </div>
202
+
203
+
204
+ </div>
205
+
206
+
207
+ <div id="validator-badges">
208
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
209
+ </div>
210
+
211
+ </body>
212
+ </html>
@@ -0,0 +1,29 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>new (NGSLib::RFile)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File rfile/lib/rfile.rb, line 13</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">filename</span>)
15
+ <span class="ruby-ivar">@filename</span> = <span class="ruby-identifier">filename</span>
16
+ <span class="ruby-ivar">@index</span> = []
17
+ <span class="ruby-ivar">@rndindex</span> = []
18
+ <span class="ruby-identifier">count</span> = <span class="ruby-value">1</span>
19
+ <span class="ruby-identifier">offset</span> = <span class="ruby-value">1</span>
20
+
21
+ <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-ivar">@filename</span>).<span class="ruby-identifier">each_line</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span>
22
+ <span class="ruby-ivar">@index</span>[<span class="ruby-identifier">count</span>] = [<span class="ruby-identifier">line</span>.<span class="ruby-identifier">length</span>, <span class="ruby-identifier">offset</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>]
23
+ <span class="ruby-identifier">offset</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">length</span>
24
+ <span class="ruby-identifier">count</span><span class="ruby-operator">+=</span><span class="ruby-value">1</span>
25
+ <span class="ruby-keyword kw">end</span>
26
+ <span class="ruby-ivar">@rndindex</span> = <span class="ruby-ivar">@index</span>.<span class="ruby-identifier">clone</span>
27
+ <span class="ruby-keyword kw">end</span></pre>
28
+ </body>
29
+ </html>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>randomline (NGSLib::RFile)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File rfile/lib/rfile.rb, line 29</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">randomline</span>
15
+ <span class="ruby-identifier">entry</span> = <span class="ruby-keyword kw">nil</span>
16
+ <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">entry</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@rndindex</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
17
+ <span class="ruby-identifier">entry</span> = <span class="ruby-ivar">@rndindex</span>.<span class="ruby-identifier">delete_at</span>(<span class="ruby-identifier">rand</span>(<span class="ruby-ivar">@rndindex</span>.<span class="ruby-identifier">length</span>))
18
+ <span class="ruby-keyword kw">end</span>
19
+ <span class="ruby-identifier">entry</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">2</span> <span class="ruby-keyword kw">and</span> <span class="ruby-constant">IO</span>.<span class="ruby-identifier">read</span>(<span class="ruby-ivar">@filename</span>, <span class="ruby-identifier">entry</span>[<span class="ruby-value">0</span>], <span class="ruby-identifier">entry</span>[<span class="ruby-value">1</span>]).<span class="ruby-identifier">chomp</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">entry</span>.<span class="ruby-identifier">nil?</span>
20
+ <span class="ruby-keyword kw">end</span></pre>
21
+ </body>
22
+ </html>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>line (NGSLib::RFile)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File rfile/lib/rfile.rb, line 38</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">line</span>(<span class="ruby-identifier">num</span>)
15
+ <span class="ruby-identifier">entry</span> = <span class="ruby-ivar">@index</span>[<span class="ruby-identifier">num</span>]
16
+ <span class="ruby-keyword kw">return</span> <span class="ruby-constant">IO</span>.<span class="ruby-identifier">read</span>(<span class="ruby-ivar">@filename</span>, <span class="ruby-identifier">entry</span>[<span class="ruby-value">0</span>], <span class="ruby-identifier">entry</span>[<span class="ruby-value">1</span>]).<span class="ruby-identifier">chomp</span>
17
+ <span class="ruby-keyword kw">end</span></pre>
18
+ </body>
19
+ </html>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>each (NGSLib::RFile)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File rfile/lib/rfile.rb, line 46</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each</span>
15
+ <span class="ruby-ivar">@index</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">entry</span>,<span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
16
+ <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">line</span>(<span class="ruby-identifier">i</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">entry</span>.<span class="ruby-identifier">nil?</span>
17
+ <span class="ruby-keyword kw">end</span>
18
+ <span class="ruby-keyword kw">end</span></pre>
19
+ </body>
20
+ </html>
data/docs/created.rid ADDED
@@ -0,0 +1 @@
1
+ Sat Aug 12 19:17:51 PDT 2006
@@ -0,0 +1,101 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>File: rfile.rb</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="fileHeader">
50
+ <h1>rfile.rb</h1>
51
+ <table class="header-table">
52
+ <tr class="top-aligned-row">
53
+ <td><strong>Path:</strong></td>
54
+ <td>rfile/lib/rfile.rb
55
+ </td>
56
+ </tr>
57
+ <tr class="top-aligned-row">
58
+ <td><strong>Last Update:</strong></td>
59
+ <td>Sat Aug 12 19:03:36 PDT 2006</td>
60
+ </tr>
61
+ </table>
62
+ </div>
63
+ <!-- banner header -->
64
+
65
+ <div id="bodyContent">
66
+
67
+
68
+
69
+ <div id="contextContent">
70
+
71
+
72
+
73
+ </div>
74
+
75
+
76
+ </div>
77
+
78
+
79
+ <!-- if includes -->
80
+
81
+ <div id="section">
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+ <!-- if method_list -->
91
+
92
+
93
+ </div>
94
+
95
+
96
+ <div id="validator-badges">
97
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
98
+ </div>
99
+
100
+ </body>
101
+ </html>
@@ -0,0 +1,28 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Classes
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Classes</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Classes</h1>
22
+ <div id="index-entries">
23
+ <a href="classes/NGSLib.html">NGSLib</a><br />
24
+ <a href="classes/NGSLib/RFile.html">NGSLib::RFile</a><br />
25
+ </div>
26
+ </div>
27
+ </body>
28
+ </html>
@@ -0,0 +1,27 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Files
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Files</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Files</h1>
22
+ <div id="index-entries">
23
+ <a href="files/rfile/lib/rfile_rb.html">rfile/lib/rfile.rb</a><br />
24
+ </div>
25
+ </div>
26
+ </body>
27
+ </html>
@@ -0,0 +1,30 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Methods
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Methods</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Methods</h1>
22
+ <div id="index-entries">
23
+ <a href="classes/NGSLib/RFile.html#M000009">each (NGSLib::RFile)</a><br />
24
+ <a href="classes/NGSLib/RFile.html#M000008">line (NGSLib::RFile)</a><br />
25
+ <a href="classes/NGSLib/RFile.html#M000006">new (NGSLib::RFile)</a><br />
26
+ <a href="classes/NGSLib/RFile.html#M000007">randomline (NGSLib::RFile)</a><br />
27
+ </div>
28
+ </div>
29
+ </body>
30
+ </html>
data/docs/index.html ADDED
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
5
+
6
+ <!--
7
+
8
+ RDoc Documentation
9
+
10
+ -->
11
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
12
+ <head>
13
+ <title>RDoc Documentation</title>
14
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
15
+ </head>
16
+ <frameset rows="20%, 80%">
17
+ <frameset cols="25%,35%,45%">
18
+ <frame src="fr_file_index.html" title="Files" name="Files" />
19
+ <frame src="fr_class_index.html" name="Classes" />
20
+ <frame src="fr_method_index.html" name="Methods" />
21
+ </frameset>
22
+ <frame src="files/rfile/lib/rfile_rb.html" name="docwin" />
23
+ </frameset>
24
+ </html>
data/lib/rfile.rb ADDED
@@ -0,0 +1,54 @@
1
+ module NGSLib
2
+ # This class is a line oriented "file" object that operates
3
+ # without keeping the file in memory.
4
+ # Enumerable is mixed in, so see Enumerable for more
5
+ # information.
6
+ class NGSLib::RFile
7
+ include Enumerable
8
+
9
+ # indexes the file.
10
+ #--
11
+ # storing line information (offset and length)
12
+ #++
13
+ def initialize(filename)
14
+ @filename = filename
15
+ @index = []
16
+ @rndindex = []
17
+ count = 1
18
+ offset = 1
19
+
20
+ File.open(@filename).each_line do |line|
21
+ @index[count] = [line.length, offset-1]
22
+ offset += line.length
23
+ count+=1
24
+ end
25
+ @rndindex = @index.clone
26
+ end
27
+
28
+ # returns a random line from the file, deleting its index
29
+ def randomline
30
+ entry = nil
31
+ while entry.nil? and @rndindex.length > 0
32
+ entry = @rndindex.delete_at(rand(@rndindex.length))
33
+ end
34
+ entry.length == 2 and IO.read(@filename, entry[0], entry[1]).chomp unless entry.nil?
35
+ end
36
+
37
+ # returns the line at num
38
+ def line(num)
39
+ entry = @index[num]
40
+ return IO.read(@filename, entry[0], entry[1]).chomp
41
+ end
42
+
43
+ # yields each line in the file, in turn.
44
+ # currently io intensive as it will open and close the file
45
+ # for each line. but thats the price you pay.
46
+ def each
47
+ @index.each_with_index do |entry,i|
48
+ yield line(i) unless entry.nil?
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ # vi:sw=2 ts=2
@@ -0,0 +1,3 @@
1
+ Line 1
2
+ Line 2
3
+ Line 3
data/test/tc_rfile.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'rfile'
2
+ require 'test/unit'
3
+
4
+ class TestRFile < Test::Unit::TestCase
5
+ def setup
6
+ @f = NGSLib::RFile.new("rfile/test/data/testfile")
7
+ end
8
+
9
+ def test_rfile
10
+ assert(@f.randomline.is_a?(String), "line is a string")
11
+ testline = @f.randomline
12
+ assert((testline == "Line 1" or testline == "Line 2" or testline == "Line 3"), "Line is valid: #{testline}")
13
+ assert(@f.randomline)
14
+ assert(@f.line(1) == "Line 1", "line(1) returns Line 1: #{@f.line(1)}")
15
+ end
16
+
17
+ def test_enum_mixin
18
+ count = 0
19
+ @f.each_with_index do |l,i|
20
+ case i
21
+ when 0
22
+ assert_equal(l, "Line 1")
23
+ when 1
24
+ assert_equal(l, "Line 2")
25
+ when 2
26
+ assert_equal(l, "Line 3")
27
+ end
28
+ count+=1
29
+ end
30
+ assert count == 3, "EACH TEST: count should be 3 count is #{count}"
31
+
32
+ assert( "Line 3" == @f.detect {|t| t.split(" ")[1].to_i == 3}, "Enum: testing detect { } " )
33
+ assert( @f.reject {|t| t == "Line 3"} == ["Line 1", "Line 2"], "Enum: testing reject { }" )
34
+ assert( @f.collect {|t| "This is " + t } == ["This is Line 1", "This is Line 2", "This is Line 3"], "Enum: testing collect")
35
+ end
36
+ end
37
+
38
+ # vi:sw=2 ts=2
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: NGSLib-RFile
5
+ version: !ruby/object:Gem::Version
6
+ version: "0.5"
7
+ date: 2006-08-12 00:00:00 -07:00
8
+ summary: a read only, line oriented, sparse file class
9
+ require_paths:
10
+ - lib
11
+ email: cmaujean@gmail.com
12
+ homepage: http://rubyforge.org/projects/ngslib
13
+ rubyforge_project:
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Christopher Maujean
31
+ files:
32
+ - docs/created.rid
33
+ - docs/files
34
+ - docs/classes
35
+ - docs/fr_file_index.html
36
+ - docs/fr_class_index.html
37
+ - docs/fr_method_index.html
38
+ - docs/index.html
39
+ - docs/LICENSE
40
+ - docs/files/rfile
41
+ - docs/files/rfile/lib
42
+ - docs/files/rfile/lib/rfile_rb.html
43
+ - docs/classes/NGSLib
44
+ - docs/classes/NGSLib.html
45
+ - docs/classes/NGSLib/RFile.src
46
+ - docs/classes/NGSLib/RFile.html
47
+ - docs/classes/NGSLib/RFile.src/M000006.html
48
+ - docs/classes/NGSLib/RFile.src/M000007.html
49
+ - docs/classes/NGSLib/RFile.src/M000008.html
50
+ - docs/classes/NGSLib/RFile.src/M000009.html
51
+ - lib/rfile.rb
52
+ - test/data
53
+ - test/tc_rfile.rb
54
+ - test/data/testfile
55
+ test_files:
56
+ - test/tc_rfile.rb
57
+ rdoc_options: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ executables: []
62
+
63
+ extensions: []
64
+
65
+ requirements: []
66
+
67
+ dependencies: []
68
+