fletcher 0.1.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/.document +5 -0
- data/.travis.yml +6 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +20 -0
- data/README.textile +40 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/fletcher.gemspec +83 -0
- data/index.html +1 -0
- data/lib/fletcher.rb +38 -0
- data/lib/fletcher/data.rb +12 -0
- data/lib/fletcher/item/amazon.rb +19 -0
- data/lib/fletcher/item/base.rb +23 -0
- data/spec/factories/item.rb +16 -0
- data/spec/lib/fletcher/data_spec.rb +20 -0
- data/spec/lib/fletcher/item/amazon_spec.rb +16 -0
- data/spec/lib/fletcher/item/base_spec.rb +14 -0
- data/spec/lib/fletcher_spec.rb +21 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/support/benchmark.rb +135 -0
- data/test/helper.rb +18 -0
- data/test/test_fletcher.rb +7 -0
- metadata +163 -0
data/.document
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.1.3)
|
5
|
+
multi_json (~> 1.0)
|
6
|
+
diff-lcs (1.1.3)
|
7
|
+
factory_girl (2.3.2)
|
8
|
+
activesupport
|
9
|
+
git (1.2.5)
|
10
|
+
hashie (1.2.0)
|
11
|
+
jeweler (1.6.4)
|
12
|
+
bundler (~> 1.0)
|
13
|
+
git (>= 1.2.5)
|
14
|
+
rake
|
15
|
+
multi_json (1.0.4)
|
16
|
+
nokogiri (1.5.0)
|
17
|
+
rake (0.9.2)
|
18
|
+
rcov (0.9.10)
|
19
|
+
rspec (2.7.0)
|
20
|
+
rspec-core (~> 2.7.0)
|
21
|
+
rspec-expectations (~> 2.7.0)
|
22
|
+
rspec-mocks (~> 2.7.0)
|
23
|
+
rspec-core (2.7.1)
|
24
|
+
rspec-expectations (2.7.0)
|
25
|
+
diff-lcs (~> 1.1.2)
|
26
|
+
rspec-mocks (2.7.0)
|
27
|
+
shoulda (2.11.3)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 1.0.0)
|
34
|
+
factory_girl
|
35
|
+
hashie
|
36
|
+
jeweler (~> 1.6.4)
|
37
|
+
nokogiri
|
38
|
+
rcov
|
39
|
+
rspec
|
40
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Dave Hulihan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
h1. Fletcher
|
2
|
+
|
3
|
+
Fletcher is a cross-website product/item information fetcher. Give fletcher producturl and you'll get back a nice, standardized object that's easy to work with.
|
4
|
+
|
5
|
+
h2. Features
|
6
|
+
|
7
|
+
* Uses nokogiri for data parsing
|
8
|
+
* No third-party API Access Required (Good for websites that don't even have API access)
|
9
|
+
|
10
|
+
h2. Supported Websites
|
11
|
+
|
12
|
+
* "Amazon":http://www.amazon.com
|
13
|
+
* "eBay":http://www.ebay.com (Coming Soon)
|
14
|
+
|
15
|
+
h2. Installation
|
16
|
+
|
17
|
+
```bash
|
18
|
+
gem install fletcher
|
19
|
+
```
|
20
|
+
|
21
|
+
h2. Examples
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
product = Fletcher.fetch("http://www.amazon.com/Avenir-Deluxe-Unicycle-20-Inch-Wheel/dp/B00165Q9F8")
|
25
|
+
|
26
|
+
product.name # => "Avenir Deluxe Unicycle (20-Inch Wheel)"
|
27
|
+
|
28
|
+
product.description # => "A wonderful unicycle"
|
29
|
+
|
30
|
+
product.images # => [{:url => "http://ecx.images-amazon.com/images/I/41b3TNb3uCL._SL500_AA300_.jpg", :alt => "Avenir Deluxe Unicycle (20-Inch Wheel)"}]
|
31
|
+
```
|
32
|
+
|
33
|
+
h2. Attributes
|
34
|
+
|
35
|
+
The following attributes are available from items:
|
36
|
+
|
37
|
+
* title - (String) The name of the item/product
|
38
|
+
* description - (String) The item/product description
|
39
|
+
* images - (Array) Any available images of the item
|
40
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "fletcher"
|
18
|
+
gem.homepage = "http://github.com/hulihanapplications/fletcher"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A cross-website product/item information fetcher.}
|
21
|
+
gem.description = %Q{Fletcher pulls product/item information from third party websites(such as Amazon, eBay, etc) and returns it in a standardized, usable object.}
|
22
|
+
gem.email = "dave@hulihanapplications.com"
|
23
|
+
gem.authors = ["Dave Hulihan", "Hulihan Applications"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "fletcher #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/fletcher.gemspec
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{fletcher}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Dave Hulihan", "Hulihan Applications"]
|
12
|
+
s.date = %q{2011-12-07}
|
13
|
+
s.description = %q{Fletcher pulls product/item information from third party websites(such as Amazon, eBay, etc) and returns it in a standardized, usable object.}
|
14
|
+
s.email = %q{dave@hulihanapplications.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.textile"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".travis.yml",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.textile",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"fletcher.gemspec",
|
29
|
+
"index.html",
|
30
|
+
"lib/fletcher.rb",
|
31
|
+
"lib/fletcher/data.rb",
|
32
|
+
"lib/fletcher/item/amazon.rb",
|
33
|
+
"lib/fletcher/item/base.rb",
|
34
|
+
"spec/factories/item.rb",
|
35
|
+
"spec/lib/fletcher/data_spec.rb",
|
36
|
+
"spec/lib/fletcher/item/amazon_spec.rb",
|
37
|
+
"spec/lib/fletcher/item/base_spec.rb",
|
38
|
+
"spec/lib/fletcher_spec.rb",
|
39
|
+
"spec/spec_helper.rb",
|
40
|
+
"spec/support/benchmark.rb",
|
41
|
+
"test/helper.rb",
|
42
|
+
"test/test_fletcher.rb"
|
43
|
+
]
|
44
|
+
s.homepage = %q{http://github.com/hulihanapplications/fletcher}
|
45
|
+
s.licenses = ["MIT"]
|
46
|
+
s.require_paths = ["lib"]
|
47
|
+
s.rubygems_version = %q{1.7.2}
|
48
|
+
s.summary = %q{A cross-website product/item information fetcher.}
|
49
|
+
|
50
|
+
if s.respond_to? :specification_version then
|
51
|
+
s.specification_version = 3
|
52
|
+
|
53
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
|
+
s.add_runtime_dependency(%q<hashie>, [">= 0"])
|
55
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
59
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<factory_girl>, [">= 0"])
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
64
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
65
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
66
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
67
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
68
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
69
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
70
|
+
s.add_dependency(%q<factory_girl>, [">= 0"])
|
71
|
+
end
|
72
|
+
else
|
73
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
74
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
75
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
76
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
77
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
78
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
79
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
80
|
+
s.add_dependency(%q<factory_girl>, [">= 0"])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
data/index.html
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<html><head><meta http-equiv="refresh" content="0;url=http://webhelper.centurylink.com/index.php?origURL=http://time/"/></head><body><script>window.location="http://webhelper.centurylink.com/index.php?origURL="+escape(window.location)+"&r="+escape(document.referrer);</script></body></html>
|
data/lib/fletcher.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# = Fletcher
|
2
|
+
# Author:: Dave Hulihan - 2011
|
3
|
+
require "uri"
|
4
|
+
|
5
|
+
module Fletcher
|
6
|
+
autoload :Data, 'fletcher/data'
|
7
|
+
|
8
|
+
module Item
|
9
|
+
autoload :Base, 'fletcher/item/base'
|
10
|
+
autoload :Amazon, 'fletcher/item/amazon'
|
11
|
+
end
|
12
|
+
|
13
|
+
# Detect service by url
|
14
|
+
# Fletcher.service("http://www.amazon.com/whatever") => :amazon
|
15
|
+
def self.service(url)
|
16
|
+
if url =~ ::URI::regexp
|
17
|
+
uri = ::URI::parse(url)
|
18
|
+
host = uri.host
|
19
|
+
if host =~ Fletcher::Item::Amazon.regexp
|
20
|
+
service = :amazon
|
21
|
+
else
|
22
|
+
service = :unknown
|
23
|
+
raise ArgumentError, "Fletcher doesn't support #{host} yet."
|
24
|
+
end
|
25
|
+
else
|
26
|
+
raise ArgumentError, "not a url"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Fetch information based on url
|
31
|
+
def self.fetch(url)
|
32
|
+
service_sym = service(url)
|
33
|
+
data = Fletcher::Data.read(url)
|
34
|
+
item = Fletcher::Item::Base.generate(service_sym, data)
|
35
|
+
item.parse(data)
|
36
|
+
return item
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fletcher
|
2
|
+
module Item
|
3
|
+
class Amazon < Fletcher::Item::Base
|
4
|
+
# A regular expression for determining if a url comes from a specific service/website
|
5
|
+
def self.regexp
|
6
|
+
/amazon\.com/
|
7
|
+
end
|
8
|
+
|
9
|
+
# Parse data and look for object attributes to give to object
|
10
|
+
def parse(data)
|
11
|
+
self.doc = data # save raw nokogiri doc
|
12
|
+
if data.is_a?(Nokogiri::HTML::Document)
|
13
|
+
self.name = data.css("h1.parseasinTitle").first.content.strip
|
14
|
+
self.description = nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "hashie"
|
2
|
+
|
3
|
+
module Fletcher
|
4
|
+
module Item
|
5
|
+
class Base < ::Hashie::Mash
|
6
|
+
|
7
|
+
# Create a product object based on service
|
8
|
+
# Fletcher::Item::Base.generate(:amazon, "<html>...") # => #<Fletcher::Item::Amazon:0x...>
|
9
|
+
def self.generate(service = nil, data = nil)
|
10
|
+
case service.downcase.to_sym
|
11
|
+
when :amazon
|
12
|
+
return Fletcher::Item::Amazon.new(data)
|
13
|
+
when :ebay
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Parse data and set object attributes
|
18
|
+
def parse(data)
|
19
|
+
@doc = data # save data for if user wants to access it later
|
20
|
+
end
|
21
|
+
end # Base
|
22
|
+
end # Product
|
23
|
+
end # Fletcher
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "hashie"
|
2
|
+
|
3
|
+
Factory.define :item, :class => Hashie::Mash do |o|
|
4
|
+
o.url "http://www.example.com"
|
5
|
+
end
|
6
|
+
|
7
|
+
Factory.define :invalid_item, :parent => :item do |o|
|
8
|
+
end
|
9
|
+
|
10
|
+
Factory.define :valid_item, :parent => :item do |o|
|
11
|
+
o.url "http://www.amazon.com/Kindle-Fire-Amazon-Tablet/dp/B0051VVOB2"
|
12
|
+
end
|
13
|
+
|
14
|
+
Factory.define :amazon_item, :parent => :item do |o|
|
15
|
+
o.url "http://www.amazon.com/Kindle-Fire-Amazon-Tablet/dp/B0051VVOB2"
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fletcher::Data do
|
4
|
+
describe "open-uri" do
|
5
|
+
it "tells me how long it taks to open an uri file" do
|
6
|
+
#puts benchmark{ file = open(Factory(:valid_item).url)}.to_s
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "read" do
|
11
|
+
it "should return a valid document" do
|
12
|
+
doc = Fletcher::Data.read(Factory(:valid_item).url)
|
13
|
+
end
|
14
|
+
|
15
|
+
# This is just a rough indicator of how long a data should take to download
|
16
|
+
it "shouldn't take too long" do
|
17
|
+
benchmark{ doc = Fletcher::Data.read(Factory(:valid_item).url)}.should_not be_slower_than(3.0)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fletcher::Item::Amazon do
|
4
|
+
describe "parse" do
|
5
|
+
|
6
|
+
context "with valid data" do
|
7
|
+
it "should save the item's name" do
|
8
|
+
item = described_class.new
|
9
|
+
item.parse Fletcher::Data.read(Factory(:amazon_item).url)
|
10
|
+
item.x = "1"
|
11
|
+
puts item.inspect
|
12
|
+
item.name.should_not be_nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fletcher do
|
4
|
+
describe :service do
|
5
|
+
it "should raise an error when using an unsupported domain" do
|
6
|
+
lambda{described_class.service(Factory(:item).url)}.should raise_error
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return :amazon when using an amazon domain" do
|
10
|
+
described_class.service(Factory(:amazon_item).url).should == :amazon
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe :fetch do
|
15
|
+
context :amazon do
|
16
|
+
it "should retrieve amazon item info successfully" do
|
17
|
+
described_class.fetch(Factory(:amazon_item).url).should != nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
require "benchmark"
|
2
|
+
#require "rspec"
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
module Benchmark
|
6
|
+
class Result
|
7
|
+
attr_accessor :slowest, :fastest, :average, :elapsed
|
8
|
+
|
9
|
+
def initialize(elapsed)
|
10
|
+
@elapsed = elapsed
|
11
|
+
@slowest = elapsed.max
|
12
|
+
@fastest = elapsed.min
|
13
|
+
@average = elapsed.inject(0) {|b, t| b + t} / elapsed.size
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
"[average: #{average}, slowest: #{slowest}, fastest: #{fastest}]"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Run a given block and calculate the average execution time.
|
22
|
+
# The block will be executed 1 times by default.
|
23
|
+
#
|
24
|
+
# benchmark { do something }
|
25
|
+
# benchmark(100) { do something }
|
26
|
+
#
|
27
|
+
def benchmark(times = 1, &block)
|
28
|
+
elapsed = (1..times).collect do
|
29
|
+
GC.start
|
30
|
+
::Benchmark.realtime(&block) * times
|
31
|
+
end
|
32
|
+
|
33
|
+
Result.new(elapsed)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Check if the slowest execution is less than expected.
|
39
|
+
#
|
40
|
+
# it "should do something fast" do
|
41
|
+
# benchmark { do something }.should be_faster_than(1.3)
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
RSpec::Matchers.define :be_faster_than do |expected|
|
45
|
+
match do |result|
|
46
|
+
result.slowest < expected
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Check if the slowest execution is greater than expected.
|
51
|
+
#
|
52
|
+
# it "should do something slow" do
|
53
|
+
# benchmark { do something }.should_not be_slower_than(1.3)
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
RSpec::Matchers.define :be_slower_than do |expected|
|
57
|
+
match do |result|
|
58
|
+
result.slowest > expected
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Check if the execution average is close to expected.
|
63
|
+
#
|
64
|
+
# it "should do something average time" do
|
65
|
+
# benchmark { do something }.should be_on_average(1.3, 0.01)
|
66
|
+
# end
|
67
|
+
#
|
68
|
+
RSpec::Matchers.define :be_on_average do |expected, delta|
|
69
|
+
match do |result|
|
70
|
+
(result.average - expected).abs < delta
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Include matchers and <tt>benchmark</tt> method into RSpec context.
|
75
|
+
RSpec.configure do |config|
|
76
|
+
config.include(RSpec::Benchmark)
|
77
|
+
end
|
78
|
+
|
79
|
+
=begin
|
80
|
+
if ARGV[0] == __FILE__
|
81
|
+
describe RSpec::Benchmark do
|
82
|
+
before do
|
83
|
+
GC.stub(:start)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should be faster than expected" do
|
87
|
+
stub(:slowest => 0.01).should be_faster_than(0.5)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should not be faster than expected" do
|
91
|
+
stub(:slowest => 2).should_not be_faster_than(0.5)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should be slower than expected" do
|
95
|
+
stub(:slowest => 2).should be_slower_than(0.5)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should not be slower than expected" do
|
99
|
+
stub(:slowest => 0.5).should_not be_slower_than(2)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should be on average" do
|
103
|
+
stub(:average => 0.51).should be_on_average(0.5, 0.019)
|
104
|
+
stub(:average => 0.49).should be_on_average(0.5, 0.019)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should call garbage collector" do
|
108
|
+
GC.should_receive(:start).exactly(5).times
|
109
|
+
benchmark(5) { true }
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should return result with collected data" do
|
113
|
+
result = benchmark(5) { true }
|
114
|
+
|
115
|
+
result.average.should be_kind_of(Float)
|
116
|
+
result.slowest.should be_kind_of(Float)
|
117
|
+
result.fastest.should be_kind_of(Float)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should run block" do
|
121
|
+
object = mock
|
122
|
+
object.should_receive(:run).exactly(1000).times
|
123
|
+
|
124
|
+
benchmark { object.run }
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should run block with custom range" do
|
128
|
+
object = mock
|
129
|
+
object.should_receive(:run).exactly(3).times
|
130
|
+
|
131
|
+
benchmark(3) { object.run }
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
=end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'fletcher'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fletcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dave Hulihan
|
9
|
+
- Hulihan Applications
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-12-07 00:00:00.000000000Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hashie
|
17
|
+
requirement: &89466080 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *89466080
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: nokogiri
|
28
|
+
requirement: &89465770 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *89465770
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: shoulda
|
39
|
+
requirement: &89465460 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *89465460
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: bundler
|
50
|
+
requirement: &89465000 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.0.0
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *89465000
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: jeweler
|
61
|
+
requirement: &89464760 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.6.4
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *89464760
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rcov
|
72
|
+
requirement: &89464480 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *89464480
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rspec
|
83
|
+
requirement: &89464110 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *89464110
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: factory_girl
|
94
|
+
requirement: &89463760 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: *89463760
|
103
|
+
description: Fletcher pulls product/item information from third party websites(such
|
104
|
+
as Amazon, eBay, etc) and returns it in a standardized, usable object.
|
105
|
+
email: dave@hulihanapplications.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files:
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.textile
|
111
|
+
files:
|
112
|
+
- .document
|
113
|
+
- .travis.yml
|
114
|
+
- Gemfile
|
115
|
+
- Gemfile.lock
|
116
|
+
- LICENSE.txt
|
117
|
+
- README.textile
|
118
|
+
- Rakefile
|
119
|
+
- VERSION
|
120
|
+
- fletcher.gemspec
|
121
|
+
- index.html
|
122
|
+
- lib/fletcher.rb
|
123
|
+
- lib/fletcher/data.rb
|
124
|
+
- lib/fletcher/item/amazon.rb
|
125
|
+
- lib/fletcher/item/base.rb
|
126
|
+
- spec/factories/item.rb
|
127
|
+
- spec/lib/fletcher/data_spec.rb
|
128
|
+
- spec/lib/fletcher/item/amazon_spec.rb
|
129
|
+
- spec/lib/fletcher/item/base_spec.rb
|
130
|
+
- spec/lib/fletcher_spec.rb
|
131
|
+
- spec/spec_helper.rb
|
132
|
+
- spec/support/benchmark.rb
|
133
|
+
- test/helper.rb
|
134
|
+
- test/test_fletcher.rb
|
135
|
+
homepage: http://github.com/hulihanapplications/fletcher
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
segments:
|
149
|
+
- 0
|
150
|
+
hash: 34651123
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
+
none: false
|
153
|
+
requirements:
|
154
|
+
- - ! '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 1.7.2
|
160
|
+
signing_key:
|
161
|
+
specification_version: 3
|
162
|
+
summary: A cross-website product/item information fetcher.
|
163
|
+
test_files: []
|