class DndNameGenerator::BashHistory

Public Instance Methods

generate() click to toggle source
# File lib/dnd_name_generator.rb, line 19
def generate
  r = rand(tokens.length)
  first, last = tokens[r..(r+1)]
  if first == last
    last = tokens[rand(tokens.length)]
  end
  "#{first.capitalize} #{last.capitalize}"
end
tokens() click to toggle source
# File lib/dnd_name_generator.rb, line 6
def tokens
  unless @tokens 
    @tokens = []
    File.open(File.join(ENV['HOME'], ".bash_history")).each_line do |line|
      line = line.gsub(/[^A-Za-z\s\/]/,'')
      t = line.split(/\s+|\//)
      @tokens.concat(t)
    end
    @tokens = @tokens.reject{|t| t.length < 3}
  end
  @tokens
end