Class: Plugins::Fnord::Fnord

Inherits:
Object
  • Object
show all
Defined in:
lib/Zeta/plugins/fnord.rb

Class Method Summary collapse

Class Method Details

.action(chance = 0) ⇒ Object



255
256
257
# File 'lib/Zeta/plugins/fnord.rb', line 255

def self.action(chance=0)
  (chance==0 or rand(chance)<1) ? ACTIONS[rand(ACTIONS.length)] : ""
end

.adjective(chance = 0) ⇒ Object

Parts of speech functions to return a random word from the arrays and return it if chance==0 or if a random integer between 0 and chance-1 equals 0. The (chance==0) check is to optimize by preventing the rand(chance) call when not required. So for a 1 in 7 chance call with chance=7.



235
236
237
# File 'lib/Zeta/plugins/fnord.rb', line 235

def self.adjective(chance=0)
  (chance==0 or rand(chance)<1) ? ADJECTIVES[rand(ADJECTIVES.length)] : ""
end

.headlineObject



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/Zeta/plugins/fnord.rb', line 271

def self.headline
  number=rand(14)
  msg=case number #Return a generated Fnord as a string
        when 0 then
          "The #{adjective(2)} #{noun} #{in_place(5)} is #{adjective}."
        when 1 then
          "#{name} #{action} the #{adjective} #{noun} and the #{adjective} #{noun}."
        when 2 then
          "The #{noun} from #{place} will go to #{place}."
        when 3 then
          "#{name} must take the #{adjective} #{noun} from #{place}."
        when 4 then
          "#{place} is #{adjective} and the #{noun} is #{adjective}."
        when 5 then
          "#{name} #{preposition} #{place} for the #{adjective} #{noun}."
        when 6 then
          "The #{adjective(2)} #{noun} #{action} the #{adjective} #{noun} #{in_place(5)}."
        when 7 then
          "#{name} #{preposition} #{place} and #{action} the #{noun}."
        when 8 then
          "#{name} takes #{pronoun} #{adjective(2)} #{noun} and #{preposition} #{place}."
        when 9 then
          "#{name} #{action} the #{adjective(2)} #{noun}."
        when 10 then
          "#{name} #{action} #{name} and #{pronoun} #{adjective(2)} #{noun}."
        when 11 then
          "#{name} is the #{adjective(2)} #{noun}; #{name} #{preposition} #{place}."
        when 12 then
          "You must meet #{name} at #{place} and get the #{adjective(2)} #{noun}."
        when 13 then
          "A #{noun} from #{place} #{action} the #{adjective(2)} #{adjective(5)} #{noun}."
      end
  while msg.include?("  ")
    msg.gsub!(/  /, " ") # Collapse multiple spaces into a single one.
  end
  msg.gsub!(/^ /, "") # remove space from the front
  msg.gsub!(/ \./, ".") # remove space from before a "."
  #Extension to allow for placing #{intro} in front of the messages, and keeping
  #the case correct, if required. Not required for the original set of strings,
  #so commented out to prevent unneccessary code execution.
  #while msg[/([^A-Z][\.\!\?\:])\s+([a-z])/]
  #	msg[/([^A-Z][\.\!\?\:])\s+([a-z])/]="#{$1} #{$2.upcase}"
  #end
  msg[0]=msg[0, 1].upcase
  msg
end

.in_place(chance = 0) ⇒ Object



247
248
249
# File 'lib/Zeta/plugins/fnord.rb', line 247

def self.in_place(chance=0)
  (chance==0 or rand(chance)<1) ? "in #{place}" : ""
end

.intro(chance = 0) ⇒ Object



263
264
265
# File 'lib/Zeta/plugins/fnord.rb', line 263

def self.intro(chance=0)
  (chance==0 or rand(chance)<1) ? INTROS[rand(INTROS.length)] : ""
end

.name(chance = 0) ⇒ Object



239
240
241
# File 'lib/Zeta/plugins/fnord.rb', line 239

def self.name(chance=0)
  (chance==0 or rand(chance)<1) ? NAMES[rand(NAMES.length)] : ""
end

.noun(chance = 0) ⇒ Object



267
268
269
# File 'lib/Zeta/plugins/fnord.rb', line 267

def self.noun(chance=0)
  (chance==0 or rand(chance)<1) ? NOUNS[rand(NOUNS.length)] : ""
end

.place(chance = 0) ⇒ Object



243
244
245
# File 'lib/Zeta/plugins/fnord.rb', line 243

def self.place(chance=0)
  (chance==0 or rand(chance)<1) ? PLACES[rand(PLACES.length)] : ""
end

.preposition(chance = 0) ⇒ Object



251
252
253
# File 'lib/Zeta/plugins/fnord.rb', line 251

def self.preposition(chance=0)
  (chance==0 or rand(chance)<1) ? PREPOSITIONS[rand(PREPOSITIONS.length)] : ""
end

.pronoun(chance = 0) ⇒ Object



259
260
261
# File 'lib/Zeta/plugins/fnord.rb', line 259

def self.pronoun(chance=0)
  (chance==0 or rand(chance)<1) ? PRONOUNS[rand(PRONOUNS.length)] : ""
end