faker 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -1
- data/README.md +13 -0
- data/lib/faker.rb +6 -0
- data/lib/faker/address.rb +11 -10
- data/lib/faker/company.rb +1 -1
- data/lib/faker/internet.rb +2 -2
- data/lib/faker/name.rb +6 -8
- data/lib/faker/phone_number.rb +1 -1
- data/lib/faker/version.rb +1 -1
- metadata +4 -4
data/History.txt
CHANGED
data/README.md
CHANGED
@@ -13,6 +13,19 @@ Usage
|
|
13
13
|
* Faker::Name.name => "Christophe Bartell"
|
14
14
|
* Faker::Internet.email => "kirsten.greenholt@corkeryfisher.info"
|
15
15
|
|
16
|
+
Usage with Rails
|
17
|
+
----------------
|
18
|
+
|
19
|
+
If you want to change your locale with Rails from the default of :en, change
|
20
|
+
config/application.rb, setting config.i18n.locale to whatever locale you
|
21
|
+
want. Change locale rather than default_locale (as suggested by the comments
|
22
|
+
in that file) so that I18n's fallbacks will work properly and Faker can use
|
23
|
+
the formats and data in en.yml (if there is no Faker localization for your
|
24
|
+
locale). If you'd prefer to set default_locale rather than locale, then
|
25
|
+
you'll also need to add config.i18n.fallbacks.defaults = [:en] to your
|
26
|
+
configuration to make the fallbacks work for Faker.
|
27
|
+
|
28
|
+
|
16
29
|
Customization
|
17
30
|
------------
|
18
31
|
Since you may want to make addresses and other types of data look different
|
data/lib/faker.rb
CHANGED
@@ -25,6 +25,12 @@ module Faker
|
|
25
25
|
def bothify(string)
|
26
26
|
letterify(numerify(string))
|
27
27
|
end
|
28
|
+
|
29
|
+
# Helper for the common approach of grabbing a translation with an array
|
30
|
+
# of values and selecting one of them
|
31
|
+
def fetch(key)
|
32
|
+
I18n.translate("faker.#{key}").rand
|
33
|
+
end
|
28
34
|
end
|
29
35
|
end
|
30
36
|
end
|
data/lib/faker/address.rb
CHANGED
@@ -18,25 +18,26 @@ module Faker
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def street_address(include_secondary = false)
|
21
|
-
numerify("#{
|
21
|
+
numerify("#{fetch('address.street_address')} #{street_name}#{' ' + secondary_address if include_secondary}")
|
22
22
|
end
|
23
23
|
|
24
24
|
def secondary_address
|
25
|
-
numerify(
|
25
|
+
numerify(fetch('address.secondary_address'))
|
26
26
|
end
|
27
27
|
|
28
28
|
def zip_code
|
29
|
-
bothify(
|
29
|
+
bothify(fetch('address.postcode')).upcase
|
30
30
|
end
|
31
31
|
alias_method :zip, :zip_code
|
32
32
|
alias_method :postcode, :zip_code
|
33
|
-
|
34
|
-
%w(street_suffix city_suffix city_prefix state_abbr state country county).each do |meth|
|
35
|
-
define_method(meth) do
|
36
|
-
I18n.translate("faker.address.#{meth}").rand
|
37
|
-
end
|
38
|
-
end
|
39
33
|
|
34
|
+
def street_suffix; fetch('address.street_suffix'); end
|
35
|
+
def city_suffix; fetch('address.city_suffix'); end
|
36
|
+
def city_prefix; fetch('address.city_prefix'); end
|
37
|
+
def state_abbr; fetch('address.state_abbr'); end
|
38
|
+
def state; fetch('address.state'); end
|
39
|
+
def country; fetch('address.country'); end
|
40
|
+
|
40
41
|
# You can add whatever you want to the locale file, and it will get
|
41
42
|
# caught here... e.g., create a country_code array in your locale,
|
42
43
|
# then you can call #country_code and it will act like #country
|
@@ -54,7 +55,7 @@ module Faker
|
|
54
55
|
alias_method :us_state, :state
|
55
56
|
alias_method :us_state_abbr, :state_abbr
|
56
57
|
alias_method :uk_postcode, :zip_code
|
57
|
-
|
58
|
+
def uk_county; county; end
|
58
59
|
|
59
60
|
end
|
60
61
|
end
|
data/lib/faker/company.rb
CHANGED
data/lib/faker/internet.rb
CHANGED
@@ -6,7 +6,7 @@ module Faker
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def free_email(name = nil)
|
9
|
-
[ user_name(name),
|
9
|
+
[ user_name(name), fetch('internet.free_email') ].join('@')
|
10
10
|
end
|
11
11
|
|
12
12
|
def user_name(name = nil)
|
@@ -30,7 +30,7 @@ module Faker
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def domain_suffix
|
33
|
-
|
33
|
+
fetch('internet.domain_suffix')
|
34
34
|
end
|
35
35
|
|
36
36
|
def ip_v4_address
|
data/lib/faker/name.rb
CHANGED
@@ -3,16 +3,14 @@ module Faker
|
|
3
3
|
class << self
|
4
4
|
|
5
5
|
def name
|
6
|
-
|
6
|
+
fetch('name.formats').collect {|meth| self.send(meth) }.join(' ')
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
9
|
+
def first_name; fetch('name.first_name'); end
|
10
|
+
def last_name; fetch('name.last_name'); end
|
11
|
+
def prefix; fetch('name.prefix'); end
|
12
|
+
def suffix; fetch('name.suffix'); end
|
13
|
+
|
16
14
|
end
|
17
15
|
end
|
18
16
|
end
|
data/lib/faker/phone_number.rb
CHANGED
data/lib/faker/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 51
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 4
|
10
|
+
version: 0.9.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Benjamin Curtis
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-29 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|