forgery 0.3.12 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,132 +1,122 @@
1
- # Forgery
1
+ Forgery
2
+ =======
2
3
 
3
- The Problem:
4
- Making meaningful development data for your application.
4
+ **A Problem**:
5
+ It's harder than *absolutely easy* to make meaningful, simple, data for testing and development.
5
6
 
6
- The Solution:
7
- A fake data generator that does more than just lorem ipsum and random text
8
- (well, it does those too, but also does much more).
7
+ **A Solution**:
8
+ A fake data generator that provides not only a host of basics and a rememberable syntax, but a customizable library to boot.
9
9
 
10
- Forgery generates fake data from dictionaries, formats, and recipes. The
11
- plugin includes a generator providing directories to make your own forgeries.
10
+ Welcome to Forgery, an excellent solution to a problem so hard you didn't know it was there.
12
11
 
13
12
 
14
- ## Install
13
+ Using
14
+ -----
15
15
 
16
- ### Run
16
+ You'll want to read individual Forgery categories for more information, but these are the basics:
17
17
 
18
- gem install forgery
18
+ ~~~ Ruby
19
+ Forgery(:basic).password
20
+ #=> "b6qZTQEH"
19
21
 
20
- ### Rails 2
22
+ Forgery(:internet).email_address
23
+ #=> "krainboltgreene@crt.net"
21
24
 
22
- # Add this to your config/environment.rb
23
- config.gem 'forgery'
25
+ Forgery(:monetary).money
26
+ #=> "1.58"
24
27
 
25
- ### Rails 3
28
+ Forgery(:lorem_ipsum).words(10)
29
+ #=> "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam egestas."
26
30
 
27
- # Add this to your Gemfile
28
- gem 'forgery'
31
+ Forgery(:monetary).formatted_money :min => 100, :max => 1000
32
+ #=> "$923.36"
33
+ ~~~
29
34
 
30
- ## Rails 2 Generator
35
+ And many many [more]()!
31
36
 
32
- ruby script/generate forgery
37
+ Alternatively you can write it like this:
33
38
 
34
- ## Rails 3 Generator
39
+ ~~~ Ruby
40
+ Forgery::Basic.hex_color
41
+ Forgery::Name.full_name
42
+ Forgery::Personal.shirt_size
43
+ ~~~
35
44
 
36
- rails generate forgery
45
+ In addition, you can always write your own dictionaries and formats, overriding the ones in the gem.
46
+ Fully explained [here]().
37
47
 
38
- In a rails project this generator creates:
39
48
 
40
- * Rails.root/lib/forgery
41
- * Rails.root/lib/forgery/dictionaries
42
- * Rails.root/lib/forgery/extensions
43
- * Rails.root/lib/forgery/forgeries
44
- * Rails.root/lib/forgery/formats
49
+ Installing
50
+ ----------
45
51
 
46
- You can then use these directories to write your own dictionaries, class
47
- extensions, forgeries, and formats.
52
+ Like any gem, you can install Forgery two ways depending on it's use.
48
53
 
54
+ For normal Ruby development, you need simply use:
49
55
 
50
- Forgery will first look here for dictionaries and formats, so you can override
51
- the ones used in the plugin.
56
+ ~~~
57
+ $ gem install forgery
58
+ ~~~
52
59
 
53
- See the forgeries in the plugin for examples of how to write your own.
60
+ This will add it to your gem library, just like any normal gem.
61
+ You can then use it like any normal gem library.
62
+ See [examples]() for more.
54
63
 
55
- See which dictionaries each forgery uses to override them with your own.
56
64
 
65
+ **Rails 3.x**
57
66
 
58
- The Rails 3 plugin also registers a rake task which can generate new dictionaries
59
- from html or xml on the web.
67
+ If you're using Rails 3.x you need to do a few extra things (that are probably rote).
68
+ First step is to add it to your `Rails.root/Gemfile`, we also suggest specifying the latest version (found on rubygems):
60
69
 
61
- Writes to '${RAILS_ROOT}/lib/forgery/dictionaries' by default
62
- (this can be overriden by setting Forgery::FileWriter#write_to!)
70
+ ~~~ ruby
71
+ gem 'forgery', '0.3.12'
72
+ ~~~
63
73
 
64
- Parameters:
65
- :dictionary_name -- the name of your new dictionary file
66
- :source_url -- web page containing the data for your dictionary file
67
- :css_or_xpath -- css or xpath selector(s) to element(s) containing the desired data
74
+ Then you'll need to run `bundle install` to install and lock in your new gem.
75
+ Next you'll want to run the special Rails 3 generator:
68
76
 
69
- Usage:
70
- rake create_dictionary[name_of_file,'http://www.html_or_xml_page.com','li']
71
- ## Examples
77
+ ~~~
78
+ $ [bundle exec] rails generate forgery
79
+ ~~~
72
80
 
73
- Here I'll supply a few examples of how it works, in general. See each forgery
74
- for individual examples.
81
+ **Rails 2.x**
75
82
 
76
- # Traditional syntax
77
- Forgery::Basic.password # => "wYMYvq"
78
- Forgery::Basic.password :allow_special => true # => ";Qo^N[T"
79
- Forgery::Basic.hex_color # => "#f4d841"
80
-
81
- Forgery::Monetary.money # => "8.21"
82
- Forgery::Monetary.formatted_money # => "$3.25"
83
- Forgery::Monetary.money :min => 100, :max => 1000 # => "848.97"
84
-
85
- # Alternate syntax
86
- Forgery(:basic).password # => "b6qZTQEH"
87
- Forgery(:basic).password :allow_special => true # => "XlrhV%An"
88
- Forgery(:basic).hex_color # => "#46b73f"
89
-
90
- Forgery(:monetary).money # => "1.58"
91
- Forgery(:monetary).formatted_money # => "$3.48"
92
- Forgery(:monetary).money :min => 100, :max => 1000 # => "923.36"
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:
93
84
 
94
- ## Customization
85
+ ~~~ ruby
86
+ config.gem 'forgery'
87
+ ~~~
95
88
 
96
- You can utilize the directories generated in /lib to customize the behavior of forgery.
89
+ Then you'll need to run this in your command line:
97
90
 
98
- Examples of each of these components are available in the source.
91
+ ~~~
92
+ $ script/generate forgery
93
+ ~~~
99
94
 
100
- ### Dictionaries
95
+ **Generators**
101
96
 
102
- Dictionaries are files with no extensions. Entries are separated by new lines.
97
+ This Rails generators will make these directories in your Rails.root directory:
103
98
 
104
- ### Forgeries
99
+ ~~~ YAML
100
+ - Rails.root/lib/forgery
101
+ - Rails.root/lib/forgery/dictionaries
102
+ - Rails.root/lib/forgery/extensions
103
+ - Rails.root/lib/forgery/forgeries
104
+ - Rails.root/lib/forgery/formats
105
+ ~~~
105
106
 
106
- Forgeries are classes that inherit from the Forgery class. A basic forgery definition is as follows
107
+ You can then use these directories to write your own dictionaries, class extensions, forgeries, and formats.
107
108
 
108
- class NewForgery < Forgery
109
- end
110
109
 
111
- ### Extensions
110
+ Contributing
111
+ ------------
112
112
 
113
- Extensions are additional methods/functionality that are added to classes (Ruby core or otherwise) that are loaded by Forgery. Follow standard Ruby practices.
113
+ This is a work in progress and an open source project, so feel free to contribute.
114
+ We'll take pull requests via git or suggestions via the issues tab.
115
+ Any work done on Forgery will get you into the credits list and in our hearts.
114
116
 
115
- ### Formats
116
117
 
117
- Formatting for numerical fields. Each numerical entry corresponds to a # mark.
118
-
119
- ## DOCUMENTATION
120
-
121
- Documentation can be found at [http://sevenwire.github.com/forgery/](http://sevenwire.github.com/forgery/)
122
-
123
- ## TODO
124
-
125
- * Add instanced forgeries for more relative information generation.
126
- * Add markov chains.
127
- * Add a way to use probability in forgeries.
128
-
129
- ## Thanks
118
+ Credits
119
+ -------
130
120
 
131
121
  Thanks to the authors and contributors:
132
122
 
@@ -143,11 +133,29 @@ Thanks to the authors and contributors:
143
133
  * SixArm (SixArm)
144
134
  * Akira Matsuda (amatsuda)
145
135
 
146
- ## Notes
147
136
 
148
- This is a work in progress. If you find bugs or have forgeries to contribute,
149
- we'll gladly take them and give credit.
137
+ Licensing
138
+ ---------
139
+
140
+ Copyright (c) 2007 Sevenwire LLC
141
+
142
+ Permission is hereby granted, free of charge, to any person obtaining
143
+ a copy of this software and associated documentation files (the
144
+ "Software"), to deal in the Software without restriction, including
145
+ without limitation the rights to use, copy, modify, merge, publish,
146
+ distribute, sublicense, and/or sell copies of the Software, and to
147
+ permit persons to whom the Software is furnished to do so, subject to
148
+ the following conditions:
149
+
150
+ The above copyright notice and this permission notice shall be
151
+ included in all copies or substantial portions of the Software.
150
152
 
151
- Enjoy.
153
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
154
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
155
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
156
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
157
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
158
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
159
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
152
160
 
153
- Nate Sutton (nate@sevenwire.com)
161
+ On that note, have fun!
@@ -9,12 +9,13 @@ require 'forgery/file_writer'
9
9
  require 'forgery/dictionaries'
10
10
  require 'forgery/formats'
11
11
 
12
- # Loading class extensions
12
+ # Loading extensions
13
+ require 'forgery/extend'
13
14
  Dir[current_path + 'forgery/extensions/**/*.rb'].uniq.each do |file|
14
15
  require file
15
16
  end
16
17
 
17
- # Load the forgery base class
18
+ # Load the forgery base classes
18
19
  require 'forgery/forgery'
19
20
 
20
21
  # Load the forgery version
@@ -8,7 +8,7 @@ class Forgery
8
8
 
9
9
  def [](key)
10
10
  symbolized_key = key.to_sym
11
- @dictionaries[symbolized_key] ||= FileReader.read_dictionary(symbolized_key)
11
+ @dictionaries[symbolized_key] ||= Forgery::Extend(FileReader.read_dictionary(symbolized_key))
12
12
  end
13
13
 
14
14
  def loaded?(key)
@@ -0,0 +1,16 @@
1
+ class Forgery
2
+ def self.Extend(object)
3
+ case object
4
+ when Array
5
+ Forgery::Extensions::Array.new(object)
6
+ when Hash
7
+ Forgery::Extensions::Hash.new(object)
8
+ when Range
9
+ Forgery::Extensions::Range.new(object.first, object.last, object.exclude_end?)
10
+ when String
11
+ Forgery::Extensions::String.new(object)
12
+ else
13
+ object
14
+ end
15
+ end
16
+ end
@@ -1,11 +1,22 @@
1
- class Array
2
- def random
3
- self[Kernel.rand(size)]
4
- end
1
+ class Forgery
2
+ module Extensions
3
+ class Array < ::Array
4
+
5
+ def unextend
6
+ to_a
7
+ end
8
+
9
+ # The only forgery extension that returns an extended object
10
+ def random
11
+ Forgery::Extend(self[Kernel.rand(size)])
12
+ end
13
+
14
+ def random_subset(len=2)
15
+ rs = []
16
+ len.times { rs << random }
17
+ rs
18
+ end
5
19
 
6
- def random_subset(len=2)
7
- rs = []
8
- len.times { rs << random }
9
- rs
20
+ end
10
21
  end
11
22
  end
@@ -1,9 +1,19 @@
1
- class Range
2
- def random
3
- Integer(first) && Integer(last)
4
- raise ArgumentError if first > last
5
- Kernel.rand(last - first + (exclude_end? ? 0 : 1)) + first
6
- rescue ArgumentError
7
- to_a.random
1
+ class Forgery
2
+ module Extensions
3
+ class Range < ::Range
4
+
5
+ def unextend
6
+ ::Range.new(first, last, exclude_end?)
7
+ end
8
+
9
+ def random
10
+ Integer(first) && Integer(last)
11
+ raise ArgumentError if first > last
12
+ Kernel.rand(last - first + (exclude_end? ? 0 : 1)) + first
13
+ rescue ArgumentError
14
+ Forgery::Extend(to_a).random
15
+ end
16
+
17
+ end
8
18
  end
9
19
  end
@@ -1,49 +1,49 @@
1
- class String
2
- def to_numbers(replace='#')
3
- gsub(/#{replace}/){ Kernel.rand(10) }
4
- end
1
+ class Forgery
2
+ module Extensions
3
+ class String < ::String
5
4
 
6
- # Ripped right out of rails
7
- if !defined?(Rails.root)
8
- def camelize(first_letter = :upper)
9
- case first_letter
10
- when :upper
11
- to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
12
- when :lower
13
- first.downcase + camelize(self)[1..-1]
5
+ def unextend
6
+ to_s
14
7
  end
15
- end
16
8
 
17
- def underscore
18
- to_s.gsub(/::/, '/').
19
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
20
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
21
- tr("-", "_").
22
- downcase
23
- end
24
-
25
- if Module.method(:const_get).arity == 1
26
- def constantize
27
- names = self.split('::')
28
- names.shift if names.empty? || names.first.empty?
9
+ def to_numbers(replace='#')
10
+ gsub(/#{replace}/){ Kernel.rand(10) }
11
+ end
29
12
 
30
- constant = Object
31
- names.each do |name|
32
- constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
13
+ # Ripped right out of rails
14
+ def camelize(first_letter = :upper)
15
+ case first_letter
16
+ when :upper
17
+ to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
18
+ when :lower
19
+ first.downcase + camelize(self)[1..-1]
33
20
  end
34
- constant
35
21
  end
36
- else
37
- def constantize
38
- names = self.split('::')
39
- names.shift if names.empty? || names.first.empty?
40
22
 
41
- constant = Object
42
- names.each do |name|
43
- constant = constant.const_get(name, false) || constant.const_missing(name)
23
+ if Module.method(:const_get).arity == 1
24
+ def constantize
25
+ names = self.split('::')
26
+ names.shift if names.empty? || names.first.empty?
27
+
28
+ constant = Object
29
+ names.each do |name|
30
+ constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
31
+ end
32
+ constant
33
+ end
34
+ else
35
+ def constantize
36
+ names = self.split('::')
37
+ names.shift if names.empty? || names.first.empty?
38
+
39
+ constant = Object
40
+ names.each do |name|
41
+ constant = constant.const_get(name, false) || constant.const_missing(name)
42
+ end
43
+ constant
44
44
  end
45
- constant
46
45
  end
46
+
47
47
  end
48
48
  end
49
49
  end
@@ -9,7 +9,7 @@ class Forgery::Address < Forgery
9
9
  # Forgery(:address).street_name
10
10
  # # => "Fordem"
11
11
  def self.street_name
12
- dictionaries[:streets].random
12
+ dictionaries[:streets].random.unextend
13
13
  end
14
14
 
15
15
  # Gets one of the formats from 'street_number_formats' and converts it to
@@ -32,7 +32,7 @@ class Forgery::Address < Forgery
32
32
  # Forgery(:address).street_suffix
33
33
  # # => "Parkway"
34
34
  def self.street_suffix
35
- dictionaries[:street_suffixes].random
35
+ dictionaries[:street_suffixes].random.unextend
36
36
  end
37
37
 
38
38
  # Gets a full street address, including street number, street name, and
@@ -55,7 +55,7 @@ class Forgery::Address < Forgery
55
55
  # Forgery(:address).city
56
56
  # # => "Sacramento"
57
57
  def self.city
58
- dictionaries[:cities].random
58
+ dictionaries[:cities].random.unextend
59
59
  end
60
60
 
61
61
  # Gets a random state out of the 'states' dictionary.
@@ -66,7 +66,7 @@ class Forgery::Address < Forgery
66
66
  # Forgery(:address).state
67
67
  # # => "Minnesota"
68
68
  def self.state
69
- dictionaries[:states].random
69
+ dictionaries[:states].random.unextend
70
70
  end
71
71
 
72
72
  # Gets a random state abbreviation out of the 'state_abbrev' dictionary.
@@ -77,7 +77,7 @@ class Forgery::Address < Forgery
77
77
  # Forgery(:address).state_abbrev
78
78
  # # => "TX"
79
79
  def self.state_abbrev
80
- dictionaries[:state_abbrevs].random
80
+ dictionaries[:state_abbrevs].random.unextend
81
81
  end
82
82
 
83
83
  # Gets a random Canadian province or territory out of the 'provinces' dictionary.
@@ -88,7 +88,7 @@ class Forgery::Address < Forgery
88
88
  # Forgery(:address).province
89
89
  # # => "Northwest Territories"
90
90
  def self.province
91
- dictionaries[:provinces].random
91
+ dictionaries[:provinces].random.unextend
92
92
  end
93
93
 
94
94
  # Gets a random Canadian province or territory abbreviation out of the 'province_abbrev' dictionary.
@@ -99,7 +99,7 @@ class Forgery::Address < Forgery
99
99
  # Forgery(:address).province_abbrev
100
100
  # # => "NT"
101
101
  def self.province_abbrev
102
- dictionaries[:province_abbrevs].random
102
+ dictionaries[:province_abbrevs].random.unextend
103
103
  end
104
104
 
105
105
  # Gets one of the formats from 'zip_formats' and converts it to numbers.
@@ -132,7 +132,7 @@ class Forgery::Address < Forgery
132
132
  # Forgery(:address).country
133
133
  # # => "Romania"
134
134
  def self.country
135
- dictionaries[:countries].random
135
+ dictionaries[:countries].random.unextend
136
136
  end
137
137
 
138
138
 
@@ -144,7 +144,7 @@ class Forgery::Address < Forgery
144
144
  # Forgery(:address).continent
145
145
  # # => "Europe"
146
146
  def self.continent
147
- dictionaries[:continents].random
147
+ dictionaries[:continents].random.unextend
148
148
  end
149
149
 
150
150
  end
@@ -2,12 +2,12 @@ require 'digest/sha1'
2
2
 
3
3
  class Forgery::Basic < Forgery
4
4
 
5
- HEX_DIGITS = %w{0 1 2 3 4 5 6 7 8 9 a b c d e f}
6
- UPPER_ALPHA = ('A'..'Z').to_a
7
- LOWER_ALPHA = ('a'..'z').to_a
8
- NUMERIC = ('0'..'9').to_a
9
- SPECIAL_CHARACTERS = %w{! ' @ # $ % ^ & * ( ) _ + - = [ ] { } ; : " , . / ?}
10
- BOOLEAN = [true, false]
5
+ HEX_DIGITS = Forgery::Extend(%w{0 1 2 3 4 5 6 7 8 9 a b c d e f})
6
+ UPPER_ALPHA = Forgery::Extend(('A'..'Z').to_a)
7
+ LOWER_ALPHA = Forgery::Extend(('a'..'z').to_a)
8
+ NUMERIC = Forgery::Extend(('0'..'9').to_a)
9
+ SPECIAL_CHARACTERS = Forgery::Extend(%w{! ' @ # $ % ^ & * ( ) _ + - = [ ] { } ; : " , . / ?})
10
+ BOOLEAN = Forgery::Extend([true, false])
11
11
 
12
12
  # Gets a random string for use as a password
13
13
  #
@@ -66,11 +66,11 @@ class Forgery::Basic < Forgery
66
66
  end
67
67
 
68
68
  def self.color
69
- dictionaries[:colors].random
69
+ dictionaries[:colors].random.unextend
70
70
  end
71
71
 
72
72
  def self.hex_color
73
- hex_digits = (1..6).collect { HEX_DIGITS.random}
73
+ hex_digits = (1..6).collect { HEX_DIGITS.random.unextend}
74
74
  "##{hex_digits.join}"
75
75
  end
76
76
 
@@ -82,7 +82,7 @@ class Forgery::Basic < Forgery
82
82
  options = {:at_least => 1,
83
83
  :at_most => 10}.merge(options)
84
84
 
85
- (options[:at_least]..options[:at_most]).random
85
+ Forgery::Extend((options[:at_least]..options[:at_most])).random
86
86
  end
87
87
 
88
88
  def self.text(options={})
@@ -99,14 +99,14 @@ class Forgery::Basic < Forgery
99
99
  allowed_characters += UPPER_ALPHA if options[:allow_upper]
100
100
  allowed_characters += NUMERIC if options[:allow_numeric]
101
101
  allowed_characters += SPECIAL_CHARACTERS if options[:allow_special]
102
-
103
- length = options[:exactly] || (options[:at_least]..options[:at_most]).random
104
102
 
105
- allowed_characters.random_subset(length).join
103
+ length = options[:exactly] || Forgery::Extend((options[:at_least]..options[:at_most])).random
104
+
105
+ Forgery::Extend(allowed_characters).random_subset(length).join
106
106
  end
107
107
 
108
108
  def self.frequency
109
- dictionaries[:frequencies].random
109
+ dictionaries[:frequencies].random.unextend
110
110
  end
111
111
 
112
112
  end
@@ -5,7 +5,7 @@ class Forgery::Currency < Forgery
5
5
  # Forgery(:currency).description
6
6
  # # => "Australian Dollars"
7
7
  def self.description
8
- dictionaries[:currency_descriptions].random
8
+ dictionaries[:currency_descriptions].random.unextend
9
9
  end
10
10
 
11
11
  # Generates a random currency code for a country
@@ -13,7 +13,7 @@ class Forgery::Currency < Forgery
13
13
  # Forgery(:currency).code
14
14
  # # => "AUD"
15
15
  def self.code
16
- dictionaries[:currency_codes].random
16
+ dictionaries[:currency_codes].random.unextend
17
17
  end
18
18
 
19
19
  end
@@ -1,38 +1,38 @@
1
1
  require 'date'
2
2
 
3
3
  class Forgery::Date < Forgery
4
- DAYS = %w{Sunday Monday Tuesday Wednesday Thursday Friday Saturday}
5
- DAYS_ABBR = %w{Sun Mon Tue Wed Thu Fri Sat}
6
- MONTHS = %w{January February March April May June July August September October November December}
7
- MONTHS_ABBR = %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
4
+ DAYS = Forgery::Extend(%w{Sunday Monday Tuesday Wednesday Thursday Friday Saturday})
5
+ DAYS_ABBR = Forgery::Extend(%w{Sun Mon Tue Wed Thu Fri Sat})
6
+ MONTHS = Forgery::Extend(%w{January February March April May June July August September October November December})
7
+ MONTHS_ABBR = Forgery::Extend(%w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))
8
8
 
9
9
  def self.day_of_week(options={})
10
- options.reverse_merge!(:abbr => false)
10
+ options = {:abbr => false}.merge(options)
11
11
 
12
12
  if (options[:abbr])
13
- DAYS_ABBR.random
13
+ DAYS_ABBR.random.unextend
14
14
  else
15
- DAYS.random
15
+ DAYS.random.unextend
16
16
  end
17
17
  end
18
18
 
19
19
  def self.month(options={})
20
- options.reverse_merge!(:abbr => false, :numerical => false)
20
+ options = {:abbr => false, :numerical => false}.merge(options)
21
21
 
22
22
  if (options[:numerical])
23
23
  1 + rand(12)
24
24
  else
25
25
  if (options[:abbr])
26
- MONTHS_ABBR.random
26
+ MONTHS_ABBR.random.unextend
27
27
  else
28
- MONTHS.random
28
+ MONTHS.random.unextend
29
29
  end
30
30
  end
31
31
 
32
32
  end
33
33
 
34
34
  def self.year(options={})
35
- options.reverse_merge!(:future => false, :past => false, :min_delta => 0, :max_delta => 20)
35
+ options = {:future => false, :past => false, :min_delta => 0, :max_delta => 20}.merge(options)
36
36
 
37
37
  #Apply our delta to this year
38
38
  DateTime.now.year + delta(options)
@@ -43,7 +43,7 @@ class Forgery::Date < Forgery
43
43
  end
44
44
 
45
45
  def self.date(options={})
46
- options.reverse_merge!(:future => false, :past => false, :min_delta => 0, :max_delta => 7300)
46
+ options = {:future => false, :past => false, :min_delta => 0, :max_delta => 7300}.merge(options)
47
47
 
48
48
  #Apply our delta to today
49
49
  ::Date.today + delta(options)
@@ -5,7 +5,7 @@ class Forgery::Internet < Forgery
5
5
  end
6
6
 
7
7
  def self.top_level_domain
8
- dictionaries[:top_level_domains].random
8
+ dictionaries[:top_level_domains].random.unextend
9
9
  end
10
10
 
11
11
  def self.domain_name
@@ -21,7 +21,7 @@ class Forgery::Internet < Forgery
21
21
  end
22
22
 
23
23
  def self.cctld
24
- dictionaries[:country_code_top_level_domains].random
24
+ dictionaries[:country_code_top_level_domains].random.unextend
25
25
  end
26
26
 
27
27
  def self.ip_v4
@@ -58,12 +58,13 @@ class Forgery::LoremIpsum < Forgery
58
58
  end
59
59
 
60
60
  def self.paragraphs(quantity=2, options={})
61
- options.reverse_merge!(:separator => "\n\n",
61
+ default_options = {:separator => "\n\n",
62
62
  :wrap => {
63
63
  :start => "",
64
64
  :end => "" },
65
65
  :html => false,
66
- :sentences => 3)
66
+ :sentences => 3}
67
+ options = default_options.merge(options)
67
68
  options.merge!(:random_limit => (dictionaries[:lorem_ipsum].length/options[:sentences])-quantity) if quantity.is_a?(Fixnum)
68
69
 
69
70
  if options[:html]
@@ -1,11 +1,11 @@
1
1
  class Forgery::Name < Forgery
2
2
 
3
3
  def self.last_name
4
- dictionaries[:last_names].random
4
+ dictionaries[:last_names].random.unextend
5
5
  end
6
6
 
7
7
  def self.first_name
8
- [dictionaries[:male_first_names], dictionaries[:female_first_names]].random.random
8
+ [dictionaries[:male_first_names], dictionaries[:female_first_names]].random.random.unextend
9
9
  end
10
10
 
11
11
  def self.full_name
@@ -13,38 +13,38 @@ class Forgery::Name < Forgery
13
13
  end
14
14
 
15
15
  def self.male_first_name
16
- dictionaries[:male_first_names].random
16
+ dictionaries[:male_first_names].random.unextend
17
17
  end
18
18
 
19
19
  def self.female_first_name
20
- dictionaries[:female_first_names].random
20
+ dictionaries[:female_first_names].random.unextend
21
21
  end
22
22
 
23
23
  def self.company_name
24
- dictionaries[:company_names].random
24
+ dictionaries[:company_names].random.unextend
25
25
  end
26
26
 
27
27
  def self.job_title
28
- dictionaries[:job_titles].random.sub('#{N}', self.job_title_suffix)
28
+ dictionaries[:job_titles].random.sub('#{N}', self.job_title_suffix).unextend
29
29
  end
30
30
 
31
31
  def self.job_title_suffix
32
- dictionaries[:job_title_suffixes].random
32
+ dictionaries[:job_title_suffixes].random.unextend
33
33
  end
34
34
 
35
35
  def self.title
36
- dictionaries[:name_titles].random
36
+ dictionaries[:name_titles].random.unextend
37
37
  end
38
38
 
39
39
  def self.suffix
40
- dictionaries[:name_suffixes].random
40
+ dictionaries[:name_suffixes].random.unextend
41
41
  end
42
42
 
43
43
  def self.location
44
- dictionaries[:locations].random
44
+ dictionaries[:locations].random.unextend
45
45
  end
46
46
 
47
47
  def self.industry
48
- dictionaries[:industries].random
48
+ dictionaries[:industries].random.unextend
49
49
  end
50
50
  end
@@ -1,7 +1,7 @@
1
1
  class Forgery::Personal < Forgery
2
2
 
3
3
  def self.gender
4
- dictionaries[:genders].random
4
+ dictionaries[:genders].random.unextend
5
5
  end
6
6
 
7
7
  def self.abbreviated_gender
@@ -9,15 +9,15 @@ class Forgery::Personal < Forgery
9
9
  end
10
10
 
11
11
  def self.shirt_size
12
- dictionaries[:shirt_sizes].random
12
+ dictionaries[:shirt_sizes].random.unextend
13
13
  end
14
14
 
15
15
  def self.race
16
- dictionaries[:races].random
16
+ dictionaries[:races].random.unextend
17
17
  end
18
18
 
19
19
  def self.language
20
- dictionaries[:languages].random
20
+ dictionaries[:languages].random.unextend
21
21
  end
22
22
 
23
23
  end
@@ -6,7 +6,7 @@ class Forgery::Time < Forgery
6
6
  # Forgery(:timezone).timezone
7
7
  # # => "Sydney"
8
8
  def self.zone
9
- dictionaries[:zones].random
9
+ dictionaries[:zones].random.unextend
10
10
  end
11
11
 
12
12
  end
@@ -1,6 +1,6 @@
1
1
  # Alternate Forgery api, see spec/forgery_spec.rb for examples.
2
2
  def Forgery(forgery, method=nil, *args)
3
- klass = "Forgery::#{forgery.to_s.camelize}".constantize
3
+ klass = Forgery::Extend("Forgery::#{Forgery::Extend(forgery.to_s).camelize}").constantize
4
4
  if method
5
5
  klass.send(method, *args)
6
6
  else
@@ -8,7 +8,7 @@ class Forgery
8
8
 
9
9
  def [](key)
10
10
  symbolized_key = key.to_sym
11
- @formats[symbolized_key] ||= FileReader.read_format(symbolized_key)
11
+ @formats[symbolized_key] ||= Forgery::Extend(FileReader.read_format(symbolized_key))
12
12
  end
13
13
 
14
14
  def loaded?(key)
@@ -1,3 +1,3 @@
1
1
  class Forgery
2
- VERSION = "0.3.12"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forgery
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 12
10
- version: 0.3.12
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nathan Sutton
@@ -16,8 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-07-18 00:00:00 -07:00
20
- default_executable:
19
+ date: 2011-09-04 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
22
  name: nokogiri
@@ -93,8 +92,8 @@ files:
93
92
  - lib/forgery/dictionaries/top_level_domains
94
93
  - lib/forgery/dictionaries/zones
95
94
  - lib/forgery/dictionaries.rb
95
+ - lib/forgery/extend.rb
96
96
  - lib/forgery/extensions/array.rb
97
- - lib/forgery/extensions/hash.rb
98
97
  - lib/forgery/extensions/range.rb
99
98
  - lib/forgery/extensions/string.rb
100
99
  - lib/forgery/file_reader.rb
@@ -123,7 +122,6 @@ files:
123
122
  - LICENSE
124
123
  - README.markdown
125
124
  - Rakefile
126
- has_rdoc: true
127
125
  homepage: http://github.com/sevenwire/forgery
128
126
  licenses: []
129
127
 
@@ -153,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
151
  requirements: []
154
152
 
155
153
  rubyforge_project: forgery
156
- rubygems_version: 1.5.0
154
+ rubygems_version: 1.8.7
157
155
  signing_key:
158
156
  specification_version: 3
159
157
  summary: Easy and customizable generation of forged data.
@@ -1,12 +0,0 @@
1
- class Hash
2
- # Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second.
3
- def reverse_merge(other_hash)
4
- other_hash.merge(self)
5
- end
6
-
7
- # Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second.
8
- # Modifies the receiver in place.
9
- def reverse_merge!(other_hash)
10
- replace(reverse_merge(other_hash))
11
- end
12
- end