rfile 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rfile.rb +15 -7
  2. metadata +5 -5
@@ -1,13 +1,17 @@
1
- # $Id: rfile.rb 44 2006-08-13 23:18:33Z cmaujean $
1
+ # $Id: rfile.rb 46 2006-08-14 06:13:47Z cmaujean $
2
+ #
2
3
  # See LICENSE for copyright information
4
+ #
3
5
  # This class is a line oriented "file" object that operates
4
6
  # without keeping the file in memory.
7
+ #
5
8
  # Enumerable is mixed in, so see Enumerable for more
6
9
  # information.
10
+ #
7
11
  class RFile
8
12
  include Enumerable
9
13
 
10
- # indexes the file.
14
+ # parses and indexes <i>filename</i>.
11
15
  #--
12
16
  # storing line information (offset and length)
13
17
  #++
@@ -26,13 +30,15 @@ class RFile
26
30
  @rndindex = @index.clone
27
31
  end
28
32
 
29
- # returns a random line from the file, deleting its index
33
+ # returns a random line from the file. will not repeat lines.
34
+ # returns nil when the file is exausted. note: does not modify file.
30
35
  def randomline
31
36
  entry = nil
32
37
  while entry.nil? and @rndindex.length > 0
33
38
  entry = @rndindex.delete_at(rand(@rndindex.length))
34
39
  end
35
- entry.length == 2 and IO.read(@filename, entry[0], entry[1]).chomp unless entry.nil?
40
+ entry.nil? and return nil
41
+ entry.length == 2 and return IO.read(@filename, entry[0], entry[1]).chomp
36
42
  end
37
43
 
38
44
  # returns the line at num
@@ -42,9 +48,11 @@ class RFile
42
48
  end
43
49
 
44
50
  # yields each line in the file, in turn.
45
- # currently io intensive as it will open and close the file
46
- # for each line. but thats the price you pay.
47
- def each
51
+ #
52
+ # note: currently IO intensive as it will open and close the file
53
+ # for each line.
54
+ #
55
+ def each # :yields:line
48
56
  @index.each_with_index do |entry,i|
49
57
  yield line(i) unless entry.nil?
50
58
  end
metadata CHANGED
@@ -3,14 +3,14 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: rfile
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
6
+ version: 0.1.1
7
7
  date: 2006-08-13 00:00:00 -07:00
8
8
  summary: a read only, line oriented, sparse file class
9
9
  require_paths:
10
10
  - lib
11
11
  email: cmaujean@gmail.com
12
12
  homepage: http://rubyforge.org/projects/ngslib
13
- rubyforge_project:
13
+ rubyforge_project: ngslib
14
14
  description:
15
15
  autorequire:
16
16
  default_executable:
@@ -31,15 +31,15 @@ authors:
31
31
  files:
32
32
  - lib/rfile.rb
33
33
  - lib/LICENSE
34
- - test/tc_rfile.rb
35
34
  - test/data
35
+ - test/tc_rfile.rb
36
36
  - test/data/testfile
37
37
  test_files:
38
38
  - test/tc_rfile.rb
39
39
  rdoc_options: []
40
40
 
41
- extra_rdoc_files: []
42
-
41
+ extra_rdoc_files:
42
+ - lib/LICENSE
43
43
  executables: []
44
44
 
45
45
  extensions: []