Class: Core
- Inherits:
-
Object
- Object
- Core
- Defined in:
- lib/aml/core/method.rb
Class Method Summary collapse
- ._random_address ⇒ Object
- ._random_email ⇒ Object
- ._random_name ⇒ Object
- ._random_paragraph(number, words) ⇒ Object
- ._random_phone ⇒ Object
- ._random_sentence(number) ⇒ Object
- ._random_title(number) ⇒ Object
- ._random_word(capitalize = false) ⇒ Object
- .alphanumeric(index = 0, a = {}, d = {:string=>nil}) ⇒ Object
- .copyright(index = 0, a = {}, d = {:name=>false}) ⇒ Object
- .date(index = 0, a = {}, d = {:format=>'%Y-%m-%d %H:%M:%S'}) ⇒ Object
- .lorem(index = 0, a = {}, d = {:paragraphs=>6, :words=>8, :type=>'paragraph',:capitalize=>true}) ⇒ Object
- .randrange(index = 0, a = {}, d = {:min=>'1', :max=>'10'}) ⇒ Object
- .year(index = 0, a = {}) ⇒ Object
Class Method Details
._random_address ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/aml/core/method.rb', line 103 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 ⇒ Object
117 118 119 |
# File 'lib/aml/core/method.rb', line 117 def self._random_email self._random_word + '@' + self._random_word + '.' + self._random_word[0..3] end |
._random_name ⇒ Object
95 96 97 |
# File 'lib/aml/core/method.rb', line 95 def self._random_name self._random_word(true) + ' ' + self._random_word(true)[0] + '. ' + self._random_word(true) end |
._random_paragraph(number, words) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/aml/core/method.rb', line 73 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 ⇒ Object
99 100 101 |
# File 'lib/aml/core/method.rb', line 99 def self._random_phone '('+ rand(100...999).to_s + ') ' + rand(100...999).to_s + '-' + rand(1000...9999).to_s end |
._random_sentence(number) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/aml/core/method.rb', line 62 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) ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/aml/core/method.rb', line 84 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) ⇒ Object
56 57 58 59 60 |
# File 'lib/aml/core/method.rb', line 56 def self._random_word(capitalize=false) string = @words[rand(@words.count)] string = string.capitalize if capitalize string end |
.alphanumeric(index = 0, a = {}, d = {:string=>nil}) ⇒ Object
21 22 23 24 |
# File 'lib/aml/core/method.rb', line 21 def self.alphanumeric(index=0, a={}, d={:string=>nil}) a = d.merge(a) return a[:string].downcase.gsub(/[^a-zA-Z0-9]/,'-') end |
.copyright(index = 0, a = {}, d = {:name=>false}) ⇒ Object
16 17 18 19 |
# File 'lib/aml/core/method.rb', line 16 def self.copyright(index=0, a={}, d={:name=>false}) a = d.merge(a) return '© ' + self.year + ' ' + a[:name] end |
.date(index = 0, a = {}, d = {:format=>'%Y-%m-%d %H:%M:%S'}) ⇒ Object
10 11 12 13 14 |
# File 'lib/aml/core/method.rb', line 10 def self.date(index=0, a={}, d={:format=>'%Y-%m-%d %H:%M:%S'}) a = d.merge(a) time = Time.new return time.strftime(a[:format]) end |
.lorem(index = 0, a = {}, d = {:paragraphs=>6, :words=>8, :type=>'paragraph',:capitalize=>true}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/aml/core/method.rb', line 30 def self.lorem(index=0, a={}, d={:paragraphs=>6, :words=>8, :type=>'paragraph',: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 string = "" if a[:type] == 'word' string = self._random_word(a[:capitalize]) elsif a[:type] == 'sentence' string = self._random_sentence(a[:words]) elsif a[:type] == 'paragraph' string = self._random_paragraph(a[:paragraphs], a[:words]) elsif a[:type] == 'title' string = self._random_title(a[:words]) elsif a[:type] == 'name' string = self._random_name elsif a[:type] == 'address' string = self._random_address elsif a[:type] == 'phone' string = self._random_phone elsif a[:type] == 'email' string = self._random_email end return string end |
.randrange(index = 0, a = {}, d = {:min=>'1', :max=>'10'}) ⇒ Object
5 6 7 8 |
# File 'lib/aml/core/method.rb', line 5 def self.randrange(index=0, a={}, d={:min=>'1', :max=>'10'}) a = d.merge(a) return rand(a[:min].to_i..a[:max].to_i) end |
.year(index = 0, a = {}) ⇒ Object
26 27 28 |
# File 'lib/aml/core/method.rb', line 26 def self.year(index=0, a={}) return self.date(index,{:format=>'%Y'}) end |