Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing up some whitespace

  • Loading branch information...
commit 5aad4640674c29fcf6ba99fe757d80f8cd7b0d9a 1 parent 4daae9b
@nate nate authored
View
25 README.markdown
@@ -33,7 +33,7 @@ plugin includes a generator providing directories to make your own forgeries.
## Rails 3 Generator
- rails generate forgery
+ rails generate forgery
In a rails project this generator creates:
@@ -77,24 +77,29 @@ for individual examples.
Forgery(:monetary).formatted_money # => "$3.48"
Forgery(:monetary).money :min => 100, :max => 1000 # => "923.36"
-##Customization
+## Customization
+
You can utilize the directories generated in /lib to customize the behavior of forgery.
+
Examples of each of these components are available in the source.
-###Dictionaries
+### Dictionaries
+
Dictionaries are files with no extensions. Entries are separated by new lines.
-###Forgeries
+### Forgeries
+
Forgeries are classes that inherit from the Forgery class. A basic forgery definition is as follows
- class NewForgery < Forgery
- end
+ class NewForgery < Forgery
+ end
+
+### Extensions
+
+Extensions are additional methods/functionality that are added to classes (Ruby core or otherwise) that are loaded by Forgery. Follow standard Ruby practices.
-###Extensions
-Extensions are additional methods/functionality that are added to classes (Ruby core or otherwise)
-that are loaded by Forgery. Follow standard Ruby practices.
+### Formats
-###Formats
Formatting for numerical fields. Each numerical entry corresponds to a # mark.
## DOCUMENTATION
View
2  lib/forgery.rb
@@ -31,5 +31,5 @@
# Only run this for Rails < 3.0 since we need to use a Railtie to initialize >= 3.0
Forgery.load_from! "#{Forgery.rails_root}/lib/forgery" if Forgery.rails? && Rails::VERSION::STRING < "3.0.0"
-#Include our Railtie if Rails >= 3.0.0
+# Include our Railtie if Rails >= 3.0.0
require 'forgery/forgery_railtie' if Forgery.rails? && Rails::VERSION::STRING >= "3.0.0"
View
28 lib/forgery/forgery/date.rb
@@ -5,20 +5,20 @@ class Forgery::Date < Forgery
DAYS_ABBR = %w{Sun Mon Tue Wed Thu Fri Sat}
MONTHS = %w{January February March April May June July August September October November December}
MONTHS_ABBR = %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
-
+
def self.day_of_week(options={})
options.reverse_merge!(:abbr => false)
-
+
if (options[:abbr])
DAYS_ABBR.random
else
DAYS.random
end
end
-
+
def self.month(options={})
options.reverse_merge!(:abbr => false, :numerical => false)
-
+
if (options[:numerical])
1 + rand(12)
else
@@ -28,43 +28,43 @@ def self.month(options={})
MONTHS.random
end
end
-
+
end
-
+
def self.year(options={})
options.reverse_merge!(:future => false, :min_delta => 0, :max_delta => 20)
-
+
#Calculate our delta
delta = options[:min_delta] + rand(options[:max_delta] + 1 - options[:min_delta]).to_i
-
+
#Potentially negate our delta if future is false
unless (options[:future])
if rand(2).zero?
delta *= -1
end
end
-
+
#Apply our delta to this year
DateTime.now.year + delta
end
-
+
def self.day
1 + rand(31)
end
-
+
def self.date(options={})
options.reverse_merge!(:future => false, :min_delta => 0, :max_delta => 7300)
-
+
#Calculate our delta
delta = options[:min_delta] + rand(options[:max_delta] + 1 - options[:min_delta]).to_i
-
+
#Potentially negate our delta if future is false
unless (options[:future])
if rand(2).zero?
delta *= -1
end
end
-
+
#Apply our delta to today
DateTime.now.to_date + delta
end
View
7 lib/forgery/forgery/name.rb
@@ -40,7 +40,8 @@ def self.suffix
dictionaries[:name_suffixes].random
end
- def self.location
- dictionaries[:locations].random
- end
+ def self.location
+ dictionaries[:locations].random
+ end
+
end
View
2  lib/forgery/forgery_railtie.rb
@@ -5,4 +5,4 @@ class ForgeryRailtie < Rails::Railtie
initializer "forgery_railtie.initialize" do
Forgery.load_from! "#{Rails.root}/lib/forgery"
end
-end
+end
View
30 lib/generators/forgery/forgery_generator.rb
@@ -1,18 +1,18 @@
require 'rails/generators/base'
class ForgeryGenerator < Rails::Generators::Base
- desc "Create the necessary directories in /lib to customize forgery's behavior"
-
- def self.source_root
- @_forgery_source_root ||= File.expand_path(File.dirname(__FILE__))
- end
-
- def create_directories
- puts "Creating directories in /lib/forgery..."
-
- FileUtils.mkdir_p 'lib/forgery/dictionaries'
- FileUtils.mkdir_p 'lib/forgery/extensions'
- FileUtils.mkdir_p 'lib/forgery/forgeries'
- FileUtils.mkdir_p 'lib/forgery/formats'
- end
-end
+ desc "Create the necessary directories in /lib to customize forgery's behavior"
+
+ def self.source_root
+ @_forgery_source_root ||= File.expand_path(File.dirname(__FILE__))
+ end
+
+ def create_directories
+ puts "Creating directories in /lib/forgery..."
+
+ FileUtils.mkdir_p 'lib/forgery/dictionaries'
+ FileUtils.mkdir_p 'lib/forgery/extensions'
+ FileUtils.mkdir_p 'lib/forgery/forgeries'
+ FileUtils.mkdir_p 'lib/forgery/formats'
+ end
+end
View
16 spec/forgery/date_spec.rb
@@ -7,31 +7,31 @@
Date::DAYNAMES.should include(Forgery::Date.day_of_week)
end
end
-
+
describe '.day_of_week(:abbr => true)' do
it 'should return a day of the week in abbreviated form' do
Date::ABBR_DAYNAMES.should include(Forgery::Date.day_of_week(:abbr => true))
end
end
-
+
describe '.month' do
it 'should return a valid month' do
Date::MONTHNAMES.should include(Forgery::Date.month)
end
end
-
+
describe '.month(:abbr => true)' do
it 'should return a valid month in abbreviated form' do
Date::ABBR_MONTHNAMES.should include(Forgery::Date.month(:abbr => true))
end
end
-
+
describe '.month(:numerical => true)' do
it 'should return a valid month in numeric form' do
[1,2,3,4,5,6,7,8,9,10,11,12].should include(Forgery::Date.month(:numerical => true))
end
end
-
+
describe '.year' do
it 'should return a valid year within 20 years of the current year' do
year = Forgery::Date.year
@@ -39,21 +39,21 @@
year.should < Date.today.year + 21
end
end
-
+
describe '.year(:future => true)' do
it 'should return a year greater than the current one' do
year = Forgery::Date.year(:future => true)
year.should >= Date.today.year
end
end
-
+
describe '.year(:min_delta => 5, :max_delta => 5, :future => true)' do
it 'should return a year 5 years from the current one' do
year = Forgery::Date.year(:min_delta => 5, :max_delta => 5, :future => true)
year.should >= Date.today.year + 5
end
end
-
+
describe '.year(:min_delta => 5, :max_delta => 10, :future => true)' do
it 'should return a year that is between 5 and 10 years greater than the current one' do
year = Forgery::Date.year(:min_delta => 5, :max_delta => 10, :future => true)
View
2  spec/forgery/internet_spec.rb
@@ -46,7 +46,7 @@
nums.each do |num|
num.should =~ /\d{1,3}/
num.to_i.should <= 255
- num.to_i.should >= 0
+ num.to_i.should >= 0
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.