class Plugins::Fnord::Fnord
Public Class Methods
action(chance=0)
click to toggle source
# 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)
click to toggle source
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.
# File lib/Zeta/plugins/fnord.rb, line 235 def self.adjective(chance=0) (chance==0 or rand(chance)<1) ? ADJECTIVES[rand(ADJECTIVES.length)] : "" end
headline()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/Zeta/plugins/fnord.rb, line 259 def self.pronoun(chance=0) (chance==0 or rand(chance)<1) ? PRONOUNS[rand(PRONOUNS.length)] : "" end