Module: DataMagic::StandardTranslation
- Included in:
- DataMagic, Translation
- Defined in:
- lib/data_magic/standard_translation.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
-
#catch_phrase ⇒ Object
(also: #dm_catch_phrase)
return a random catch phrase.
-
#cell_phone ⇒ Object
(also: #dm_cell_phone)
return a random cell number.
-
#characters(character_count = 255) ⇒ Object
(also: #dm_characters)
return random characters - default is 255 characters.
-
#city ⇒ Object
(also: #dm_city)
return a random city.
-
#color_hex ⇒ Object
(also: #dm_color_hex)
return a random color code in hex.
-
#color_name ⇒ Object
(also: #dm_color_name)
return a random color name.
-
#company_name ⇒ Object
(also: #dm_company_name)
return a random company name.
-
#country ⇒ Object
(also: #dm_country)
return a random country.
-
#credit_card_number ⇒ Object
(also: #dm_credit_card_number)
return a credit card number.
-
#credit_card_type ⇒ Object
(also: #dm_credit_card_type)
return a credit card type.
-
#decimal(before_decimal, after_decimal = 2) ⇒ Object
(also: #dm_decimal)
return a random number in decimal.
-
#domain_name ⇒ Object
(also: #dm_domain_name)
return a random domain name.
-
#email_address(name = nil, domain = nil) ⇒ Object
(also: #dm_email_address)
return a random email address.
-
#first_name ⇒ Object
(also: #dm_first_name)
return a random first name.
-
#full_name ⇒ Object
(also: #dm_full_name)
return a random name (first and last).
-
#job_title ⇒ Object
(also: #dm_job_title)
return a random job title.
-
#last_name ⇒ Object
(also: #dm_last_name)
return a random last name.
-
#mask(value) ⇒ Object
(also: #dm_mask)
return a value based on a mast The # character will be replaced with a number The A character will be replaced with an upper case letter The a character will be replaced with a lower case letter.
-
#merge(separator = ' ', *params) ⇒ Object
(also: #dm_merge)
merge variables.
-
#name_prefix ⇒ Object
(also: #dm_name_prefix)
return a random name prefix.
-
#name_suffix ⇒ Object
(also: #dm_name_suffix)
return a random name suffix.
-
#number(digits, leading_zero = false) ⇒ Object
(also: #dm_number)
return a random number in specified digits.
-
#paragraphs(paragraph_count = 3) ⇒ Object
(also: #dm_paragraphs)
return random paragraphs - default is 3 paragraphs.
-
#phone_number ⇒ Object
(also: #dm_phone_number)
return a random phone number.
-
#randomize(value) ⇒ Object
(also: #dm_randomize)
return a random value from an array or range.
-
#secondary_address ⇒ Object
(also: #dm_secondary_address)
return a random secondary address.
-
#sentence(min_word_count = 4) ⇒ Object
(also: #dm_sentence)
return a random sentence - default minimum word count is 4.
-
#sentences(sentence_count = 3) ⇒ Object
(also: #dm_sentences)
return random sentences - default is 3 sentences.
-
#sequential(value) ⇒ Object
return an element from the array.
-
#state ⇒ Object
(also: #dm_state)
return a random state.
-
#state_abbr ⇒ Object
(also: #dm_state_abbr)
return a random state abbreviation.
-
#street_address(include_secondary = false) ⇒ Object
(also: #dm_street_address)
return a random street address.
-
#url ⇒ Object
(also: #dm_url)
return a random url.
-
#user_name ⇒ Object
(also: #dm_user_name)
return a random user name.
-
#words(number = 3) ⇒ Object
(also: #dm_words)
return random words - default is 3 words.
-
#zip_code ⇒ Object
(also: #dm_zip_code)
return a random 5 or 9 digit zip code.
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
5 6 7 |
# File 'lib/data_magic/standard_translation.rb', line 5 def parent @parent end |
Instance Method Details
#catch_phrase ⇒ Object Also known as: dm_catch_phrase
return a random catch phrase
126 127 128 |
# File 'lib/data_magic/standard_translation.rb', line 126 def catch_phrase Faker::Company.catch_phrase end |
#cell_phone ⇒ Object Also known as: dm_cell_phone
return a random cell number
231 232 233 234 |
# File 'lib/data_magic/standard_translation.rb', line 231 def cell_phone value = Faker::PhoneNumber.cell_phone remove_extension(value) end |
#characters(character_count = 255) ⇒ Object Also known as: dm_characters
return random characters - default is 255 characters
182 183 184 |
# File 'lib/data_magic/standard_translation.rb', line 182 def characters(character_count = 255) Faker::Lorem.characters(number: character_count) end |
#city ⇒ Object Also known as: dm_city
return a random city
78 79 80 |
# File 'lib/data_magic/standard_translation.rb', line 78 def city Faker::Address.city end |
#color_hex ⇒ Object Also known as: dm_color_hex
return a random color code in hex
291 292 293 |
# File 'lib/data_magic/standard_translation.rb', line 291 def color_hex Faker::Color.hex_color end |
#color_name ⇒ Object Also known as: dm_color_name
return a random color name
299 300 301 |
# File 'lib/data_magic/standard_translation.rb', line 299 def color_name Faker::Color.color_name end |
#company_name ⇒ Object Also known as: dm_company_name
return a random company name
118 119 120 |
# File 'lib/data_magic/standard_translation.rb', line 118 def company_name Faker::Company.name end |
#country ⇒ Object Also known as: dm_country
return a random country
110 111 112 |
# File 'lib/data_magic/standard_translation.rb', line 110 def country Faker::Address.country end |
#credit_card_number ⇒ Object Also known as: dm_credit_card_number
return a credit card number
134 135 136 |
# File 'lib/data_magic/standard_translation.rb', line 134 def credit_card_number Faker::Business.credit_card_number end |
#credit_card_type ⇒ Object Also known as: dm_credit_card_type
return a credit card type
142 143 144 |
# File 'lib/data_magic/standard_translation.rb', line 142 def credit_card_type Faker::Business.credit_card_type end |
#decimal(before_decimal, after_decimal = 2) ⇒ Object Also known as: dm_decimal
return a random number in decimal
315 316 317 |
# File 'lib/data_magic/standard_translation.rb', line 315 def decimal(before_decimal, after_decimal = 2) Faker::Number.decimal(l_digits: before_decimal, r_digits: after_decimal) end |
#domain_name ⇒ Object Also known as: dm_domain_name
return a random domain name
198 199 200 |
# File 'lib/data_magic/standard_translation.rb', line 198 def domain_name Faker::Internet.domain_name end |
#email_address(name = nil, domain = nil) ⇒ Object Also known as: dm_email_address
return a random email address
190 191 192 |
# File 'lib/data_magic/standard_translation.rb', line 190 def email_address(name = nil, domain = nil) Faker::Internet.email(name: name, domain: domain) end |
#first_name ⇒ Object Also known as: dm_first_name
return a random first name
18 19 20 |
# File 'lib/data_magic/standard_translation.rb', line 18 def first_name Faker::Name.first_name end |
#full_name ⇒ Object Also known as: dm_full_name
return a random name (first and last)
10 11 12 |
# File 'lib/data_magic/standard_translation.rb', line 10 def full_name Faker::Name.name end |
#job_title ⇒ Object Also known as: dm_job_title
return a random job title
54 55 56 |
# File 'lib/data_magic/standard_translation.rb', line 54 def job_title Faker::Job.title end |
#last_name ⇒ Object Also known as: dm_last_name
return a random last name
26 27 28 |
# File 'lib/data_magic/standard_translation.rb', line 26 def last_name Faker::Name.last_name end |
#mask(value) ⇒ Object Also known as: dm_mask
return a value based on a mast The # character will be replaced with a number The A character will be replaced with an upper case letter The a character will be replaced with a lower case letter
268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/data_magic/standard_translation.rb', line 268 def mask(value) result = '' value.each_char do |ch| result += case ch when '#' then randomize(0..9).to_s when 'A' then ('A'..'Z').to_a[rand(26)] when 'a' then ('a'..'z').to_a[rand(26)] else ch end end result end |
#merge(separator = ' ', *params) ⇒ Object Also known as: dm_merge
merge variables
323 324 325 |
# File 'lib/data_magic/standard_translation.rb', line 323 def merge(separator = ' ', *params) params.join(separator) end |
#name_prefix ⇒ Object Also known as: dm_name_prefix
return a random name prefix
34 35 36 |
# File 'lib/data_magic/standard_translation.rb', line 34 def name_prefix Faker::Name.prefix end |
#name_suffix ⇒ Object Also known as: dm_name_suffix
return a random name suffix
42 43 44 |
# File 'lib/data_magic/standard_translation.rb', line 42 def name_suffix Faker::Name.suffix end |
#number(digits, leading_zero = false) ⇒ Object Also known as: dm_number
return a random number in specified digits
307 308 309 |
# File 'lib/data_magic/standard_translation.rb', line 307 def number(digits, leading_zero = false) leading_zero ? Faker::Number.leading_zero_number(digits: digits) : Faker::Number.number(digits: digits) end |
#paragraphs(paragraph_count = 3) ⇒ Object Also known as: dm_paragraphs
return random paragraphs - default is 3 paragraphs
174 175 176 |
# File 'lib/data_magic/standard_translation.rb', line 174 def paragraphs(paragraph_count = 3) Faker::Lorem.paragraphs(number: paragraph_count).join('\n\n') end |
#phone_number ⇒ Object Also known as: dm_phone_number
return a random phone number
222 223 224 225 |
# File 'lib/data_magic/standard_translation.rb', line 222 def phone_number value = Faker::PhoneNumber.phone_number remove_extension(value) end |
#randomize(value) ⇒ Object Also known as: dm_randomize
return a random value from an array or range
240 241 242 243 244 245 246 |
# File 'lib/data_magic/standard_translation.rb', line 240 def randomize(value) case value when Array then value[rand(value.size)] when Range then rand((value.last + 1) - value.first) + value.first else value end end |
#secondary_address ⇒ Object Also known as: dm_secondary_address
return a random secondary address
70 71 72 |
# File 'lib/data_magic/standard_translation.rb', line 70 def secondary_address Faker::Address.secondary_address end |
#sentence(min_word_count = 4) ⇒ Object Also known as: dm_sentence
return a random sentence - default minimum word count is 4
158 159 160 |
# File 'lib/data_magic/standard_translation.rb', line 158 def sentence(min_word_count = 4) Faker::Lorem.sentence(word_count: min_word_count) end |
#sentences(sentence_count = 3) ⇒ Object Also known as: dm_sentences
return random sentences - default is 3 sentences
166 167 168 |
# File 'lib/data_magic/standard_translation.rb', line 166 def sentences(sentence_count = 3) Faker::Lorem.sentences(number: sentence_count).join(' ') end |
#sequential(value) ⇒ Object
return an element from the array. The first request will return the first element, the second request will return the second, and so forth.
254 255 256 257 258 259 260 |
# File 'lib/data_magic/standard_translation.rb', line 254 def sequential(value) index = index_variable_for(value) index = (index ? index + 1 : 0) index = 0 if index == value.length set_index_variable(value, index) value[index] end |
#state ⇒ Object Also known as: dm_state
return a random state
86 87 88 |
# File 'lib/data_magic/standard_translation.rb', line 86 def state Faker::Address.state end |
#state_abbr ⇒ Object Also known as: dm_state_abbr
return a random state abbreviation
94 95 96 |
# File 'lib/data_magic/standard_translation.rb', line 94 def state_abbr Faker::Address.state_abbr end |
#street_address(include_secondary = false) ⇒ Object Also known as: dm_street_address
return a random street address
62 63 64 |
# File 'lib/data_magic/standard_translation.rb', line 62 def street_address(include_secondary = false) Faker::Address.street_address(include_secondary: include_secondary) end |
#url ⇒ Object Also known as: dm_url
return a random url
206 207 208 |
# File 'lib/data_magic/standard_translation.rb', line 206 def url Faker::Internet.url end |
#user_name ⇒ Object Also known as: dm_user_name
return a random user name
214 215 216 |
# File 'lib/data_magic/standard_translation.rb', line 214 def user_name Faker::Internet.user_name end |
#words(number = 3) ⇒ Object Also known as: dm_words
return random words - default is 3 words
150 151 152 |
# File 'lib/data_magic/standard_translation.rb', line 150 def words(number = 3) Faker::Lorem.words(number: number).join(' ') end |
#zip_code ⇒ Object Also known as: dm_zip_code
return a random 5 or 9 digit zip code
102 103 104 |
# File 'lib/data_magic/standard_translation.rb', line 102 def zip_code Faker::Address.zip end |