Class: LinuxFortune::Fortune
- Inherits:
-
Object
- Object
- LinuxFortune::Fortune
- Defined in:
- lib/linux_fortune.rb
Overview
The Fortune class is basicly 2 strings, source and body
Instance Method Summary collapse
-
#body ⇒ Object
(also: #to_s)
gets the fortune text.
- #body=(text = "") ⇒ Object
-
#initialize(fortunestring) ⇒ Fortune
constructor
pass the string from the fortune program.
-
#source ⇒ Object
gets the fortune source.
- #source=(src = "") ⇒ Object
Constructor Details
#initialize(fortunestring) ⇒ Fortune
pass the string from the fortune program
149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/linux_fortune.rb', line 149 def initialize(fortunestring) # check lines of the string, extract source and separate from the rest of the body src = "" bod = "" fortunestring.each do |s| if s.match(/\(.*\)/) and src.empty? src = s.gsub(/(^\()|(\)$)/, "").strip else bod += s unless s.match(/^%\n/) end end @source = src @body = bod end |
Instance Method Details
#body ⇒ Object Also known as: to_s
gets the fortune text
166 167 168 |
# File 'lib/linux_fortune.rb', line 166 def body @body end |
#body=(text = "") ⇒ Object
177 178 179 |
# File 'lib/linux_fortune.rb', line 177 def body=(text = "") @body = text end |
#source ⇒ Object
gets the fortune source
173 174 175 |
# File 'lib/linux_fortune.rb', line 173 def source @source end |
#source=(src = "") ⇒ Object
181 182 183 |
# File 'lib/linux_fortune.rb', line 181 def source=(src = "") @source = src end |