snl-kosher 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +26 -0
- data/data/rules.yml +8 -0
- data/lib/kosher.rb +38 -0
- data/test/kosher_test.rb +42 -0
- metadata +56 -0
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= Kosher
|
2
|
+
|
3
|
+
People sell stuff online. Some are bad sellers. Some sell bad stuff. This module provides some basic methods to filter out those iffy listings you probably do not want to buy.
|
4
|
+
|
5
|
+
The current incarnation only works with Amazon sellers and book descriptions in English, but the idea is easily expandable to other product groups, venues, or languages.
|
6
|
+
|
7
|
+
== Example usage
|
8
|
+
|
9
|
+
>> load "lib/kosher.rb"
|
10
|
+
=> true
|
11
|
+
>> Kosher.seller? :amazon, nil, 0
|
12
|
+
=> true
|
13
|
+
>> Kosher.seller? :amazon, 4.9, 1000
|
14
|
+
=> true
|
15
|
+
>> Kosher.seller? :amazon, 4.5, 1000
|
16
|
+
=> false
|
17
|
+
>> Kosher.description? :book, "Fine/Fine."
|
18
|
+
=> true
|
19
|
+
>> Kosher.description? :book, "Very good. Not an exlib."
|
20
|
+
=> true
|
21
|
+
>> Kosher.description? :book, "Withdrawn library copy."
|
22
|
+
=> false
|
23
|
+
>> Kosher.description? :book, "Some highlighting."
|
24
|
+
=> false
|
25
|
+
|
26
|
+
That's about it!
|
data/data/rules.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
---
|
2
|
+
:en:
|
3
|
+
:book:
|
4
|
+
- bad: (has|have|contains?|some|considerable|neatly) (hi|under|writing|marginalia|marking|note)
|
5
|
+
- bad: \. *highlight|\. *hili|^ *highlight|^ *hili
|
6
|
+
- bad: missing|torn|broken|split|different|no cd|sticker|stain|damaged|water
|
7
|
+
- bad: discard|withdrawn|x.{0,2}lib|retired.*library|former.*library|has.*library|may have library|school
|
8
|
+
good: not a?n? ?(e?x.{0,2}lib|library)
|
data/lib/kosher.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module Kosher
|
4
|
+
RULES = File.open(File.join(File.dirname(__FILE__), "../data/rules.yml")) {|f| YAML.load(f)}
|
5
|
+
|
6
|
+
# Check if a book description is kosher.
|
7
|
+
def self.description?(product_group, description, language = :en)
|
8
|
+
if RULES[language].is_a?(Hash) && RULES[language][product_group].is_a?(Array)
|
9
|
+
RULES[language][product_group].each do |rule|
|
10
|
+
if description =~ Regexp.new(rule["bad"], true)
|
11
|
+
if rule["good"].nil? || description !~ Regexp.new(rule["good"], true)
|
12
|
+
return false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
# Check if a seller is kosher.
|
21
|
+
def self.seller?(venue, ave_feedback, total_feedback, feedback_threshold = 4.8)
|
22
|
+
# Give small sellers the benefit of doubt.
|
23
|
+
if total_feedback == 0
|
24
|
+
true
|
25
|
+
else
|
26
|
+
if venue == :amazon
|
27
|
+
if total_feedback < 5
|
28
|
+
ave_feedback > 4.4 ? true : false
|
29
|
+
else
|
30
|
+
ave_feedback >= feedback_threshold ? true : false
|
31
|
+
end
|
32
|
+
else
|
33
|
+
# Other venues are not included at the moment.
|
34
|
+
true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/test/kosher_test.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require File.dirname(__FILE__) + '/../lib/kosher'
|
3
|
+
|
4
|
+
class KosherTest < Test::Unit::TestCase
|
5
|
+
def test_book_descriptions
|
6
|
+
kosher_descriptions = {:en => {:book => [nil,
|
7
|
+
"",
|
8
|
+
"Lorem ipsum",
|
9
|
+
"Not exlib",
|
10
|
+
"No highlighting"]}}
|
11
|
+
unkosher_descriptions = {:en => {:book => ["Some underlining",
|
12
|
+
"Has highlighting",
|
13
|
+
"A withdrawn library copy",
|
14
|
+
"Awesome book. EXLIB!",
|
15
|
+
"A former school library book"]}}
|
16
|
+
kosher_descriptions.each do |language, product_groups|
|
17
|
+
product_groups.each do |product_group, descriptions|
|
18
|
+
descriptions.each do |description|
|
19
|
+
assert_equal true, (Kosher.description? product_group, description, language), description
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
unkosher_descriptions.each do |language, product_groups|
|
24
|
+
product_groups.each do |product_group, descriptions|
|
25
|
+
descriptions.each do |description|
|
26
|
+
assert_equal false, (Kosher.description? product_group, description, language), description
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_amazon_sellers
|
33
|
+
assert_equal true, (Kosher.seller? :amazon, nil, 0), "Kosher new Amazon seller"
|
34
|
+
assert_equal true, (Kosher.seller? :amazon, 4.5, 1), "Kosher small Amazon seller"
|
35
|
+
assert_equal true, (Kosher.seller? :amazon, 4.9, 100), "Kosher big Amazon seller"
|
36
|
+
assert_equal false, (Kosher.seller? :amazon, 4, 1), "Unkosher small Amazon seller"
|
37
|
+
assert_equal false, (Kosher.seller? :amazon, 4.5, 100), "Unkosher big Amazon seller"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
require 'test/unit/ui/console/testrunner'
|
42
|
+
Test::Unit::UI::Console::TestRunner.run(KosherTest)
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: snl-kosher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Hakan \xC5\x9Eenol Ensari"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-07 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Kosher is a Ruby module that provides some methods to filter out iffy listings on Amazon and similar venues.
|
17
|
+
email: snl@theorydot.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- data/rules.yml
|
26
|
+
- lib/kosher.rb
|
27
|
+
- README.rdoc
|
28
|
+
has_rdoc: true
|
29
|
+
homepage: http://github.com/snl/kosher
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options:
|
32
|
+
- --inline-source
|
33
|
+
- --charset=UTF-8
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.2.0
|
52
|
+
signing_key:
|
53
|
+
specification_version: 2
|
54
|
+
summary: Kosher is a Ruby module that provides some methods to filter out iffy listings on Amazon and similar venues.
|
55
|
+
test_files:
|
56
|
+
- test/kosher_test.rb
|