forgery 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,6 +46,7 @@ In a rails project this generator creates:
46
46
  You can then use these directories to write your own dictionaries, class
47
47
  extensions, forgeries, and formats.
48
48
 
49
+
49
50
  Forgery will first look here for dictionaries and formats, so you can override
50
51
  the ones used in the plugin.
51
52
 
@@ -54,6 +55,19 @@ See the forgeries in the plugin for examples of how to write your own.
54
55
  See which dictionaries each forgery uses to override them with your own.
55
56
 
56
57
 
58
+ The Rails 3 plugin also registers a rake task which can generate new dictionaries
59
+ from html or xml on the web.
60
+
61
+ Writes to '${RAILS_ROOT}/lib/forgery/dictionaries' by default
62
+ (this can be overriden by setting Forgery::FileWriter#write_to!)
63
+
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
68
+
69
+ Usage:
70
+ rake create_dictionary[name_of_file,'http://www.html_or_xml_page.com','li']
57
71
  ## Examples
58
72
 
59
73
  Here I'll supply a few examples of how it works, in general. See each forgery
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rake'
2
2
  require 'rake/rdoctask'
3
3
  require 'spec/rake/spectask'
4
+ require File.expand_path('./lib/forgery/file_writer')
4
5
 
5
6
  begin
6
7
  require 'sdoc_helpers'
@@ -8,7 +9,6 @@ rescue LoadError
8
9
  puts "sdoc support not enabled. Please gem install sdoc-helpers."
9
10
  end
10
11
 
11
-
12
12
  desc 'Default: run specs with rcov.'
13
13
  task :default => :rcov_spec
14
14
 
@@ -33,3 +33,25 @@ Rake::RDocTask.new do |t|
33
33
  t.options << '--all'
34
34
  t.options << '--line-numbers'
35
35
  end
36
+
37
+ desc %q{
38
+ Create a dictionary file from web content (xml or html).
39
+ Writes to the directory specified by Forgery::FileWriter#write_to!
40
+ '${GEM_HOME}/lib/forgery/dictionaries' by default (standalone)
41
+ '${RAILS_ROOT}/lib/forgery/dictionaries' by default (as a Rails 3 plugin)
42
+
43
+ Parameters:
44
+ :dictionary_name -- the name of your new dictionary file
45
+ :source_url -- web page containing the data for your dictionary file
46
+ :css_or_xpath -- css or xpath selector(s) to element(s) containing the desired data
47
+
48
+ Usage:
49
+ rake create_dictionary[name_of_file,'http://www.html_or_xml_page.com','li']
50
+ }
51
+ task :create_dictionary, :dictionary_name, :source_url, :css_or_xpath do |t, args|
52
+ dictionary_name = args[:dictionary_name].to_s || raise("parameter :dictionary_name is required")
53
+ source_url = args[:source_url].to_s || raise("parameter :source_url is required")
54
+ css_or_xpath = args[:css_or_xpath].to_s || raise("parameter :css_or_xpath is required")
55
+
56
+ Forgery::FileWriter.create_dictionary dictionary_name, source_url, css_or_xpath
57
+ end
@@ -5,6 +5,7 @@ current_path = File.expand_path(File.dirname(__FILE__)) + '/'
5
5
 
6
6
  # Loading forgery helpers.
7
7
  require 'forgery/file_reader'
8
+ require 'forgery/file_writer'
8
9
  require 'forgery/dictionaries'
9
10
  require 'forgery/formats'
10
11
 
@@ -30,6 +31,5 @@ end
30
31
  # Loading rails forgeries to override current forgery methods and add new forgeries
31
32
  # Only run this for Rails < 3.0 since we need to use a Railtie to initialize >= 3.0
32
33
  Forgery.load_from! "#{Forgery.rails_root}/lib/forgery" if Forgery.rails? && Rails::VERSION::STRING < "3.0.0"
33
-
34
34
  # Include our Railtie if Rails >= 3.0.0
35
35
  require 'forgery/forgery_railtie' if Forgery.rails? && Rails::VERSION::STRING >= "3.0.0"
@@ -0,0 +1,130 @@
1
+ EUR
2
+ USD
3
+ GBP
4
+ CAD
5
+ AUD
6
+ JPY
7
+ INR
8
+ NZD
9
+ CHF
10
+ ZAR
11
+ EUR
12
+ AFN
13
+ ALL
14
+ DZD
15
+ USD
16
+ ARS
17
+ AUD
18
+ ATS
19
+ BSD
20
+ BHD
21
+ BDT
22
+ BBD
23
+ BEF
24
+ BMD
25
+ BRL
26
+ BGN
27
+ CAD
28
+ XOF
29
+ XAF
30
+ CLP
31
+ CNY
32
+ CNY
33
+ COP
34
+ XPF
35
+ CRC
36
+ HRK
37
+ CYP
38
+ CZK
39
+ DKK
40
+ DEM
41
+ DOP
42
+ NLG
43
+ XCD
44
+ EGP
45
+ EEK
46
+ EUR
47
+ FJD
48
+ FIM
49
+ FRF
50
+ DEM
51
+ XAU
52
+ GRD
53
+ NLG
54
+ HKD
55
+ HUF
56
+ ISK
57
+ XDR
58
+ INR
59
+ IDR
60
+ IRR
61
+ IQD
62
+ IEP
63
+ ILS
64
+ ITL
65
+ JMD
66
+ JPY
67
+ JOD
68
+ KES
69
+ KRW
70
+ KWD
71
+ LBP
72
+ LUF
73
+ MYR
74
+ MTL
75
+ MUR
76
+ MXN
77
+ MAD
78
+ NLG
79
+ NZD
80
+ NOK
81
+ OMR
82
+ PKR
83
+ XPD
84
+ PEN
85
+ PHP
86
+ XPT
87
+ PLN
88
+ PTE
89
+ QAR
90
+ RON
91
+ ROL
92
+ RUB
93
+ SAR
94
+ XAG
95
+ SGD
96
+ SKK
97
+ SIT
98
+ ZAR
99
+ KRW
100
+ ESP
101
+ XDR
102
+ LKR
103
+ SDG
104
+ SEK
105
+ CHF
106
+ TWD
107
+ THB
108
+ TTD
109
+ TND
110
+ TRY
111
+ AED
112
+ GBP
113
+ USD
114
+ VEB
115
+ VEF
116
+ VND
117
+ ZMK
118
+ EUR
119
+ XAF
120
+ XOF
121
+ XPF
122
+ XCD
123
+ EUR
124
+ XDR
125
+ XAU
126
+ XAG
127
+ XAU
128
+ XPT
129
+ XPD
130
+ EUR
@@ -0,0 +1,106 @@
1
+ Afghanistan Afghanis
2
+ Albania Leke
3
+ Algeria Dinars
4
+ America (United States) Dollars
5
+ Argentina Pesos
6
+ Australia Dollars
7
+ Austria Schillings
8
+ Bahamas Dollars
9
+ Bahrain Dinars
10
+ Bangladesh Taka
11
+ Barbados Dollars
12
+ Belgium Francs
13
+ Bermuda Dollars
14
+ Brazil Reais
15
+ Bulgaria Leva
16
+ Canada Dollars
17
+ CFA BCEAO Francs
18
+ CFA BEAC Francs
19
+ Chile Pesos
20
+ China Yuan Renminbi
21
+ RMB (China Yuan Renminbi)
22
+ Colombia Pesos
23
+ CFP Francs
24
+ Costa Rica Colones
25
+ Croatia Kuna
26
+ Cyprus Pounds
27
+ Czech Republic Koruny
28
+ Denmark Kroner
29
+ Deutsche (Germany) Marks
30
+ Dominican Republic Pesos
31
+ Dutch (Netherlands) Guilders
32
+ Eastern Caribbean Dollars
33
+ Egypt Pounds
34
+ Estonia Krooni
35
+ Euros
36
+ Fiji Dollars
37
+ Finland Markkaa
38
+ France Francs
39
+ Germany Deutsche Marks
40
+ Gold Ounces
41
+ Greece Drachmae
42
+ Holland (Netherlands) Guilders
43
+ Hong Kong Dollars
44
+ Hungary Forint
45
+ Iceland Kronur
46
+ IMF Special Drawing Right
47
+ India Rupees
48
+ Indonesia Rupiahs
49
+ Iran Rials
50
+ Iraq Dinars
51
+ Ireland Pounds
52
+ Israel New Shekels
53
+ Italy Lire
54
+ Jamaica Dollars
55
+ Japan Yen
56
+ Jordan Dinars
57
+ Kenya Shillings
58
+ Korea (South) Won
59
+ Kuwait Dinars
60
+ Lebanon Pounds
61
+ Luxembourg Francs
62
+ Malaysia Ringgits
63
+ Malta Liri
64
+ Mauritius Rupees
65
+ Mexico Pesos
66
+ Morocco Dirhams
67
+ Netherlands Guilders
68
+ New Zealand Dollars
69
+ Norway Kroner
70
+ Oman Rials
71
+ Pakistan Rupees
72
+ Palladium Ounces
73
+ Peru Nuevos Soles
74
+ Philippines Pesos
75
+ Platinum Ounces
76
+ Poland Zlotych
77
+ Portugal Escudos
78
+ Qatar Riyals
79
+ Romania New Lei
80
+ Romania Lei
81
+ Russia Rubles
82
+ Saudi Arabia Riyals
83
+ Silver Ounces
84
+ Singapore Dollars
85
+ Slovakia Koruny
86
+ Slovenia Tolars
87
+ South Africa Rand
88
+ South Korea Won
89
+ Spain Pesetas
90
+ Special Drawing Rights (IMF)
91
+ Sri Lanka Rupees
92
+ Sudan Pounds
93
+ Sweden Kronor
94
+ Switzerland Francs
95
+ Taiwan New Dollars
96
+ Thailand Baht
97
+ Trinidad and Tobago Dollars
98
+ Tunisia Dinars
99
+ Turkey Lira
100
+ United Arab Emirates Dirhams
101
+ United Kingdom Pounds
102
+ United States Dollars
103
+ Venezuela Bolivares
104
+ Venezuela Bolivares Fuertes
105
+ Vietnam Dong
106
+ Zambia Kwacha
@@ -2,7 +2,7 @@ class Range
2
2
  def random
3
3
  Integer(first) && Integer(last)
4
4
  raise ArgumentError if first > last
5
- Kernel.rand(last - first + 1) + first
5
+ Kernel.rand(last - first + (exclude_end? ? 0 : 1)) + first
6
6
  rescue ArgumentError
7
7
  to_a.random
8
8
  end
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ class Forgery
5
+
6
+ class FileWriter
7
+
8
+ # Creates a dictionary file with data from a web page
9
+ def self.create_dictionary(dictionary_name, source_url, *css_or_xpath)
10
+ doc = open_page(source_url)
11
+ lines = []
12
+ doc.search(*css_or_xpath).each do |node|
13
+ lines << node.content
14
+ end
15
+ raise empty_msg if lines.empty?
16
+ create_file(dictionary_name, lines)
17
+ end
18
+
19
+ # Path to which new dictionaries will be written
20
+ # '${GEM_HOME}/lib/forgery/dictionaries' by default
21
+ def self.write_path
22
+ @@write_path
23
+ end
24
+
25
+ # Sets path to which new dictionaries will be written
26
+ def self.write_to!(path)
27
+ @@write_path = File.expand_path path
28
+ end
29
+
30
+ private
31
+ # Creates file with a line for each item in the supplied array
32
+ def self.create_file(name, lines)
33
+ file_path = File.join(write_path, name)
34
+ File.open(file_path, "w") do |f|
35
+ lines.each do |line|
36
+ stripped_line = line.strip
37
+ f.puts stripped_line unless stripped_line.empty?
38
+ end
39
+ end
40
+ puts "Created file #{name} in #{write_path}"
41
+ file_path
42
+ end
43
+
44
+ # opens url and parses document
45
+ def self.open_page(url)
46
+ Nokogiri.parse(open url)
47
+ end
48
+
49
+ def self.empty_msg
50
+ msg = %q{No items found. Please double check your css or xpath selectors
51
+ and ensure that the site you are trying to reach does not block scripts. }
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,19 @@
1
+ class Forgery::Currency < Forgery
2
+
3
+ # Generates a random currency description
4
+ #
5
+ # Forgery(:currency).description
6
+ # # => "Australian Dollars"
7
+ def self.description
8
+ dictionaries[:currency_descriptions].random
9
+ end
10
+
11
+ # Generates a random currency code for a country
12
+ #
13
+ # Forgery(:currency).code
14
+ # # => "AUD"
15
+ def self.code
16
+ dictionaries[:currency_codes].random
17
+ end
18
+
19
+ end
@@ -5,4 +5,31 @@ class ForgeryRailtie < Rails::Railtie
5
5
  initializer "forgery_railtie.initialize" do
6
6
  Forgery.load_from! "#{Rails.root}/lib/forgery"
7
7
  end
8
+
9
+ rake_tasks do
10
+ namespace :forgery do
11
+ desc %q{
12
+ Create a dictionary file from web content (xml or html).
13
+ Writes to the directory specified by Forgery::FileWriter#write_to!
14
+ '${GEM_HOME}/lib/forgery/dictionaries' by default (standalone)
15
+ '${RAILS_ROOT}/lib/forgery/dictionaries' by default (as a Rails 3 plugin)
16
+
17
+ Parameters:
18
+ :dictionary_name -- the name of your new dictionary file
19
+ :source_url -- web page containing the data for your dictionary file
20
+ :css_or_xpath -- css or xpath selector(s) to element(s) containing the desired data
21
+
22
+ Usage:
23
+ rake forgery:create_dictionary[name_of_file,'http://www.html_or_xml_page.com','li']
24
+ }
25
+ task :create_dictionary, :dictionary_name, :source_url, :css_or_xpath do |t, args|
26
+ dictionary_name = args[:dictionary_name].to_s || raise("parameter :dictionary_name is required")
27
+ source_url = args[:source_url].to_s || raise("parameter :source_url is required")
28
+ css_or_xpath = args[:css_or_xpath].to_s || raise("parameter :css_or_xpath is required")
29
+
30
+ Forgery::FileWriter.write_to! "#{Rails.root}/lib/forgery/dictionaries"
31
+ Forgery::FileWriter.create_dictionary dictionary_name, source_url, css_or_xpath
32
+ end
33
+ end
34
+ end
8
35
  end
@@ -1,3 +1,3 @@
1
1
  class Forgery
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
3
3
  end
metadata CHANGED
@@ -1,36 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forgery
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 29
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 3
8
- - 6
9
- version: 0.3.6
9
+ - 7
10
+ version: 0.3.7
10
11
  platform: ruby
11
12
  authors:
12
13
  - Nathan Sutton
14
+ - Brandon Arbini
13
15
  autorequire:
14
16
  bindir: bin
15
17
  cert_chain: []
16
18
 
17
- date: 2010-10-22 00:00:00 -05:00
19
+ date: 2011-02-10 00:00:00 -06:00
18
20
  default_executable:
19
21
  dependencies:
20
22
  - !ruby/object:Gem::Dependency
21
- name: rspec
23
+ name: nokogiri
22
24
  prerelease: false
23
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 7
31
+ segments:
32
+ - 1
33
+ - 4
34
+ version: "1.4"
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
24
42
  requirements:
25
43
  - - ">="
26
44
  - !ruby/object:Gem::Version
45
+ hash: 3
27
46
  segments:
28
47
  - 0
29
48
  version: "0"
30
49
  type: :development
31
- version_requirements: *id001
50
+ version_requirements: *id002
32
51
  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.
33
- email: nate@sevenwire.com
52
+ email:
53
+ - nate@zencoder.com
54
+ - brandon@zencoder.com
34
55
  executables: []
35
56
 
36
57
  extensions: []
@@ -46,6 +67,8 @@ files:
46
67
  - lib/forgery/dictionaries/continents
47
68
  - lib/forgery/dictionaries/countries
48
69
  - lib/forgery/dictionaries/country_code_top_level_domains
70
+ - lib/forgery/dictionaries/currency_codes
71
+ - lib/forgery/dictionaries/currency_descriptions
49
72
  - lib/forgery/dictionaries/female_first_names
50
73
  - lib/forgery/dictionaries/frequencies
51
74
  - lib/forgery/dictionaries/genders
@@ -74,8 +97,10 @@ files:
74
97
  - lib/forgery/extensions/range.rb
75
98
  - lib/forgery/extensions/string.rb
76
99
  - lib/forgery/file_reader.rb
100
+ - lib/forgery/file_writer.rb
77
101
  - lib/forgery/forgery/address.rb
78
102
  - lib/forgery/forgery/basic.rb
103
+ - lib/forgery/forgery/currency.rb
79
104
  - lib/forgery/forgery/date.rb
80
105
  - lib/forgery/forgery/internet.rb
81
106
  - lib/forgery/forgery/lorem_ipsum.rb
@@ -106,23 +131,27 @@ rdoc_options: []
106
131
  require_paths:
107
132
  - lib
108
133
  required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
109
135
  requirements:
110
136
  - - ">="
111
137
  - !ruby/object:Gem::Version
138
+ hash: 3
112
139
  segments:
113
140
  - 0
114
141
  version: "0"
115
142
  required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
116
144
  requirements:
117
145
  - - ">="
118
146
  - !ruby/object:Gem::Version
147
+ hash: 3
119
148
  segments:
120
149
  - 0
121
150
  version: "0"
122
151
  requirements: []
123
152
 
124
153
  rubyforge_project: forgery
125
- rubygems_version: 1.3.6
154
+ rubygems_version: 1.3.7
126
155
  signing_key:
127
156
  specification_version: 3
128
157
  summary: Easy and customizable generation of forged data.