class Core
Public Class Methods
_random_address()
click to toggle source
# File lib/aml/core/method.rb, line 126 def self._random_address address = [] count = rand(2..4) until address.count == count do address << self._random_word(true) end city = [] count = rand(1..2) until city.count == count do city << self._random_word(true) end rand(100..5000).to_s + ' ' + address.join(' ') + ', ' + city.join(' ') + ', ' + self._random_word(true)[0].upcase + self._random_word(true)[0].upcase + ' ' + rand(10000...99999).to_s end
_random_email()
click to toggle source
# File lib/aml/core/method.rb, line 140 def self._random_email self._random_word + '@' + self._random_word + '.' + self._random_word[0..3] end
_random_name()
click to toggle source
# File lib/aml/core/method.rb, line 118 def self._random_name self._random_word(true) + ' ' + self._random_word(true)[0] + '. ' + self._random_word(true) end
_random_paragraph(number, words)
click to toggle source
# File lib/aml/core/method.rb, line 96 def self._random_paragraph(number, words) paragraphs = rand(number) paragraphs = number if paragraphs == 0 paragraphs = paragraphs <= (number/2) ? number/2+rand(0..1) : paragraphs string = [] until string.count == paragraphs do string << self._random_sentence(words) end string.join(' ') end
_random_phone()
click to toggle source
# File lib/aml/core/method.rb, line 122 def self._random_phone '('+ rand(100...999).to_s + ') ' + rand(100...999).to_s + '-' + rand(1000...9999).to_s end
_random_sentence(number)
click to toggle source
# File lib/aml/core/method.rb, line 85 def self._random_sentence(number) words = rand(number) words = number if words == 0 words = words <= (number/2) ? number/2+rand(0..1) : words string = [] until string.count == words do string << self._random_word(string.count==0) end string.join(' ') + '.' end
_random_title(number)
click to toggle source
# File lib/aml/core/method.rb, line 107 def self._random_title(number) words = rand(number) words = number if words == 0 words = words <= (number/2) ? number/2+rand(0..1) : words string = [] until string.count == words do string << self._random_word(true) end string.join(' ') end
_random_word(capitalize=false)
click to toggle source
# File lib/aml/core/method.rb, line 79 def self._random_word(capitalize=false) string = @words[rand(@words.count)] string = string.capitalize if capitalize string end
alphanumeric(index=0, a={}, d={:value=>nil,:replace=>' '})
click to toggle source
# File lib/aml/core/method.rb, line 20 def self.alphanumeric(index=0, a={}, d={:value=>nil,:replace=>' '}) a = d.merge(a) self.downcase(index,{:value=>a[:value]}).gsub(/[^\w]/,a[:replace]).gsub(/#{a[:replace]}{2,}/,a[:replace]).gsub(/^#{a[:replace]}/,'').gsub(/#{a[:replace]}$/,'') end
copyright(index=0, a={}, d={:value=>false})
click to toggle source
# File lib/aml/core/method.rb, line 41 def self.copyright(index=0, a={}, d={:value=>false}) a = d.merge(a) string = '© ' + self.year string += ' ' + a[:value].to_s if a[:value].to_s.length > 0 string end
date(index=0, a={}, d={:format=>'%Y-%m-%d %H:%M:%S'})
click to toggle source
# File lib/aml/core/method.rb, line 35 def self.date(index=0, a={}, d={:format=>'%Y-%m-%d %H:%M:%S'}) a = d.merge(a) time = Time.new time.strftime(a[:format]) end
downcase(index=0, a={}, d={:value=>nil})
click to toggle source
# File lib/aml/core/method.rb, line 10 def self.downcase(index=0, a={}, d={:value=>nil}) a = d.merge(a) a[:value].to_s.downcase end
filename(index=0, a={}, d={:value=>nil,:replace=>'-'})
click to toggle source
# File lib/aml/core/method.rb, line 25 def self.filename(index=0, a={}, d={:value=>nil,:replace=>'-'}) a = d.merge(a) self.alphanumeric(index,{:value=>a[:value], :replace=>a[:replace]}) end
lorem(index=0, a={}, d={:paragraphs=>6, :words=>8, :value=>nil,:capitalize=>true})
click to toggle source
# File lib/aml/core/method.rb, line 52 def self.lorem(index=0, a={}, d={:paragraphs=>6, :words=>8, :value=>nil,:capitalize=>true}) #Generate random copy based on en-us formats. a = d.merge(a) a[:paragraphs] = a[:paragraphs].to_i a[:words] = a[:words].to_i a[:value] = a[:value].to_s.strip == "" ? 'paragraph' : a[:value].downcase string = "" if a[:value] == 'word' string = self._random_word(a[:capitalize]) elsif a[:value] == 'sentence' string = self._random_sentence(a[:words]) elsif a[:value] == 'paragraph' string = self._random_paragraph(a[:paragraphs], a[:words]) elsif a[:value] == 'title' string = self._random_title(a[:words]) elsif a[:value] == 'name' string = self._random_name elsif a[:value] == 'address' string = self._random_address elsif a[:value] == 'phone' string = self._random_phone elsif a[:value] == 'email' string = self._random_email end return string end
randrange(index=0, a={}, d={:min=>'1', :max=>'10'})
click to toggle source
# File lib/aml/core/method.rb, line 30 def self.randrange(index=0, a={}, d={:min=>'1', :max=>'10'}) a = d.merge(a) rand(a[:min].to_i..a[:max].to_i) end
swapcase(index=0, a={}, d={:value=>nil})
click to toggle source
# File lib/aml/core/method.rb, line 15 def self.swapcase(index=0, a={}, d={:value=>nil}) a = d.merge(a) a[:value].to_s.swapcase end
upcase(index=0, a={}, d={:value=>nil})
click to toggle source
# File lib/aml/core/method.rb, line 5 def self.upcase(index=0, a={}, d={:value=>nil}) a = d.merge(a) a[:value].to_s.upcase end
year(index=0, a={})
click to toggle source
# File lib/aml/core/method.rb, line 48 def self.year(index=0, a={}) self.date(index,{:format=>'%Y'}) end