forgery 0.4.4 → 0.5.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.
data/Rakefile CHANGED
@@ -5,27 +5,3 @@ Bundler::GemHelper.install_tasks
5
5
  RSpec::Core::RakeTask.new
6
6
 
7
7
  task :default => :spec
8
-
9
- require File.expand_path('./lib/forgery/file_writer')
10
-
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 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.create_dictionary dictionary_name, source_url, css_or_xpath
31
- end
@@ -5,7 +5,6 @@ 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'
9
8
  require 'forgery/dictionaries'
10
9
  require 'forgery/formats'
11
10
 
@@ -48,7 +48,7 @@ class Forgery::CreditCard < Forgery
48
48
  number += check_digit(number)
49
49
  end
50
50
 
51
- private
51
+ private
52
52
 
53
53
  def self.check_digit(number)
54
54
  # for explanation, please see: http://www.darkcoding.net/credit-card/luhn-formula/
@@ -3,36 +3,7 @@ require 'rails'
3
3
  require 'rake'
4
4
 
5
5
  class ForgeryRailtie < Rails::Railtie
6
- extend Rake::DSL
7
-
8
6
  config.to_prepare do
9
7
  Forgery.load_from! "#{Rails.root}/lib/forgery"
10
8
  end
11
-
12
- rake_tasks do
13
- namespace :forgery do
14
- desc %q{
15
- Create a dictionary file from web content (xml or html).
16
- Writes to the directory specified by Forgery::FileWriter#write_to!
17
- '${GEM_HOME}/lib/forgery/dictionaries' by default (standalone)
18
- '${Rails.root}/lib/forgery/dictionaries' by default (as a Rails 3 plugin)
19
-
20
- Parameters:
21
- :dictionary_name -- the name of your new dictionary file
22
- :source_url -- web page containing the data for your dictionary file
23
- :css_or_xpath -- css or xpath selector(s) to element(s) containing the desired data
24
-
25
- Usage:
26
- rake forgery:create_dictionary[name_of_file,'http://www.html_or_xml_page.com','li']
27
- }
28
- task :create_dictionary, :dictionary_name, :source_url, :css_or_xpath do |t, args|
29
- dictionary_name = args[:dictionary_name].to_s || raise("parameter :dictionary_name is required")
30
- source_url = args[:source_url].to_s || raise("parameter :source_url is required")
31
- css_or_xpath = args[:css_or_xpath].to_s || raise("parameter :css_or_xpath is required")
32
-
33
- Forgery::FileWriter.write_to! "#{Rails.root}/lib/forgery/dictionaries"
34
- Forgery::FileWriter.create_dictionary dictionary_name, source_url, css_or_xpath
35
- end
36
- end
37
- end
38
9
  end
@@ -1,3 +1,3 @@
1
1
  class Forgery
2
- VERSION = "0.4.4"
2
+ VERSION = "0.5.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: 7
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 4
10
- version: 0.4.4
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nathan Sutton
@@ -18,25 +18,10 @@ cert_chain: []
18
18
 
19
19
  date: 2011-09-08 00:00:00 Z
20
20
  dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: nokogiri
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 1
32
- - 4
33
- version: "1.4"
34
- type: :runtime
35
- version_requirements: *id001
36
21
  - !ruby/object:Gem::Dependency
37
22
  name: rspec
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
40
25
  none: false
41
26
  requirements:
42
27
  - - ">="
@@ -46,7 +31,7 @@ dependencies:
46
31
  - 0
47
32
  version: "0"
48
33
  type: :development
49
- version_requirements: *id002
34
+ version_requirements: *id001
50
35
  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
36
  email:
52
37
  - nate@zencoder.com
@@ -97,7 +82,6 @@ files:
97
82
  - lib/forgery/extensions/range.rb
98
83
  - lib/forgery/extensions/string.rb
99
84
  - lib/forgery/file_reader.rb
100
- - lib/forgery/file_writer.rb
101
85
  - lib/forgery/forgery/address.rb
102
86
  - lib/forgery/forgery/basic.rb
103
87
  - lib/forgery/forgery/credit_card.rb
@@ -1,54 +0,0 @@
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}" unless ENV["TESTING_VIA_RSPEC"]
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