ffaker 1.16.0 → 1.16.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ == 1.16.1
2
+ Fixes for ruby 1.8.x
3
+
1
4
  == 1.16.0
2
5
  Many module additions from different contributors!
3
6
 
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
4
4
  s.rubygems_version = '1.3.5'
5
5
 
6
6
  s.name = 'ffaker'
7
- s.version = '1.16.0'
8
- s.date = '2013-04-28'
7
+ s.version = '1.16.1'
8
+ s.date = '2013-05-02'
9
9
  s.rubyforge_project = 'ffaker'
10
10
 
11
11
  s.summary = "Faster Faker, generates dummy data."
@@ -1,5 +1,5 @@
1
1
  module Faker
2
- VERSION = "1.16.0"
2
+ VERSION = "1.16.1"
3
3
 
4
4
  require 'ffaker/utils/array_utils'
5
5
  require 'ffaker/utils/module_utils'
@@ -7,7 +7,6 @@ module Faker
7
7
  extend ModuleUtils
8
8
 
9
9
  LETTERS = k('a'..'z')
10
- CAPITAL_LETTERS = k('A'..'Z')
11
10
 
12
11
  def self.numerify(*masks)
13
12
  mask = ArrayUtils.rand(masks.flatten)
@@ -15,18 +14,14 @@ module Faker
15
14
  mask
16
15
  end
17
16
 
18
- def self.letterify(capitalize = false, *masks)
17
+ def self.letterify(*masks)
19
18
  mask = ArrayUtils.rand(masks.flatten)
20
- if capitalize
21
- mask.gsub!(/\?/) {CAPITAL_LETTERS.rand}
22
- else
23
- mask.gsub!(/\?/) { LETTERS.rand }
24
- end
19
+ mask.gsub!(/\?/) { LETTERS.rand }
25
20
  mask
26
21
  end
27
22
 
28
- def self.bothify(capitalize = false, masks)
29
- letterify(capitalize, numerify(masks))
23
+ def self.bothify(masks)
24
+ letterify(numerify(masks))
30
25
  end
31
26
 
32
27
  autoload :Address, 'ffaker/address'
@@ -42,7 +42,7 @@ module Faker
42
42
  end
43
43
 
44
44
  def building_number
45
- Faker.numerify ( '#' * rand(3) ) << '###'
45
+ Faker.numerify(( '#' * rand(3) ) << '###')
46
46
  end
47
47
 
48
48
  def street_name
@@ -6,6 +6,10 @@ module Faker
6
6
  extend ModuleUtils
7
7
  extend self
8
8
 
9
+ def zip_code
10
+ Faker::AddressUS.zip_code
11
+ end
12
+
9
13
  def postal_code
10
14
  Faker.numerify POSTAL_CODE_FORMATS.rand
11
15
  end
@@ -4,7 +4,7 @@ module Faker
4
4
  extend self
5
5
 
6
6
  def drivers_license
7
- Faker.bothify(true, '?###-###-##-###-#')
7
+ Faker.bothify('?###-###-##-###-#').upcase
8
8
  end
9
9
 
10
10
  def ssn
@@ -22,4 +22,4 @@ module Faker
22
22
  ETHNICITIES = k ['African American', 'Asian/Pacific Islander', 'Caucasian', 'Hispanic', 'Native American', 'Multiracial', 'Other', 'Prefer not to respond']
23
23
  GENDERS = k %w(Male Female)
24
24
  end
25
- end
25
+ end
@@ -26,39 +26,40 @@ module Faker
26
26
  private
27
27
 
28
28
  def title_with_prefix
29
- "#{PREFIXES.sample} #{maybe_adj_or_adv}#{NOUNS.sample}"
29
+ "#{PREFIXES.rand} #{maybe_adj_or_adv}#{NOUNS.rand}"
30
30
  end
31
31
 
32
32
  def title_with_suffix
33
- "The #{maybe_adj_or_adv}#{NOUNS.sample} #{SUFFIXES.sample}"
33
+ "The #{maybe_adj_or_adv}#{NOUNS.rand} #{SUFFIXES.rand}"
34
34
  end
35
35
 
36
36
  def maybe_adj_or_adv
37
37
  if rand(2) == 1
38
- ADJ_AND_ADV.sample + " "
38
+ ADJ_AND_ADV.rand + " "
39
39
  end
40
40
  end
41
41
 
42
42
  def simple_title
43
- "#{ADJ_AND_ADV.sample} #{NOUNS.sample}"
43
+ "#{ADJ_AND_ADV.rand} #{NOUNS.rand}"
44
44
  end
45
45
 
46
46
  def title_from_formula
47
- [
48
- "#{NOUNS.sample} 2: Electric Boogaloo",
49
- "The #{NOUNS.sample} Without a #{NOUNS.sample}",
50
- "The #{NOUNS.sample} from #{rand(20_000)} Leagues",
51
- "#{simple_title}: The #{Faker::Name.name} Story",
52
- "When #{Faker::Name.first_name} Met #{Faker::Name.first_name}",
53
- "Dr. #{NOUNS.sample}",
54
- "Je Vous Presente, #{Faker::Name.first_name}",
55
- "#{rand(3000)} A.D.",
56
- "The #{NOUNS.sample} from #{Faker::Address.neighborhood}",
57
- "Christmas on #{Faker::Address.street_name}",
58
- "The #{ %w{ Red Yellow Black White }.sample } Rose of #{Faker::AddressUK.country}",
59
- "Hard Boiled #{NOUNS.sample}",
60
- String.new.tap{|s| n = simple_title; s.replace("#{n} 2: Son of #{n}")}
61
- ].sample
47
+ case rand(13)
48
+ when 0 then "#{NOUNS.rand} 2: Electric Boogaloo"
49
+ when 1 then "The #{NOUNS.rand} Without a #{NOUNS.rand}"
50
+ when 2 then "The #{NOUNS.rand} from #{rand(20_000)} Leagues"
51
+ when 3 then "#{simple_title}: The #{Faker::Name.name} Story"
52
+ when 4 then "When #{Faker::Name.first_name} Met #{Faker::Name.first_name}"
53
+ when 5 then "Dr. #{NOUNS.rand}"
54
+ when 6 then "Je Vous Presente, #{Faker::Name.first_name}"
55
+ when 7 then "#{rand(3000)} A.D."
56
+ when 8 then "The #{NOUNS.rand} from #{Faker::Address.neighborhood}"
57
+ when 9 then "Christmas on #{Faker::Address.street_name}"
58
+ when 10 then "The #{ %w{ Red Yellow Black White }.rand } Rose of #{Faker::AddressUK.country}"
59
+ when 11 then "Hard Boiled #{NOUNS.rand}"
60
+ else
61
+ String.new.tap{|s| n = simple_title; s.replace("#{n} 2: Son of #{n}")}
62
+ end
62
63
  end
63
64
  end
64
65
  end
@@ -26,7 +26,7 @@ module Faker
26
26
  def ssn(opts = {})
27
27
  from = opts[:from] || ::Time.local(1940, 1, 1)
28
28
  to = opts[:to] || ::Time.now
29
- gender = opts[:gender] || genders.sample
29
+ gender = opts[:gender] || GENDERS.rand
30
30
 
31
31
  raise_error_on_bad_arguments(from, to, gender)
32
32
 
@@ -48,13 +48,10 @@ module Faker
48
48
  raise ArgumentError, "Invalid from argument: from" unless to.is_a? ::Time
49
49
  raise ArgumentError, "Invalid from argument: from" unless from.is_a? ::Time
50
50
  raise ArgumentError, "Invalid argument: from > to" if from > to
51
- raise ArgumentError, "Invalid argument: gender" unless genders.include?(gender)
51
+ raise ArgumentError, "Invalid argument: gender" unless GENDERS.include?(gender.to_s)
52
52
  end
53
53
 
54
- def genders
55
- # XXX Don't like this def.
56
- [:female, :male]
57
- end
54
+ GENDERS = k ["female", "male"]
58
55
 
59
56
  def random_birth_time_between(from=::Time.local(1940, 1, 1), to=::Time.now)
60
57
  ::Time.at(from + rand * (to.to_f - from.to_f))
@@ -62,18 +59,18 @@ module Faker
62
59
 
63
60
  def get_random_region_for(gender)
64
61
  region_number = case gender
65
- when :female then get_random_region_even
66
- when :male then get_random_region_odd
62
+ when "female" then get_random_region_even
63
+ when "male" then get_random_region_odd
67
64
  end
68
65
  three_character_string(region_number)
69
66
  end
70
67
 
71
68
  def get_random_region_even
72
- (0..998).step(2).to_a.sample
69
+ rand(499) * 2
73
70
  end
74
71
 
75
72
  def get_random_region_odd
76
- get_random_region_even + 1
73
+ rand(499) * 2 + 1
77
74
  end
78
75
 
79
76
  def three_character_string(number)
@@ -10,19 +10,19 @@ module Faker
10
10
  def date(params={})
11
11
  years_back = params[:year_range] || 5
12
12
  latest_year = params [:year_latest] || 0
13
- year = (rand * (years_back)).ceil + (Object::Time.now.year - latest_year - years_back)
13
+ year = (rand * (years_back)).ceil + (::Time.now.year - latest_year - years_back)
14
14
  month = (rand * 12).ceil
15
15
  day = (rand * 31).ceil
16
- series = [date = Object::Time.local(year, month, day)]
16
+ series = [date = ::Time.local(year, month, day)]
17
17
  if params[:series]
18
18
  params[:series].each do |some_time_after|
19
19
  series << series.last + (rand * some_time_after).ceil
20
20
  end
21
21
  return series
22
22
  end
23
- date
23
+ date.strftime "%Y-%m-%d %T %z"
24
24
  end
25
25
 
26
26
  MONTHS = k %w(January February March April May June July August September October November December)
27
27
  end
28
- end
28
+ end
@@ -4,40 +4,25 @@ class TestFaker < Test::Unit::TestCase
4
4
  def test_numerify
5
5
  assert Faker.numerify('###').match(/\d{3}/)
6
6
  end
7
-
7
+
8
8
  def test_numerify_with_array
9
9
  assert Faker.numerify(['###', '###']).match(/\d{3}/)
10
10
  end
11
11
 
12
12
  def test_letterify
13
- assert Faker.letterify(false, '???').match(/[a-z]{3}/)
14
- end
15
-
16
- def test_capital_letterify
17
- assert Faker.letterify(true, '???').match(/[A-Z]{3}/)
13
+ assert Faker.letterify('???').match(/[a-z]{3}/)
18
14
  end
19
15
 
20
16
  def test_letterify_with_array
21
- assert Faker.letterify(false, ['???', '???']).match(/[a-z]{3}/)
17
+ assert Faker.letterify(['???', '???']).match(/[a-z]{3}/)
22
18
  end
23
19
 
24
- def test_capital_letterify_with_array
25
- assert Faker.letterify(true, ['???', '???']).match(/[A-Z]{3}/)
26
- end
27
-
28
20
  def test_bothify
29
21
  assert Faker.bothify('???###').match(/[a-z]{3}\d{3}/)
30
22
  end
31
23
 
32
- def test_capital_bothify
33
- assert Faker.bothify(true, '???###').match(/[A-Z]{3}\d{3}/)
34
- end
35
-
36
24
  def test_bothify_with_array
37
- assert Faker.bothify(false, ['???###', '???###']).match(/[a-z]{3}\d{3}/)
25
+ assert Faker.bothify(['???###', '???###']).match(/[a-z]{3}\d{3}/)
38
26
  end
39
27
 
40
- def test_capital_bothify_with_array
41
- assert Faker.bothify(true, ['???###', '???###']).match(/[A-Z]{3}\d{3}/)
42
- end
43
28
  end
@@ -14,14 +14,14 @@ class TestSSN < Test::Unit::TestCase
14
14
  end
15
15
 
16
16
  def test_ssn_with_gender
17
- ssn_male = Faker::SSNSE.ssn(gender: :male)
17
+ ssn_male = Faker::SSNSE.ssn(:gender => :male)
18
18
  assert is_equal?(ssn_male[10].to_i)
19
19
 
20
- ssn_female = Faker::SSNSE.ssn(gender: :female)
20
+ ssn_female = Faker::SSNSE.ssn(:gender => :female)
21
21
  assert is_equal?(ssn_female[10].to_i)
22
22
 
23
23
  assert_raise ArgumentError do
24
- Faker::SSNSE.ssn(gender: :unkown)
24
+ Faker::SSNSE.ssn(:gender => :unkown)
25
25
  end
26
26
  end
27
27
 
@@ -30,7 +30,7 @@ class TestSSN < Test::Unit::TestCase
30
30
  from = Time.local(1980, 2, 28)
31
31
  to = Time.local(2000, 2, 28)
32
32
 
33
- ssn = Faker::SSNSE.ssn(from: from, to: to)
33
+ ssn = Faker::SSNSE.ssn(:from => from, :to => to)
34
34
  year = ssn[0..3].to_i
35
35
  month = ssn[4..5].to_i
36
36
  day = ssn[6..7].to_i
metadata CHANGED
@@ -1,57 +1,61 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ffaker
3
- version: !ruby/object:Gem::Version
4
- version: 1.16.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 85
5
5
  prerelease:
6
+ segments:
7
+ - 1
8
+ - 16
9
+ - 1
10
+ version: 1.16.1
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Emmanuel Oga
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2013-04-28 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2013-05-02 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: rake
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
23
22
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: test-unit
32
- requirement: !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
33
24
  none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
38
32
  type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: test-unit
39
36
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
37
+ requirement: &id002 !ruby/object:Gem::Requirement
41
38
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
46
48
  description: Faster Faker, generates dummy data.
47
49
  email: EmmanuelOga@gmail.com
48
50
  executables: []
51
+
49
52
  extensions: []
50
- extra_rdoc_files:
53
+
54
+ extra_rdoc_files:
51
55
  - README.rdoc
52
56
  - LICENSE
53
57
  - Changelog.rdoc
54
- files:
58
+ files:
55
59
  - Changelog.rdoc
56
60
  - Gemfile
57
61
  - LICENSE
@@ -169,30 +173,38 @@ files:
169
173
  - test/test_venue.rb
170
174
  homepage: http://github.com/emmanueloga/ffaker
171
175
  licenses: []
176
+
172
177
  post_install_message:
173
- rdoc_options:
178
+ rdoc_options:
174
179
  - --charset=UTF-8
175
- require_paths:
180
+ require_paths:
176
181
  - lib
177
- required_ruby_version: !ruby/object:Gem::Requirement
182
+ required_ruby_version: !ruby/object:Gem::Requirement
178
183
  none: false
179
- requirements:
180
- - - ! '>='
181
- - !ruby/object:Gem::Version
182
- version: '0'
183
- required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ hash: 3
188
+ segments:
189
+ - 0
190
+ version: "0"
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
192
  none: false
185
- requirements:
186
- - - ! '>='
187
- - !ruby/object:Gem::Version
188
- version: '0'
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ hash: 3
197
+ segments:
198
+ - 0
199
+ version: "0"
189
200
  requirements: []
201
+
190
202
  rubyforge_project: ffaker
191
203
  rubygems_version: 1.8.25
192
204
  signing_key:
193
205
  specification_version: 2
194
206
  summary: Faster Faker, generates dummy data.
195
- test_files:
207
+ test_files:
196
208
  - test/test_address.rb
197
209
  - test/test_address_au.rb
198
210
  - test/test_address_ca.rb