linux_fortune 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -1
- data/Rakefile +1 -1
- data/lib/linux_fortune.rb +9 -52
- data/linux_fortune.gemspec +2 -2
- data/test/test_linux_fortune.rb +9 -12
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
data/History.txt
CHANGED
@@ -12,4 +12,10 @@
|
|
12
12
|
=== 0.0.3 2010-03-24
|
13
13
|
|
14
14
|
* 1 major enhancement:
|
15
|
-
* fortune sources listing / selection
|
15
|
+
* fortune sources listing / selection
|
16
|
+
|
17
|
+
=== 0.0.4 2010-03-25
|
18
|
+
|
19
|
+
* 2 minor enhancements:
|
20
|
+
* some of "gregory's anonymous class hacks":http://blog.rubybestpractices.com/posts/gregory/anonymous_class_hacks.html rbp's implemented
|
21
|
+
* updated testing
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('linux_fortune', '0.0.
|
5
|
+
Echoe.new('linux_fortune', '0.0.4') do |p|
|
6
6
|
p.description = "A gem that provides a wrapper for the linux fortune program"
|
7
7
|
p.url = "http://github.com/srejbi/linux_fortune"
|
8
8
|
p.author = "George Schreiber"
|
data/lib/linux_fortune.rb
CHANGED
@@ -92,46 +92,21 @@ module LinuxFortune
|
|
92
92
|
# fortune source class
|
93
93
|
# basically a couple of strings to construct the db file path
|
94
94
|
# and the weight (in percentage) of the file (compared to 100%)
|
95
|
-
|
96
|
-
@path = "/usr/share/fortune"
|
97
|
-
@source = ""
|
98
|
-
@weight = ""
|
99
|
-
|
95
|
+
FortuneSource = Class.new do
|
100
96
|
# create a new source reference with source, path and weight
|
101
97
|
def initialize(source = nil, path = "/usr/share/fortune", weight = nil )
|
102
98
|
@source = source
|
103
99
|
@path = path
|
104
100
|
@weight = weight
|
105
101
|
end
|
106
|
-
|
107
|
-
# sets the fortune source path
|
108
|
-
def path=(srcpath)
|
109
|
-
@path = srcpath
|
110
|
-
end
|
111
|
-
|
112
|
-
# gets the source path (directory with source)
|
113
|
-
def path
|
114
|
-
@path
|
115
|
-
end
|
116
|
-
|
117
|
-
# sets the source file name (file in FortuneSource.path)
|
118
|
-
def source=(src)
|
119
|
-
@source = src
|
120
|
-
end
|
121
|
-
|
122
|
-
# gets source file name
|
123
|
-
def source
|
124
|
-
@source
|
125
|
-
end
|
126
|
-
|
127
|
-
def weight
|
128
|
-
@weight
|
129
|
-
end
|
102
|
+
attr_reader :source, :path, :weight
|
130
103
|
|
131
104
|
# gets full path to the source
|
132
105
|
def fullpath
|
133
106
|
File.join(@path, @source)
|
134
107
|
end
|
108
|
+
# gets the full path to the message
|
109
|
+
alias_method(:to_s, :fullpath)
|
135
110
|
|
136
111
|
# gets a fortune message from this source
|
137
112
|
def fortune
|
@@ -141,10 +116,7 @@ module LinuxFortune
|
|
141
116
|
|
142
117
|
|
143
118
|
# The Fortune class is basicly 2 strings, source and body
|
144
|
-
|
145
|
-
@source = ""
|
146
|
-
@body = ""
|
147
|
-
|
119
|
+
Fortune = Class.new do
|
148
120
|
# pass the string from the fortune program
|
149
121
|
def initialize(fortunestring)
|
150
122
|
# check lines of the string, extract source and separate from the rest of the body
|
@@ -162,27 +134,12 @@ module LinuxFortune
|
|
162
134
|
end
|
163
135
|
# attribute accessors
|
164
136
|
|
165
|
-
|
166
|
-
|
167
|
-
@body
|
168
|
-
end
|
137
|
+
attr_reader :body, :source
|
138
|
+
|
169
139
|
# gets the fortune text (alias for body)
|
170
140
|
alias_method(:to_s, :body)
|
171
|
-
|
172
|
-
# gets the fortune source
|
173
|
-
def source
|
174
|
-
@source
|
175
|
-
end
|
176
|
-
|
177
|
-
def body=(text = "")
|
178
|
-
@body = text
|
179
|
-
end
|
180
|
-
|
181
|
-
def source=(src = "")
|
182
|
-
@source = src
|
183
|
-
end
|
184
|
-
|
185
141
|
end
|
142
|
+
|
186
143
|
|
187
144
|
# list available sources
|
188
145
|
def self.get_sources
|
@@ -203,7 +160,7 @@ module LinuxFortune
|
|
203
160
|
# executes the fortune program
|
204
161
|
def self.fortune(sources = nil)
|
205
162
|
#puts "executing #{self.binary_path} -c #{fortune_options} #{sources.each { |s| s.strip }.join(" ") unless sources.nil?} 2>&1"
|
206
|
-
`#{self.binary_path} -c #{fortune_options} #{sources.each { |s| s.
|
163
|
+
`#{self.binary_path} -c #{fortune_options} #{sources.each { |s| s.to_s }.join(" ") unless sources.nil?} 2>&1`
|
207
164
|
end
|
208
165
|
|
209
166
|
# generates a fortune message
|
data/linux_fortune.gemspec
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{linux_fortune}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["George Schreiber"]
|
9
9
|
s.cert_chain = ["/home/george/.ssh/gem/gem-public_cert.pem"]
|
10
|
-
s.date = %q{2010-03-
|
10
|
+
s.date = %q{2010-03-25}
|
11
11
|
s.description = %q{A gem that provides a wrapper for the linux fortune program}
|
12
12
|
s.email = %q{gy.schreiber @nospam@ mobility.hu}
|
13
13
|
s.extra_rdoc_files = ["README.rdoc", "lib/linux_fortune.rb"]
|
data/test/test_linux_fortune.rb
CHANGED
@@ -28,7 +28,7 @@ class TestLinuxFortune < Test::Unit::TestCase
|
|
28
28
|
assert LinuxFortune.fortune_options.include?("-n") || LinuxFortune.short_length == 160
|
29
29
|
10.times do # check multiple times if the generated length is ok
|
30
30
|
lf = LinuxFortune.generate
|
31
|
-
assert lf.body.size < LinuxFortune.short_length # check if actual size is less than the max. short length
|
31
|
+
assert lf.body.size*0.9 < LinuxFortune.short_length # check if actual size is less than the max. short length
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -43,7 +43,7 @@ class TestLinuxFortune < Test::Unit::TestCase
|
|
43
43
|
lf = LinuxFortune.generate
|
44
44
|
#puts "#{lf.body.size} characters"
|
45
45
|
# TODO apparently there is an issue with 'fortune -l'; check fortune docs & bugs (manual mentions a different problem
|
46
|
-
assert lf.body.size
|
46
|
+
assert lf.body.size*1.1 >= LinuxFortune.short_length # check if actual size is greater than the max. short length
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -76,15 +76,12 @@ class TestLinuxFortune < Test::Unit::TestCase
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
# test if fortune messages are
|
80
|
-
#
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
#puts lf.source.split("/").last
|
87
|
-
assert ["chucknorris","linux"].include?(lf.source.split("/").last.strip)
|
88
|
-
end
|
79
|
+
# test if fortune messages are generated when passing an array containing
|
80
|
+
# FortuneSource elements
|
81
|
+
def test_fortune_from_all_named_fortune_sources
|
82
|
+
sources = LinuxFortune.get_sources
|
83
|
+
fortunes = []
|
84
|
+
fortunes << LinuxFortune.generate( sources )
|
85
|
+
assert !fortunes.empty?
|
89
86
|
end
|
90
87
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- George Schreiber
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
0ps4N+22wwDW/tu5hg8+hebo
|
36
36
|
-----END CERTIFICATE-----
|
37
37
|
|
38
|
-
date: 2010-03-
|
38
|
+
date: 2010-03-25 00:00:00 +01:00
|
39
39
|
default_executable:
|
40
40
|
dependencies: []
|
41
41
|
|
metadata.gz.sig
CHANGED
Binary file
|