Module: Quickstrings

Defined in:
lib/quickstrings.rb,
lib/quickstrings/version.rb

Constant Summary collapse

URLS =

Feel free to add items to the end of the arrays Specific functions are written to return the first thing in the array, so DO NOT add any new items in the first position of the arrays.

Doing so will break tests and expected behavior.
['http://www.google.com', 'http://www.amazon.com', 'http://www.linkedin.com']
EMAILS =
['[email protected]', '[email protected]']
NAMES =
["Frank", "Mary", "Susan", "Apu"]
FULLNAMES =
["Frank Enstein", "Mary Contrary", "Susan Smith", "Apu Nahasapeemapetilon"]
UTF8SAMPLE =

UTF8 sampling focus on umlauted characters from 00C0 to 00FF see www.utf8-chartable.de/ Chars 00D7 and 00F7 would for some reason stop the next ones from generating, so they’re excluded

("\u00C0".."\u00D6").to_a + ("\u00D8".."\u00F6").to_a + ("\u00F8".."\u00FF").to_a
IMAGES =

default gravatar image

["http://www.gravatar.com/avatar/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",  # default gravatar image
	    "http://www.gravatar.com/avatar/bebfcf57d6d8277d806a9ef3385c078d" # gravatar image from Hartl's book
]
VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.emailObject



32
33
34
# File 'lib/quickstrings.rb', line 32

def email
  EMAILS.first
end

.flnameObject



48
49
50
# File 'lib/quickstrings.rb', line 48

def flname
  FULLNAMES.first
end

.fnameObject



40
41
42
# File 'lib/quickstrings.rb', line 40

def fname
  NAMES.first
end

.image(size = nil) ⇒ Object



60
61
62
# File 'lib/quickstrings.rb', line 60

def image(size = nil)
	IMAGES.first + (size.nil? ? "":"?s=#{size}")
end

.remailObject



36
37
38
# File 'lib/quickstrings.rb', line 36

def remail
  EMAILS.sample
end

.rflnameObject



52
53
54
# File 'lib/quickstrings.rb', line 52

def rflname
  FULLNAMES.sample
end

.rfnameObject



44
45
46
# File 'lib/quickstrings.rb', line 44

def rfname
  NAMES.sample
end

.rimage(size = nil) ⇒ Object



64
65
66
# File 'lib/quickstrings.rb', line 64

def rimage(size = nil)
	IMAGES.sample + (size.nil? ? "":"?s=#{size}")
end

.rstring(length = 1, delim = nil) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/quickstrings.rb', line 68

def rstring(length = 1, delim = nil)
  new_string = whitelist_string ('a'..'z'), length
  if !delim.nil?
    new_string[0] = delim
    new_string[-1] = delim
  end
  new_string
end

.rurlObject



28
29
30
# File 'lib/quickstrings.rb', line 28

def rurl
  URLS.sample
end

.rutf8string(length = 1) ⇒ Object



56
57
58
# File 'lib/quickstrings.rb', line 56

def rutf8string(length = 1)
  whitelist_string UTF8SAMPLE, length
end

.urlObject



24
25
26
# File 'lib/quickstrings.rb', line 24

def url
  URLS.first
end

.whitelist_string(whitelist, length) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/quickstrings.rb', line 79

def whitelist_string(whitelist, length)

  case(whitelist)
  when Range
	whitelist = whitelist.to_a
  when String
	whitelist = whitelist.split("")	
  when Fixnum
	whitelist = whitelist.to_s.split("")
  end

  output = ""

  length.times do 
    output += whitelist.sample
  end
  
  output

end