LibInsult - Python
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
insult.Insulter Class Reference

Object that can generate insults. More...

Inheritance diagram for insult.Insulter:
[legend]
Collaboration diagram for insult.Insulter:
[legend]

Public Member Functions

def __init__ (self)
 
def word_list (self, wl_id, add=False)
 Returns a matching word list. More...
 
def load_directory (self, path)
 Loads all word lists in path. More...
 
def add_words (self, wl_id, words)
 Adds words to a word list. More...
 
def get (self, wl_id, max_count=1, min_count=None)
 Retrieves a random subset of words form a word list. More...
 
def format (self, string)
 Formats an insult string. More...
 
def set_max (self, max_count, word_list=None)
 Set the maximum number of repetitions for get() More...
 
def set_rules (self, name, rules)
 Sets some language rules for the given identifier. More...
 

Public Attributes

 word_lists
 Word lists to look up. More...
 
 max_count
 Maximum number of repetitions allowed. More...
 
 list_max_count
 Maximum number of repetitions allowed for a specific word list. More...
 
 rules
 Language rules. More...
 

Static Public Attributes

 regex_word_file = re.compile(r'^[a-z_]+$')
 Regex used to recognize valid word file names. More...
 
string rules_file = "rules.json"
 File name for language rules. More...
 

Detailed Description

Object that can generate insults.

Note
all methods that take a WordListId argument, will expand it using word_list_id()

Definition at line 102 of file insult.py.

Constructor & Destructor Documentation

def insult.Insulter.__init__ (   self)

Definition at line 114 of file insult.py.

Member Function Documentation

def insult.Insulter.add_words (   self,
  wl_id,
  words 
)

Adds words to a word list.

Parameters
wl_idWordListId to match the list
wordsIterable with words to be added

Definition at line 165 of file insult.py.

Referenced by insult.Insulter.load_directory().

def insult.Insulter.format (   self,
  string 
)

Formats an insult string.

Definition at line 191 of file insult.py.

def insult.Insulter.get (   self,
  wl_id,
  max_count = 1,
  min_count = None 
)

Retrieves a random subset of words form a word list.

Parameters
wl_idWordListId to match the list
max_countMaximum number of words to return, note that it will be checked against the value set with set_max()
min_countMinimum number of words to return, if omitted, returns exactly max_count words
See also
set_max(), WordList.get()

Definition at line 173 of file insult.py.

Referenced by insult.Insulter.format().

def insult.Insulter.load_directory (   self,
  path 
)

Loads all word lists in path.

Parameters
pathThe path to the directory to load
Note
Only files matching regex_word_file will be considered

Definition at line 144 of file insult.py.

def insult.Insulter.set_max (   self,
  max_count,
  word_list = None 
)

Set the maximum number of repetitions for get()

Parameters
max_countMaximum to be set, if None will disable the maximum limit
word_listWord list name (note: not a WordListId)

Definition at line 237 of file insult.py.

def insult.Insulter.set_rules (   self,
  name,
  rules 
)

Sets some language rules for the given identifier.

Definition at line 252 of file insult.py.

Referenced by insult.Insulter.load_directory().

def insult.Insulter.word_list (   self,
  wl_id,
  add = False 
)

Returns a matching word list.

Parameters
wl_idWordListId to match the list
addif True, missing lists will be added to the insulter
Exceptions
Exceptionif the list cannot be retrieved

Definition at line 126 of file insult.py.

Referenced by insult.Insulter.add_words(), and insult.Insulter.get().

Member Data Documentation

insult.Insulter.list_max_count

Maximum number of repetitions allowed for a specific word list.

Definition at line 122 of file insult.py.

Referenced by insult.Insulter.get(), and insult.Insulter.set_max().

insult.Insulter.max_count

Maximum number of repetitions allowed.

Definition at line 120 of file insult.py.

Referenced by insult.Insulter.get(), and insult.Insulter.set_max().

insult.Insulter.regex_word_file = re.compile(r'^[a-z_]+$')
static

Regex used to recognize valid word file names.

Definition at line 110 of file insult.py.

insult.Insulter.rules

Language rules.

Definition at line 124 of file insult.py.

Referenced by insult.Insulter.format(), and insult.Insulter.set_rules().

string insult.Insulter.rules_file = "rules.json"
static

File name for language rules.

Definition at line 112 of file insult.py.

insult.Insulter.word_lists

Word lists to look up.

Definition at line 118 of file insult.py.

Referenced by insult.Insulter.word_list().


The documentation for this class was generated from the following file: