Module: WWMDUtils

Included in:
WWMD::Page
Defined in:
lib/wwmd/wwmd_utils.rb

Class Method Summary collapse

Class Method Details

.header_array_from_file(filename) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/wwmd/wwmd_utils.rb', line 3

def self.header_array_from_file(filename)
  ret = Hash.new
  File.readlines(filename).each do |line|
    a = line.chomp.split(/\t/,2)
    ret[a[0]] = a[1]
  end
  return ret
end

.rannum(len = 8, hex = false) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/wwmd/wwmd_utils.rb', line 20

def self.rannum(len=8,hex=false)
  chars = ("0".."9").to_a
  chars += ("A".."F").to_a if hex
  ret = ""
  1.upto(len) { |i| ret << chars[rand(chars.size-1)] }
  return ret
end

.ranstr(len = 8, digits = false) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/wwmd/wwmd_utils.rb', line 12

def self.ranstr(len=8,digits=false)
  chars = ("a".."z").to_a
  chars += ("0".."9").to_a if digits
  ret = ""
  1.upto(len) { |i| ret << chars[rand(chars.size-1)] }
  return ret
end