module DataMagic::StandardTranslation
Attributes
Public Instance Methods
return a random catch phrase
# File lib/data_magic/standard_translation.rb, line 126 def catch_phrase Faker::Company.catch_phrase end
return a random cell number
# File lib/data_magic/standard_translation.rb, line 231 def cell_phone value = Faker::PhoneNumber.cell_phone remove_extension(value) end
return random characters - default is 255 characters
# File lib/data_magic/standard_translation.rb, line 182 def characters(character_count = 255) Faker::Lorem.characters(number: character_count) end
return a random city
# File lib/data_magic/standard_translation.rb, line 78 def city Faker::Address.city end
return a random color code in hex
# File lib/data_magic/standard_translation.rb, line 291 def color_hex Faker::Color.hex_color end
return a random color name
# File lib/data_magic/standard_translation.rb, line 299 def color_name Faker::Color.color_name end
return a random company name
# File lib/data_magic/standard_translation.rb, line 118 def company_name Faker::Company.name end
return a random country
# File lib/data_magic/standard_translation.rb, line 110 def country Faker::Address.country end
return a credit card number
# File lib/data_magic/standard_translation.rb, line 134 def credit_card_number Faker::Business.credit_card_number end
return a credit card type
# File lib/data_magic/standard_translation.rb, line 142 def credit_card_type Faker::Business.credit_card_type end
return a random number in decimal
# 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
return a random domain name
# File lib/data_magic/standard_translation.rb, line 198 def domain_name Faker::Internet.domain_name end
return a random email address
# File lib/data_magic/standard_translation.rb, line 190 def email_address(name = nil, domain = nil) Faker::Internet.email(name: name, domain: domain) end
return a random first name
# File lib/data_magic/standard_translation.rb, line 18 def first_name Faker::Name.first_name end
return a random name (first and last)
# File lib/data_magic/standard_translation.rb, line 10 def full_name Faker::Name.name end
return a random job title
# File lib/data_magic/standard_translation.rb, line 54 def job_title Faker::Job.title end
return a random last name
# File lib/data_magic/standard_translation.rb, line 26 def last_name Faker::Name.last_name end
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
# 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 variables
# File lib/data_magic/standard_translation.rb, line 323 def merge(separator = ' ', *params) params.join(separator) end
return a random name prefix
# File lib/data_magic/standard_translation.rb, line 34 def name_prefix Faker::Name.prefix end
return a random name suffix
# File lib/data_magic/standard_translation.rb, line 42 def name_suffix Faker::Name.suffix end
return a random number in specified digits
# 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
return random paragraphs - default is 3 paragraphs
# File lib/data_magic/standard_translation.rb, line 174 def paragraphs(paragraph_count = 3) Faker::Lorem.paragraphs(number: paragraph_count).join('\n\n') end
return a random phone number
# File lib/data_magic/standard_translation.rb, line 222 def phone_number value = Faker::PhoneNumber.phone_number remove_extension(value) end
return a random value from an array or range
# 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
return a random secondary address
# File lib/data_magic/standard_translation.rb, line 70 def secondary_address Faker::Address.secondary_address end
return a random sentence - default minimum word count is 4
# File lib/data_magic/standard_translation.rb, line 158 def sentence(min_word_count = 4) Faker::Lorem.sentence(word_count: min_word_count) end
return random sentences - default is 3 sentences
# File lib/data_magic/standard_translation.rb, line 166 def sentences(sentence_count = 3) Faker::Lorem.sentences(number: sentence_count).join(' ') end
return an element from the array. The first request will return the first element, the second request will return the second, and so forth.
# 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
return a random state
# File lib/data_magic/standard_translation.rb, line 86 def state Faker::Address.state end
return a random state abbreviation
# File lib/data_magic/standard_translation.rb, line 94 def state_abbr Faker::Address.state_abbr end
return a random street address
# File lib/data_magic/standard_translation.rb, line 62 def street_address(include_secondary = false) Faker::Address.street_address(include_secondary: include_secondary) end
return a random url
# File lib/data_magic/standard_translation.rb, line 206 def url Faker::Internet.url end
return a random user name
# File lib/data_magic/standard_translation.rb, line 214 def user_name Faker::Internet.user_name end
return random words - default is 3 words
# File lib/data_magic/standard_translation.rb, line 150 def words(number = 3) Faker::Lorem.words(number: number).join(' ') end
return a random 5 or 9 digit zip code
# File lib/data_magic/standard_translation.rb, line 102 def zip_code Faker::Address.zip end
Private Instance Methods
# File lib/data_magic/standard_translation.rb, line 356 def data_hash $data_magic_data_hash ||= {} end
# File lib/data_magic/standard_translation.rb, line 350 def index_hash dh = data_hash[parent] data_hash[parent] = {} unless dh data_hash[parent] end
# File lib/data_magic/standard_translation.rb, line 346 def index_name(ary) "#{ary[0]}#{ary[1]}_index".gsub(' ', '_').downcase end
# File lib/data_magic/standard_translation.rb, line 340 def index_variable_for(ary) value = index_hash[index_name(ary)] index_hash[index_name(ary)] = -1 unless value index_hash[index_name(ary)] end
# File lib/data_magic/standard_translation.rb, line 360 def process(value) eval value end
# File lib/data_magic/standard_translation.rb, line 364 def remove_extension(phone) index = phone.index('x') phone = phone[0, (index - 1)] if index phone end
#
NEW TRANSLATOR ENDS HERE #
#
# File lib/data_magic/standard_translation.rb, line 336 def set_index_variable(ary, value) index_hash[index_name(ary)] = value end