Class: DataMagic::Translation
- Inherits:
-
Object
- Object
- DataMagic::Translation
- Includes:
- DateTranslation
- Defined in:
- lib/data_magic/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.
-
#company_name ⇒ Object
(also: #dm_company_name)
return a random company name.
-
#country ⇒ Object
(also: #dm_country)
return a random country.
-
#domain_name ⇒ Object
(also: #dm_domain_name)
return a random domain name.
-
#email_address(name = 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).
-
#initialize(parent) ⇒ Translation
constructor
A new instance of Translation.
-
#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.
-
#name_prefix ⇒ Object
(also: #dm_name_prefix)
return a random name prefix.
-
#name_suffix ⇒ Object
(also: #dm_name_suffix)
return a random name suffix.
-
#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.
-
#title ⇒ Object
(also: #dm_title)
return a random title.
-
#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.
Methods included from DateTranslation
#day_of_week, #day_of_week_abbr, #month, #month_abbr, #today, #tomorrow, #yesterday
Constructor Details
#initialize(parent) ⇒ Translation
Returns a new instance of Translation.
9 10 11 |
# File 'lib/data_magic/translation.rb', line 9 def initialize(parent) @parent = parent end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
7 8 9 |
# File 'lib/data_magic/translation.rb', line 7 def parent @parent end |
Instance Method Details
#catch_phrase ⇒ Object Also known as: dm_catch_phrase
return a random catch phrase
129 130 131 |
# File 'lib/data_magic/translation.rb', line 129 def catch_phrase Faker::Company.catch_phrase end |
#cell_phone ⇒ Object Also known as: dm_cell_phone
return a random cell number
218 219 220 221 |
# File 'lib/data_magic/translation.rb', line 218 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
169 170 171 |
# File 'lib/data_magic/translation.rb', line 169 def characters(character_count = 255) Faker::Lorem.characters(character_count) end |
#city ⇒ Object Also known as: dm_city
return a random city
80 81 82 |
# File 'lib/data_magic/translation.rb', line 80 def city Faker::Address.city end |
#company_name ⇒ Object Also known as: dm_company_name
return a random company name
121 122 123 |
# File 'lib/data_magic/translation.rb', line 121 def company_name Faker::Company.name end |
#country ⇒ Object Also known as: dm_country
return a random country
112 113 114 |
# File 'lib/data_magic/translation.rb', line 112 def country Faker::Address.country end |
#domain_name ⇒ Object Also known as: dm_domain_name
return a random domain name
185 186 187 |
# File 'lib/data_magic/translation.rb', line 185 def domain_name Faker::Internet.domain_name end |
#email_address(name = nil) ⇒ Object Also known as: dm_email_address
return a random email address
177 178 179 |
# File 'lib/data_magic/translation.rb', line 177 def email_address(name=nil) Faker::Internet.email(name) end |
#first_name ⇒ Object Also known as: dm_first_name
return a random first name
24 25 26 |
# File 'lib/data_magic/translation.rb', line 24 def first_name Faker::Name.first_name end |
#full_name ⇒ Object Also known as: dm_full_name
return a random name (first and last)
16 17 18 |
# File 'lib/data_magic/translation.rb', line 16 def full_name Faker::Name.name end |
#last_name ⇒ Object Also known as: dm_last_name
return a random last name
32 33 34 |
# File 'lib/data_magic/translation.rb', line 32 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
255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/data_magic/translation.rb', line 255 def mask(value) result = '' value.each_char do |ch| case ch when '#' then result += randomize(0..9).to_s when 'A' then result += ('A'..'Z').to_a[rand(26)] when 'a' then result += ('a'..'z').to_a[rand(26)] else result += ch end end result end |
#name_prefix ⇒ Object Also known as: dm_name_prefix
return a random name prefix
40 41 42 |
# File 'lib/data_magic/translation.rb', line 40 def name_prefix Faker::Name.prefix end |
#name_suffix ⇒ Object Also known as: dm_name_suffix
return a random name suffix
48 49 50 |
# File 'lib/data_magic/translation.rb', line 48 def name_suffix Faker::Name.suffix end |
#paragraphs(paragraph_count = 3) ⇒ Object Also known as: dm_paragraphs
return random paragraphs - default is 3 paragraphs
161 162 163 |
# File 'lib/data_magic/translation.rb', line 161 def paragraphs(paragraph_count = 3) Faker::Lorem.paragraphs(paragraph_count).join('\n\n') end |
#phone_number ⇒ Object Also known as: dm_phone_number
return a random phone number
209 210 211 212 |
# File 'lib/data_magic/translation.rb', line 209 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
227 228 229 230 231 232 233 |
# File 'lib/data_magic/translation.rb', line 227 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
72 73 74 |
# File 'lib/data_magic/translation.rb', line 72 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
145 146 147 |
# File 'lib/data_magic/translation.rb', line 145 def sentence(min_word_count = 4) Faker::Lorem.sentence(min_word_count) end |
#sentences(sentence_count = 3) ⇒ Object Also known as: dm_sentences
return random sentences - default is 3 sentences
153 154 155 |
# File 'lib/data_magic/translation.rb', line 153 def sentences(sentence_count = 3) Faker::Lorem.sentences(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.
241 242 243 244 245 246 247 |
# File 'lib/data_magic/translation.rb', line 241 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
88 89 90 |
# File 'lib/data_magic/translation.rb', line 88 def state Faker::Address.state end |
#state_abbr ⇒ Object Also known as: dm_state_abbr
return a random state abbreviation
96 97 98 |
# File 'lib/data_magic/translation.rb', line 96 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
64 65 66 |
# File 'lib/data_magic/translation.rb', line 64 def street_address(include_secondary=false) Faker::Address.street_address(include_secondary) end |
#title ⇒ Object Also known as: dm_title
return a random title
56 57 58 |
# File 'lib/data_magic/translation.rb', line 56 def title Faker::Name.title end |
#url ⇒ Object Also known as: dm_url
return a random url
193 194 195 |
# File 'lib/data_magic/translation.rb', line 193 def url Faker::Internet.url end |
#user_name ⇒ Object Also known as: dm_user_name
return a random user name
201 202 203 |
# File 'lib/data_magic/translation.rb', line 201 def user_name Faker::Internet.user_name end |
#words(number = 3) ⇒ Object Also known as: dm_words
return random words - default is 3 words
137 138 139 |
# File 'lib/data_magic/translation.rb', line 137 def words(number = 3) Faker::Lorem.words(number).join(' ') end |
#zip_code ⇒ Object Also known as: dm_zip_code
return a random 5 or 9 digit zip code
104 105 106 |
# File 'lib/data_magic/translation.rb', line 104 def zip_code Faker::Address.zip end |