module Connie

Constants

VERSION

Public Class Methods

[](dictionary_name) click to toggle source
# File lib/connie/connie.rb, line 12
def self.[] dictionary_name
  @dictionaries[dictionary_name.to_sym] or Dictionary.new(dictionary_name.to_s)
end
dictionaries() click to toggle source
# File lib/connie/connie.rb, line 10
def self.dictionaries;@dictionaries;end
dictionaries_paths() click to toggle source
# File lib/connie.rb, line 26
def self.dictionaries_paths
  @dictionaries_paths
end
digit() click to toggle source
# File lib/connie/connie.rb, line 43
def self.digit
  rand(9)
end
formats(format, min = 1, max = 0) click to toggle source
# File lib/connie/connie.rb, line 47
def self.formats format, min = 1, max = 0
  array = max > 0 ? Array.new(rand(max-min)+min) : Array.new(min)
    
  generator = case format
  when :W then lambda {Connie.letter(:uppercase)}
  when :w then lambda {Connie.letter}
  when :d then lambda {Connie.digit.to_s}
  end
  
  array.map{generator.call}.join
end
letter(variant=nil) click to toggle source

Returns a random letter

# File lib/connie/connie.rb, line 37
def self.letter(variant=nil)
  index = rand(26)*2
  index +=1 if variant == :uppercase
  @alphabet[index]
end
pick_a_line_from(file_path, line_no = false) click to toggle source

Picks a random line from a text file or a precise line if a number is provided

# File lib/connie/connie.rb, line 21
def self.pick_a_line_from(file_path, line_no = false)
  File.open file_path, 'r' do |file|
    unless line_no
      file.inject { |choice, line| rand < 1/file.lineno.to_f ? line.strip : choice }
    else
      line = line_no % (file.lineno - 1) # cycles around the file
      file.readlines[line-1].strip
    end
  end
end
register_dictionary(dictionary) click to toggle source
# File lib/connie/connie.rb, line 16
def self.register_dictionary(dictionary)
  @dictionaries[dictionary.name.to_sym] = dictionary
end
reload_dictionaries() click to toggle source
# File lib/connie/connie.rb, line 32
def self.reload_dictionaries
  @dictionaries = {}
end