forgery 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,7 @@ Using
15
15
 
16
16
  You'll want to read individual Forgery categories for more information, but these are the basics:
17
17
 
18
- ~~~ Ruby
18
+ ```ruby
19
19
  Forgery(:basic).password
20
20
  #=> "b6qZTQEH"
21
21
 
@@ -30,17 +30,17 @@ Forgery(:lorem_ipsum).words(10)
30
30
 
31
31
  Forgery(:monetary).formatted_money :min => 100, :max => 1000
32
32
  #=> "$923.36"
33
- ~~~
33
+ ```
34
34
 
35
35
  And many many [more]()!
36
36
 
37
37
  Alternatively you can write it like this:
38
38
 
39
- ~~~ Ruby
39
+ ```ruby
40
40
  Forgery::Basic.hex_color
41
41
  Forgery::Name.full_name
42
42
  Forgery::Personal.shirt_size
43
- ~~~
43
+ ```
44
44
 
45
45
  In addition, you can always write your own dictionaries and formats, overriding the ones in the gem.
46
46
  Fully explained [here]().
@@ -53,9 +53,9 @@ Like any gem, you can install Forgery two ways depending on it's use.
53
53
 
54
54
  For normal Ruby development, you need simply use:
55
55
 
56
- ~~~
56
+ ```bash
57
57
  $ gem install forgery
58
- ~~~
58
+ ```
59
59
 
60
60
  This will add it to your gem library, just like any normal gem.
61
61
  You can then use it like any normal gem library.
@@ -67,42 +67,40 @@ See [examples]() for more.
67
67
  If you're using Rails 3.x you need to do a few extra things (that are probably rote).
68
68
  First step is to add it to your `Rails.root/Gemfile`, we also suggest specifying the latest version (found on rubygems):
69
69
 
70
- ~~~ ruby
70
+ ```ruby
71
71
  gem 'forgery', '0.3.12'
72
- ~~~
72
+ ```
73
73
 
74
74
  Then you'll need to run `bundle install` to install and lock in your new gem.
75
75
  Next you'll want to run the special Rails 3 generator:
76
76
 
77
- ~~~
77
+ ```
78
78
  $ [bundle exec] rails generate forgery
79
- ~~~
79
+ ```
80
80
 
81
81
  **Rails 2.x**
82
82
 
83
83
  For **Rails 2.x** you'll need to do something a little different, by first editing your `Rails.root/config/environment.rb` and adding this to the configuration block:
84
84
 
85
- ~~~ ruby
85
+ ```ruby
86
86
  config.gem 'forgery'
87
- ~~~
87
+ ```
88
88
 
89
89
  Then you'll need to run this in your command line:
90
90
 
91
- ~~~
91
+ ```bash
92
92
  $ script/generate forgery
93
- ~~~
93
+ ```
94
94
 
95
95
  **Generators**
96
96
 
97
97
  This Rails generators will make these directories in your Rails.root directory:
98
98
 
99
- ~~~ YAML
100
99
  - Rails.root/lib/forgery
101
100
  - Rails.root/lib/forgery/dictionaries
102
101
  - Rails.root/lib/forgery/extensions
103
102
  - Rails.root/lib/forgery/forgeries
104
103
  - Rails.root/lib/forgery/formats
105
- ~~~
106
104
 
107
105
  You can then use these directories to write your own dictionaries, class extensions, forgeries, and formats.
108
106
 
@@ -132,6 +130,9 @@ Thanks to the authors and contributors:
132
130
  * Stafford Brunk (wingrunr21)
133
131
  * SixArm (SixArm)
134
132
  * Akira Matsuda (amatsuda)
133
+ * Diego Plentz (plentz)
134
+ * Gabe Berke-Williams (gabebw)
135
+ * Todd Mazierski (toddmazierski)
135
136
 
136
137
 
137
138
  Licensing
data/Rakefile CHANGED
@@ -1,40 +1,12 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'rspec/core'
1
+ require 'bundler'
4
2
  require 'rspec/core/rake_task'
5
- require 'rdoc/task'
6
- require File.expand_path('./lib/forgery/file_writer')
7
-
8
- begin
9
- require 'sdoc_helpers'
10
- rescue LoadError
11
- puts "sdoc support not enabled. Please gem install sdoc-helpers."
12
- end
13
-
14
- desc 'Default: run specs with rcov.'
15
- task :default => :rcov_spec
16
3
 
17
- desc 'Run the specs'
18
- RSpec::Core::RakeTask.new(:spec) do |t|
19
- t.rspec_opts = ['--colour --format progress']
20
- t.pattern = FileList['spec/**/*_spec.rb']
21
- end
4
+ Bundler::GemHelper.install_tasks
5
+ RSpec::Core::RakeTask.new
22
6
 
23
- desc 'Run the specs with rcov'
24
- RSpec::Core::RakeTask.new("rcov_spec") do |t|
25
- t.pattern = FileList['spec/**/*_spec.rb']
26
- t.rspec_opts = ['--color']
27
- t.rcov = true
28
- t.rcov_opts = ['--exclude', '^spec,/gems/']
29
- end
7
+ task :default => :spec
30
8
 
31
- Rake::RDocTask.new do |t|
32
- t.rdoc_dir = 'doc'
33
- t.rdoc_files.include('lib/**/*.rb')
34
- t.options << '--inline-source'
35
- t.options << '--all'
36
- t.options << '--line-numbers'
37
- end
9
+ require File.expand_path('./lib/forgery/file_writer')
38
10
 
39
11
  desc %q{
40
12
  Create a dictionary file from web content (xml or html).
@@ -3,8 +3,6 @@ class Forgery
3
3
  case object
4
4
  when Array
5
5
  Forgery::Extensions::Array.new(object)
6
- when Hash
7
- Forgery::Extensions::Hash.new(object)
8
6
  when Range
9
7
  Forgery::Extensions::Range.new(object.first, object.last, object.exclude_end?)
10
8
  when String
@@ -0,0 +1,71 @@
1
+ # Generates random credit card numbers.
2
+ class Forgery::CreditCard < Forgery
3
+
4
+ CARDS = Forgery::Extend([
5
+ {:type => 'Visa', :length => 16, :prefixes => %w"4539 4556 4916 4532 4929 40240071 4485 4716 4"},
6
+ {:type => 'MasterCard', :length => 16, :prefixes => %w"51 52 53 54 55"},
7
+ {:type => 'American Express', :length => 15, :prefixes => %w"34 37"},
8
+ {:type => 'Discover', :length => 16, :prefixes => ["6011"]}
9
+ ])
10
+
11
+ # Gets a random credit card type
12
+ #
13
+ # Forgery(:credit_card).type
14
+ # # => "Visa"
15
+ def self.type
16
+ CARDS.random[:type]
17
+ end
18
+
19
+ # Gets a random credit card number
20
+ #
21
+ # Forgery(:credit_card).number
22
+ # # => "4539750423451972"
23
+ #
24
+ # Forgery(:credit_card).number(:type => 'Visa', :length => 13)
25
+ # # => "4556180133982"
26
+ #
27
+ # Supported Options
28
+ # [:type]
29
+ # The credit card type. Defaults to a random selection.
30
+ # [:length]
31
+ # The length of the credit card number. Defaults to the length for the selected card type.
32
+ # [:prefixes]
33
+ # The allowed prefixes for the card number. Defaults to prefixes for the selected card type.
34
+ def self.number(options={})
35
+ # find a card by type specified, or select a card randomly
36
+ card = if options[:type]
37
+ CARDS.find { |card| card[:type] == options[:type] }.clone
38
+ else
39
+ CARDS.random.clone
40
+ end
41
+ # merge the remaining options
42
+ card.merge!(options)
43
+ # start the number with a prefix for this card
44
+ number = Forgery::Extend(card[:prefixes]).random
45
+ # fill in the rest of the number with random digits, leave one space for the check digit
46
+ number << Forgery::Extend("#" * (card[:length] - number.length - 1)).to_numbers
47
+ # add the check digit
48
+ number += check_digit(number)
49
+ end
50
+
51
+ private
52
+
53
+ def self.check_digit(number)
54
+ # for explanation, please see: http://www.darkcoding.net/credit-card/luhn-formula/
55
+ sum = 0
56
+ digits = number.reverse.chars.to_a.collect { |digit| digit.to_i }
57
+ digits.each_with_index do |digit, index|
58
+ if index.even?
59
+ sum += if digit * 2 > 9
60
+ digit * 2 - 9
61
+ else
62
+ digit * 2
63
+ end
64
+ else
65
+ sum += digit
66
+ end
67
+ end
68
+ (((sum / 10 + 1) * 10 - sum) % 10).to_s
69
+ end
70
+
71
+ end
@@ -1,3 +1,3 @@
1
1
  class Forgery
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
metadata CHANGED
@@ -1,48 +1,63 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: forgery
3
- version: !ruby/object:Gem::Version
4
- version: 0.4.3
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 4
9
+ - 4
10
+ version: 0.4.4
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Nathan Sutton
9
14
  - Brandon Arbini
10
15
  autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
- date: 2011-09-05 00:00:00.000000000Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
18
+
19
+ date: 2011-09-08 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
16
22
  name: nokogiri
17
- requirement: &70093145962180 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
18
25
  none: false
19
- requirements:
26
+ requirements:
20
27
  - - ~>
21
- - !ruby/object:Gem::Version
22
- version: '1.4'
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 1
32
+ - 4
33
+ version: "1.4"
23
34
  type: :runtime
24
- prerelease: false
25
- version_requirements: *70093145962180
26
- - !ruby/object:Gem::Dependency
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
27
37
  name: rspec
28
- requirement: &70093145961760 !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
29
40
  none: false
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
34
48
  type: :development
35
- prerelease: false
36
- version_requirements: *70093145961760
37
- description: Easy and customizable generation of forged data. Can be used as a gem
38
- or a rails plugin. Includes rails generators for creating your own forgeries.
39
- email:
49
+ version_requirements: *id002
50
+ description: Easy and customizable generation of forged data. Can be used as a gem or a rails plugin. Includes rails generators for creating your own forgeries.
51
+ email:
40
52
  - nate@zencoder.com
41
53
  - brandon@zencoder.com
42
54
  executables: []
55
+
43
56
  extensions: []
57
+
44
58
  extra_rdoc_files: []
45
- files:
59
+
60
+ files:
46
61
  - generators/forgery/forgery_generator.rb
47
62
  - generators/forgery/USAGE
48
63
  - lib/forgery/dictionaries/cities
@@ -85,6 +100,7 @@ files:
85
100
  - lib/forgery/file_writer.rb
86
101
  - lib/forgery/forgery/address.rb
87
102
  - lib/forgery/forgery/basic.rb
103
+ - lib/forgery/forgery/credit_card.rb
88
104
  - lib/forgery/forgery/currency.rb
89
105
  - lib/forgery/forgery/date.rb
90
106
  - lib/forgery/forgery/email.rb
@@ -109,26 +125,36 @@ files:
109
125
  - Rakefile
110
126
  homepage: http://github.com/sevenwire/forgery
111
127
  licenses: []
128
+
112
129
  post_install_message:
113
130
  rdoc_options: []
114
- require_paths:
131
+
132
+ require_paths:
115
133
  - lib
116
- required_ruby_version: !ruby/object:Gem::Requirement
134
+ required_ruby_version: !ruby/object:Gem::Requirement
117
135
  none: false
118
- requirements:
119
- - - ! '>='
120
- - !ruby/object:Gem::Version
121
- version: '0'
122
- required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ hash: 3
140
+ segments:
141
+ - 0
142
+ version: "0"
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
144
  none: false
124
- requirements:
125
- - - ! '>='
126
- - !ruby/object:Gem::Version
127
- version: '0'
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
128
152
  requirements: []
153
+
129
154
  rubyforge_project: forgery
130
- rubygems_version: 1.8.10
155
+ rubygems_version: 1.8.7
131
156
  signing_key:
132
157
  specification_version: 3
133
158
  summary: Easy and customizable generation of forged data.
134
159
  test_files: []
160
+