technicalpickles-rankles 0.0.2

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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Josh Nichols
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.
@@ -0,0 +1,30 @@
1
+ = rankles
2
+
3
+ Rankles is a collection of ranking algorithms (technically only one at the moment) implemented in Ruby.
4
+
5
+ The idea is simple. Give Rankles some data, and it will give you a number. You probably want to sort based on this number.
6
+
7
+ Quick example:
8
+
9
+ reddit = Rankles::Reddit.new :date => entry.published_at,
10
+ :upvotes => entry.cached_upvotes_count,
11
+ :downvotes => entry.cached_downvotes_count
12
+
13
+ reddit.to_f
14
+
15
+ If you're dealing with ActiveRecord objects, you can actually assign the Rankles object to a float field, and it will handle converstion:
16
+
17
+ class Entry < ActiveRecord::Base
18
+ # ommitted
19
+ def calculate_ranking
20
+ reddit_ranking = Rankles::Reddit.new :date => entry.published_at,
21
+ :upvotes => entry.cached_upvotes_count,
22
+ :downvotes => entry.cached_downvotes_count
23
+
24
+ update_attributes! :ranking => reddit_ranking
25
+ end
26
+ end
27
+
28
+ == Copyright
29
+
30
+ Copyright (c) 2009 Josh Nichols. See LICENSE for details.
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rankles"
8
+ gem.summary = %Q{Ranking algorithms.}
9
+ gem.email = "josh@technicalpickles.com"
10
+ gem.homepage = "http://github.com/technicalpickles/rankles"
11
+ gem.authors = ["Josh Nichols"]
12
+ gem.rubyforge_project = "pickles"
13
+ gem.add_dependency "activesupport"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+
17
+ Jeweler::RubyforgeTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ if File.exist?('VERSION.yml')
40
+ config = YAML.load(File.read('VERSION.yml'))
41
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
42
+ else
43
+ version = ""
44
+ end
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "rankles #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
51
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,38 @@
1
+ require 'activesupport'
2
+ module Rankles
3
+ class Reddit
4
+ attr_accessor :date, :upvotes, :downvotes
5
+
6
+ # Setup data for ranking calculation. Required options:
7
+ # * <tt>:date</tt>
8
+ # * <tt>:upvotes</tt>
9
+ # * <tt>:downvotes</tt>
10
+ def initialize(options = {})
11
+ self.date = options[:date]
12
+ self.upvotes = options[:upvotes]
13
+ self.downvotes = options[:downvotes]
14
+ end
15
+
16
+ # http://www.seomoz.org/img/upload/reddit_cf_algorithm.png
17
+ #
18
+ # Gives the result of the reddit algorithm. Higher is better.
19
+ def to_f
20
+ ts = date - Time.utc(2005, 12, 8, 7, 46, 43)
21
+ x = upvotes - downvotes
22
+
23
+ y = case
24
+ when x > 0 then 1
25
+ when x == 0 then 0
26
+ when x < 0 then -1
27
+ end
28
+
29
+ z = if x.abs >= 1
30
+ x.abs
31
+ else
32
+ 1
33
+ end
34
+
35
+ Math.log10(z) + (y * ts) / 12.5.hours
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,51 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rankles}
5
+ s.version = "0.0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Josh Nichols"]
9
+ s.date = %q{2009-05-14}
10
+ s.email = %q{josh@technicalpickles.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "lib/rankles.rb",
23
+ "rankles.gemspec",
24
+ "spec/rankles_spec.rb",
25
+ "spec/spec_helper.rb"
26
+ ]
27
+ s.has_rdoc = true
28
+ s.homepage = %q{http://github.com/technicalpickles/rankles}
29
+ s.rdoc_options = ["--charset=UTF-8"]
30
+ s.require_paths = ["lib"]
31
+ s.rubyforge_project = %q{pickles}
32
+ s.rubygems_version = %q{1.3.1}
33
+ s.summary = %q{Ranking algorithms.}
34
+ s.test_files = [
35
+ "spec/rankles_spec.rb",
36
+ "spec/spec_helper.rb"
37
+ ]
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 2
42
+
43
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
45
+ else
46
+ s.add_dependency(%q<activesupport>, [">= 0"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<activesupport>, [">= 0"])
50
+ end
51
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Rankles::Reddit do
4
+ it "should not blow up" do
5
+ reddit = Rankles::Reddit.new :date => Time.now, :upvotes => 0, :downvotes => 0
6
+ reddit.to_f
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'rankles'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: technicalpickles-rankles
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Josh Nichols
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-14 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: josh@technicalpickles.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/rankles.rb
42
+ - rankles.gemspec
43
+ - spec/rankles_spec.rb
44
+ - spec/spec_helper.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/technicalpickles/rankles
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project: pickles
67
+ rubygems_version: 1.2.0
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: Ranking algorithms.
71
+ test_files:
72
+ - spec/rankles_spec.rb
73
+ - spec/spec_helper.rb