Class: Mack::Data::Factory::FieldContentGenerator
- Defined in:
- lib/mack-data_factory/content_generator.rb
Overview
:nodoc:
Class Method Summary collapse
- .alpha_generator ⇒ Object
- .alpha_numeric_generator ⇒ Object
-
.city_generator ⇒ Object
Address Generators.
- .company_generator ⇒ Object
- .domain_generator ⇒ Object
- .email_generator ⇒ Object
- .firstname_generator ⇒ Object
- .lastname_generator ⇒ Object
-
.money_generator ⇒ Object
def date_time_generator @date_time_gen = Proc.new do |def_value, rules, index| Time.now.to_s end return @date_time_gen end.
- .name_generator ⇒ Object
- .numeric_generator ⇒ Object
- .phone_generator ⇒ Object
- .state_generator ⇒ Object
- .streetname_generator ⇒ Object
- .time_generator ⇒ Object
- .username_generator ⇒ Object
- .zipcode_generator ⇒ Object
Class Method Details
.alpha_generator ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mack-data_factory/content_generator.rb', line 9 def alpha_generator @alpha_gen = Proc.new do |def_value, rules, index| words = %w(alias consequatur aut perferendis sit voluptatem accusantium doloremque aperiam eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem ullam corporis nemo enim ipsam voluptatem quia voluptas sit suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae et iusto odio dignissimos ducimus qui blanditiis praesentium laudantium totam rem voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident sed ut perspiciatis unde omnis iste natus error similique sunt in culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo porro quisquam est qui minus id quod maxime placeat facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur at vero eos et accusamus officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores doloribus asperiores repellat) length = 128 min_length = -1 max_length = -1 if rules[:min_length] min_length = rules[:min_length].to_i end if rules[:max_length] max_length = rules[:max_length].to_i end if rules[:length] length = rules[:length].to_i length = max_length if (max_length != -1) and (max_length <= length) end ret_val = "" words_size = words.size until ret_val.size > length do i = (rand * 100).to_i i = words_size if (i-1) > words_size ret_val += words[i] ret_val += " " if rules[:add_space] end ret_val.strip! ret_val = ret_val[0, length] if ret_val.size > length ret_val end return @alpha_gen end |
.alpha_numeric_generator ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/mack-data_factory/content_generator.rb', line 49 def alpha_numeric_generator @alpha_numeric_gen = Proc.new do |def_value, rules, index| words = %w(alias consequatur aut perferendis sit voluptatem accusantium doloremque aperiam eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem ullam corporis nemo enim ipsam voluptatem quia voluptas sit suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae et iusto odio dignissimos ducimus qui blanditiis praesentium laudantium totam rem voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident sed ut perspiciatis unde omnis iste natus error similique sunt in culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo porro quisquam est qui minus id quod maxime placeat facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur at vero eos et accusamus officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores doloribus asperiores repellat) length = 128 min_length = -1 max_length = -1 if rules[:min_length] min_length = rules[:min_length].to_i end if rules[:max_length] max_length = rules[:max_length].to_i end if rules[:length] length = rules[:length].to_i length = max_length if (max_length != -1) and (max_length <= length) end ret_val = "" words_size = words.size until ret_val.size > length do i = (rand * 100).to_i i = words_size if (i-1) > words_size ret_val += (words[i] + (rand * 1000).to_i.to_s) ret_val += " " if rules[:add_space] end ret_val.strip! ret_val = ret_val[0, length] if ret_val.size > length ret_val end return @alpha_numeric_gen end |
.city_generator ⇒ Object
Address Generators
192 193 194 195 196 197 |
# File 'lib/mack-data_factory/content_generator.rb', line 192 def city_generator @city_gen = Proc.new do |def_value, rules, index| Faker::Address.city end return @city_gen end |
.company_generator ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/mack-data_factory/content_generator.rb', line 170 def company_generator @company_gen = Proc.new do |def_value, rules, index| str = Faker::Company.name if rules[:include_bs] str += "\n#{Faker::Company.bs}" end str end return @company_gen end |
.domain_generator ⇒ Object
142 143 144 145 146 147 |
# File 'lib/mack-data_factory/content_generator.rb', line 142 def domain_generator @domain_gen = Proc.new do |def_value, rules, index| Faker::Internet.domain_name end return @domain_gen end |
.email_generator ⇒ Object
128 129 130 131 132 133 |
# File 'lib/mack-data_factory/content_generator.rb', line 128 def email_generator @email_gen = Proc.new do |def_value, rules, index| Faker::Internet.free_email end return @email_gen end |
.firstname_generator ⇒ Object
149 150 151 152 153 154 |
# File 'lib/mack-data_factory/content_generator.rb', line 149 def firstname_generator @fn_gen = Proc.new do |def_value, rules, index| Faker::Name.first_name end return @fn_gen end |
.lastname_generator ⇒ Object
156 157 158 159 160 161 |
# File 'lib/mack-data_factory/content_generator.rb', line 156 def lastname_generator @ln_gen = Proc.new do |def_value, rules, index| Faker::Name.last_name end return @ln_gen end |
.money_generator ⇒ Object
def date_time_generator
@date_time_gen = Proc.new do |def_value, rules, index|
Time.now.to_s
end
return @date_time_gen
end
118 119 120 121 122 123 124 125 126 |
# File 'lib/mack-data_factory/content_generator.rb', line 118 def money_generator @money_gen = Proc.new do |def_value, rules, index| min = rules[:min] || 0.00 max = rules[:max] || 500.75 diff = rand * (max - min) BigDecimal((min + diff).to_s) end return @money_gen end |
.name_generator ⇒ Object
183 184 185 186 187 188 |
# File 'lib/mack-data_factory/content_generator.rb', line 183 def name_generator @name_gen = Proc.new do |def_value, rules, index| Faker::Name.name end return @name_gen end |
.numeric_generator ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/mack-data_factory/content_generator.rb', line 89 def numeric_generator @numeric_gen = Proc.new do |def_value, rules, index| n_start = rules[:start_num] || 0 n_end = rules[:end_num] || 1000 val = (n_start..n_end).to_a.randomize[0] val end return @numeric_gen end |
.phone_generator ⇒ Object
163 164 165 166 167 168 |
# File 'lib/mack-data_factory/content_generator.rb', line 163 def phone_generator @phone_gen = Proc.new do |def_value, rules, index| Faker::PhoneNumber.phone_number end return @phone_gen end |
.state_generator ⇒ Object
206 207 208 209 210 211 212 213 214 215 |
# File 'lib/mack-data_factory/content_generator.rb', line 206 def state_generator @state_gen = Proc.new do |def_value, rules, index| supported_countries = [:us, :uk] us_or_uk = :us us_or_uk = :uk if rules[:country] and rules[:country].to_sym == :uk abbr = (us_or_uk == :us and rules[:abbr]) ? "_abbr" : "" Faker::Address.send("#{us_or_uk.to_s}_state#{abbr}") end return @state_gen end |
.streetname_generator ⇒ Object
199 200 201 202 203 204 |
# File 'lib/mack-data_factory/content_generator.rb', line 199 def streetname_generator @sn_gen = Proc.new do |def_value, rules, index| Faker::Address.street_name end return @sn_gen end |
.time_generator ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/mack-data_factory/content_generator.rb', line 100 def time_generator @date_gen = Proc.new do |def_value, rules, index| start_time = rules[:start_time] || 1.day.ago end_time = rules[:end_time] || 1.day.from_now diff = (end_time - start_time).to_i start_time + rand(diff).to_i end return @date_gen end |
.username_generator ⇒ Object
135 136 137 138 139 140 |
# File 'lib/mack-data_factory/content_generator.rb', line 135 def username_generator @username_gen = Proc.new do |def_value, rules, index| Faker::Internet.user_name end return @username_gen end |
.zipcode_generator ⇒ Object
217 218 219 220 221 222 223 224 |
# File 'lib/mack-data_factory/content_generator.rb', line 217 def zipcode_generator @zip_gen = Proc.new do |def_value, rules, index| ret_val = Faker::Address.zip_code ret_val = Faker::Address.uk_postcode if rules[:country] and rules[:country].to_sym == :uk ret_val end return @zip_gen end |