rfortune 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +1 -1
  2. data/TODO.rdoc +2 -0
  3. data/lib/rfortune.rb +15 -15
  4. metadata +8 -6
data/README.rdoc CHANGED
@@ -22,7 +22,7 @@ current directory it will be searched beneath /usr/share/games/fortunes.
22
22
 
23
23
  To get a random cookie from the jar simply do:
24
24
 
25
- puts cookies.random
25
+ cookies.random
26
26
 
27
27
  == Copyright
28
28
 
data/TODO.rdoc ADDED
@@ -0,0 +1,2 @@
1
+ == TODO
2
+
data/lib/rfortune.rb CHANGED
@@ -12,7 +12,8 @@
12
12
 
13
13
  class RFortune
14
14
 
15
- FortunesPath = '/usr/share/games/fortunes/'
15
+ # The path to fortune's fortunes directory
16
+ FORTUNES_PATH = '/usr/share/games/fortunes/'
16
17
 
17
18
  # Looks for the specified cookie jar file first localy, than under
18
19
  # /usr/share/games/fortunes, opens it and reads its content to the
@@ -26,34 +27,29 @@ class RFortune
26
27
 
27
28
  if File.exist?( @file_path )
28
29
 
29
- if File.writable?( @file_path )
30
- mode = 'r+'
31
- else
32
- mode = 'r'
33
- end
30
+ cookie_jar_file = File.open( @file_path, 'r' )
34
31
 
35
- cookie_jar_file = File.open( @file_path, mode )
32
+ elsif File.exist?( FORTUNES_PATH + @file_path )
36
33
 
37
- elsif File.exist?( FortunesPath + @file_path )
34
+ cookie_jar_file = File.open( FORTUNES_PATH + @file_path, 'r' )
38
35
 
39
- cookie_jar_file = File.open( FortunesPath + @file_path, 'r' )
36
+ elsif File.exist?( FORTUNES_PATH + 'off/' + @file_path )
40
37
 
41
- elsif File.exist?( FortunesPath + 'off/' + @file_path )
42
-
43
- cookie_jar_file = File.open( FortunesPath + 'off/' + @file_path, 'r' )
38
+ cookie_jar_file = File.open( FORTUNES_PATH + 'off/' + @file_path, 'r' )
44
39
 
45
40
  end
46
41
 
47
42
  end
48
43
 
44
+ # If there is a cookie jar file, read it. Otherwise start with an empty one.
49
45
  unless cookie_jar_file.nil?
50
46
 
51
47
  @cookies = cookie_jar_file.read.split( '%' )
52
48
 
53
49
  cookie_jar_file.close
54
50
 
55
- # delete empty cookies
56
- @cookies.delete_if { |cookie| cookie.match( /^[\r\n\s]+$/ ) }
51
+ # Delete empty cookies
52
+ @cookies.delete_if { |cookie| cookie.match( /\A[\r\n\s]*\Z/ ) }
57
53
 
58
54
  else
59
55
 
@@ -105,13 +101,17 @@ class RFortune
105
101
  end
106
102
 
107
103
  # Saves the content of the jar to the file specified by argument given
108
- # to itself or to the new method
104
+ # to itself or to the initialize method
109
105
  def save new_file_path = nil
110
106
 
107
+ # If there is no new_file_path specified take the path specified
108
+ # at initialization. If thats also not specified raise an error.
111
109
  new_file_path or new_file_path = @file_path or raise 'No file name given'
112
110
 
111
+ # Write all cookies in cookie jar format to the file specified
113
112
  File.open( new_file_path, 'w') { |jar| jar.puts all_formated }
114
113
 
115
114
  end
116
115
 
117
116
  end
117
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfortune
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Helge Rausch
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-30 00:00:00 +01:00
12
+ date: 2009-12-05 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -19,13 +19,15 @@ executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files: []
23
-
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - TODO.rdoc
24
25
  files:
25
26
  - lib/rfortune.rb
26
27
  - test/test_rfortune.rb
27
28
  - LICENSE
28
29
  - README.rdoc
30
+ - TODO.rdoc
29
31
  - VERSION
30
32
  has_rdoc: true
31
33
  homepage: http://github.com/tsujigiri/rfortune
@@ -55,5 +57,5 @@ rubygems_version: 1.3.5
55
57
  signing_key:
56
58
  specification_version: 3
57
59
  summary: RFortune provides handling of cookie jar files as known from 'fortune'
58
- test_files: []
59
-
60
+ test_files:
61
+ - test/test_rfortune.rb