slide_rule 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -9
- data/Gemfile +0 -1
- data/README.md +2 -0
- data/Rakefile +5 -3
- data/lib/slide_rule/distance_calculator.rb +6 -7
- data/lib/slide_rule/distance_calculators/day_of_month.rb +11 -5
- data/lib/slide_rule/distance_calculators/day_of_year.rb +11 -5
- data/lib/slide_rule/distance_calculators/levenshtein.rb +1 -3
- data/lib/slide_rule/version.rb +1 -1
- data/lib/slide_rule.rb +2 -0
- data/slide_rule.gemspec +1 -1
- metadata +6 -18
- data/.rubocop_todo.yml +0 -41
- data/Gemfile.lock +0 -71
- data/slide_rulee/.gitignore +0 -9
- data/slide_rulee/Gemfile +0 -4
- data/slide_rulee/README.md +0 -41
- data/slide_rulee/bin/console +0 -14
- data/slide_rulee/bin/setup +0 -7
- data/slide_rulee/lib/slide_rulee/version.rb +0 -3
- data/slide_rulee/lib/slide_rulee.rb +0 -5
- data/slide_rulee/slide_rulee.gemspec +0 -33
- data/slide_rulee/spec/slide_rulee_spec.rb +0 -11
- data/slide_rulee/spec/spec_helper.rb +0 -2
- /data/{slide_rulee/.travis.yml → .travis.yml} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c64f03bd0a58531ff1ba600c493168d36baeca24
|
4
|
+
data.tar.gz: aacb2941fa539b5051d904b269047b3d33c96b75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f266a284b49d88cd63f3958f778e8b2288d7d06fb520f22fdaf24aa84c0d75ee2b102595f9333dc9b5e9aa695fddc50b3e56256ca58b61cb5c030eea4a422841
|
7
|
+
data.tar.gz: 9cd3e4e6689bd4c316b65b5edb91d89c5767597347a66f3b4c53f13fc08ff794fb3f21f13bb36fcf0c1f4581d885b2c131d7f45055bf286832623565d0f04d3a
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
inherit_from:
|
2
|
-
- .rubocop_todo.yml
|
3
|
-
|
4
1
|
AllCops:
|
5
2
|
DisplayCopNames: true
|
6
3
|
Exclude:
|
@@ -11,14 +8,13 @@ AllCops:
|
|
11
8
|
- 'lib/core_ext/pkcs12.rb'
|
12
9
|
|
13
10
|
Metrics/LineLength:
|
11
|
+
Max: 100
|
14
12
|
Exclude:
|
15
13
|
- 'spec/**/*'
|
14
|
+
- 'slide_rule.gemspec'
|
15
|
+
|
16
|
+
Metrics/MethodLength:
|
17
|
+
Max: 15
|
16
18
|
|
17
19
|
Style/Documentation:
|
18
20
|
Enabled: false
|
19
|
-
|
20
|
-
Metrics/LineLength:
|
21
|
-
Max: 100
|
22
|
-
Exclude:
|
23
|
-
- 'spec/**/*'
|
24
|
-
- 'slide_rule.gemspec'
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
3
4
|
|
5
|
+
RuboCop::RakeTask.new
|
4
6
|
RSpec::Core::RakeTask.new(:spec)
|
5
7
|
|
6
|
-
task :
|
8
|
+
task default: [:spec, :rubocop]
|
@@ -27,12 +27,11 @@ module SlideRule
|
|
27
27
|
def matches(obj, array, threshold)
|
28
28
|
array.map do |item|
|
29
29
|
distance = calculate_distance(obj, item)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
30
|
+
next nil unless distance < threshold
|
31
|
+
{
|
32
|
+
item: item,
|
33
|
+
distance: distance
|
34
|
+
}
|
36
35
|
end.compact
|
37
36
|
end
|
38
37
|
|
@@ -53,7 +52,7 @@ module SlideRule
|
|
53
52
|
val2 = i2.send(attribute)
|
54
53
|
calculator = get_calculator(rule[:type])
|
55
54
|
calculator.calculate(val1, val2).to_f * rule[:weight]
|
56
|
-
end.
|
55
|
+
end.reduce(0.0, &:+)
|
57
56
|
end
|
58
57
|
|
59
58
|
def get_calculator(calculator)
|
@@ -8,11 +8,8 @@ module SlideRule
|
|
8
8
|
# Does not take into account the number of days in the actual month being considered.
|
9
9
|
#
|
10
10
|
def calculate(first, second)
|
11
|
-
first =
|
12
|
-
second =
|
13
|
-
|
14
|
-
first = first.to_date if first.is_a?(::Time)
|
15
|
-
second = second.to_date if second.is_a?(::Time)
|
11
|
+
first = cleanse_date(first)
|
12
|
+
second = cleanse_date(second)
|
16
13
|
|
17
14
|
difference_in_days(first, second).to_f / MAX_DAYS
|
18
15
|
end
|
@@ -22,6 +19,15 @@ module SlideRule
|
|
22
19
|
return distance if distance <= MAX_DAYS
|
23
20
|
MAX_DAYS - (distance - MAX_DAYS)
|
24
21
|
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def cleanse_date(date)
|
26
|
+
date = Date.parse(date) unless date.is_a?(::Date) || date.is_a?(::Time)
|
27
|
+
date = date.to_date if date.is_a?(::Time)
|
28
|
+
|
29
|
+
date
|
30
|
+
end
|
25
31
|
end
|
26
32
|
end
|
27
33
|
end
|
@@ -4,11 +4,8 @@ module SlideRule
|
|
4
4
|
DAYS_IN_YEAR = 365
|
5
5
|
|
6
6
|
def calculate(date_1, date_2)
|
7
|
-
date_1 =
|
8
|
-
date_2 =
|
9
|
-
|
10
|
-
date_1 = date_1.to_date if date_1.is_a?(::Time)
|
11
|
-
date_2 = date_2.to_date if date_2.is_a?(::Time)
|
7
|
+
date_1 = cleanse_date(date_1)
|
8
|
+
date_2 = cleanse_date(date_2)
|
12
9
|
|
13
10
|
days_apart = (date_1.mjd - date_2.mjd).abs
|
14
11
|
|
@@ -17,6 +14,15 @@ module SlideRule
|
|
17
14
|
distance = days_apart.to_f / DAYS_IN_YEAR
|
18
15
|
distance.round(2)
|
19
16
|
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def cleanse_date(date)
|
21
|
+
date = Date.parse(date) unless date.is_a?(::Date) || date.is_a?(::Time)
|
22
|
+
date = date.to_date if date.is_a?(::Time)
|
23
|
+
|
24
|
+
date
|
25
|
+
end
|
20
26
|
end
|
21
27
|
end
|
22
28
|
end
|
@@ -1,10 +1,8 @@
|
|
1
|
-
require 'levee'
|
2
|
-
|
3
1
|
module SlideRule
|
4
2
|
module DistanceCalculators
|
5
3
|
class Levenshtein
|
6
4
|
def calculate(first, second)
|
7
|
-
distance =
|
5
|
+
distance = ::Levenshtein.distance(first, second).to_f
|
8
6
|
|
9
7
|
# Lower bound is difference in length
|
10
8
|
# distance = matrix.last.last.to_f - (first.length - second.length).abs
|
data/lib/slide_rule/version.rb
CHANGED
data/lib/slide_rule.rb
CHANGED
data/slide_rule.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slide_rule
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mattnichols
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-11-
|
12
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: levenshtein
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '2'
|
20
|
+
version: '0.2'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '2'
|
27
|
+
version: '0.2'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,10 +91,9 @@ extra_rdoc_files: []
|
|
91
91
|
files:
|
92
92
|
- ".gitignore"
|
93
93
|
- ".rubocop.yml"
|
94
|
-
- ".
|
94
|
+
- ".travis.yml"
|
95
95
|
- CODE_OF_CONDUCT.md
|
96
96
|
- Gemfile
|
97
|
-
- Gemfile.lock
|
98
97
|
- LICENSE
|
99
98
|
- README.md
|
100
99
|
- Rakefile
|
@@ -105,17 +104,6 @@ files:
|
|
105
104
|
- lib/slide_rule/distance_calculators/levenshtein.rb
|
106
105
|
- lib/slide_rule/version.rb
|
107
106
|
- slide_rule.gemspec
|
108
|
-
- slide_rulee/.gitignore
|
109
|
-
- slide_rulee/.travis.yml
|
110
|
-
- slide_rulee/Gemfile
|
111
|
-
- slide_rulee/README.md
|
112
|
-
- slide_rulee/bin/console
|
113
|
-
- slide_rulee/bin/setup
|
114
|
-
- slide_rulee/lib/slide_rulee.rb
|
115
|
-
- slide_rulee/lib/slide_rulee/version.rb
|
116
|
-
- slide_rulee/slide_rulee.gemspec
|
117
|
-
- slide_rulee/spec/slide_rulee_spec.rb
|
118
|
-
- slide_rulee/spec/spec_helper.rb
|
119
107
|
- spec/slide_rule/distance_calculator_spec.rb
|
120
108
|
- spec/slide_rule/distance_calculators/day_of_month_spec.rb
|
121
109
|
- spec/slide_rule/distance_calculators/day_of_year_spec.rb
|
data/.rubocop_todo.yml
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# This configuration was generated by
|
2
|
-
# `rubocop --auto-gen-config`
|
3
|
-
# on 2015-11-02 16:38:15 -0700 using RuboCop version 0.34.1.
|
4
|
-
# The point is for the user to remove these configuration records
|
5
|
-
# one by one as the offenses are removed from the code base.
|
6
|
-
# Note that changes in the inspected code, or installation of new
|
7
|
-
# versions of RuboCop, may require this file to be generated again.
|
8
|
-
|
9
|
-
# Offense count: 1
|
10
|
-
Metrics/AbcSize:
|
11
|
-
Max: 21
|
12
|
-
|
13
|
-
# Offense count: 2
|
14
|
-
Metrics/CyclomaticComplexity:
|
15
|
-
Max: 8
|
16
|
-
|
17
|
-
# Offense count: 1
|
18
|
-
# Configuration parameters: CountComments.
|
19
|
-
Metrics/MethodLength:
|
20
|
-
Max: 11
|
21
|
-
|
22
|
-
# Offense count: 1
|
23
|
-
Metrics/PerceivedComplexity:
|
24
|
-
Max: 8
|
25
|
-
|
26
|
-
# Offense count: 1
|
27
|
-
Style/MultilineBlockChain:
|
28
|
-
Exclude:
|
29
|
-
- 'lib/slide_rule/distance_calculator.rb'
|
30
|
-
|
31
|
-
# Offense count: 1
|
32
|
-
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
|
33
|
-
Style/Next:
|
34
|
-
Exclude:
|
35
|
-
- 'lib/slide_rule/distance_calculator.rb'
|
36
|
-
|
37
|
-
# Offense count: 1
|
38
|
-
# Configuration parameters: Methods.
|
39
|
-
Style/SingleLineBlockParams:
|
40
|
-
Exclude:
|
41
|
-
- 'lib/slide_rule/distance_calculator.rb'
|
data/Gemfile.lock
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
slide_rule (0.0.1)
|
5
|
-
levee (~> 2)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
remote: http://gems.moneydesktop.com/
|
10
|
-
specs:
|
11
|
-
ast (2.1.0)
|
12
|
-
astrolabe (1.3.1)
|
13
|
-
parser (~> 2.2)
|
14
|
-
coderay (1.1.0)
|
15
|
-
diff-lcs (1.2.5)
|
16
|
-
ffi (1.9.10)
|
17
|
-
ffi (1.9.10-java)
|
18
|
-
levee (2.0.0)
|
19
|
-
ffi
|
20
|
-
method_source (0.8.2)
|
21
|
-
parser (2.2.2.6)
|
22
|
-
ast (>= 1.1, < 3.0)
|
23
|
-
powerpack (0.1.1)
|
24
|
-
pry (0.10.1)
|
25
|
-
coderay (~> 1.1.0)
|
26
|
-
method_source (~> 0.8.1)
|
27
|
-
slop (~> 3.4)
|
28
|
-
pry (0.10.1-java)
|
29
|
-
coderay (~> 1.1.0)
|
30
|
-
method_source (~> 0.8.1)
|
31
|
-
slop (~> 3.4)
|
32
|
-
spoon (~> 0.0)
|
33
|
-
rainbow (2.0.0)
|
34
|
-
rake (10.4.2)
|
35
|
-
rspec (3.3.0)
|
36
|
-
rspec-core (~> 3.3.0)
|
37
|
-
rspec-expectations (~> 3.3.0)
|
38
|
-
rspec-mocks (~> 3.3.0)
|
39
|
-
rspec-core (3.3.2)
|
40
|
-
rspec-support (~> 3.3.0)
|
41
|
-
rspec-expectations (3.3.1)
|
42
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
-
rspec-support (~> 3.3.0)
|
44
|
-
rspec-mocks (3.3.2)
|
45
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
-
rspec-support (~> 3.3.0)
|
47
|
-
rspec-support (3.3.0)
|
48
|
-
rubocop (0.34.1)
|
49
|
-
astrolabe (~> 1.3)
|
50
|
-
parser (>= 2.2.2.5, < 3.0)
|
51
|
-
powerpack (~> 0.1)
|
52
|
-
rainbow (>= 1.99.1, < 3.0)
|
53
|
-
ruby-progressbar (~> 1.4)
|
54
|
-
ruby-progressbar (1.7.5)
|
55
|
-
slop (3.6.0)
|
56
|
-
spoon (0.0.4)
|
57
|
-
ffi
|
58
|
-
|
59
|
-
PLATFORMS
|
60
|
-
java
|
61
|
-
ruby
|
62
|
-
|
63
|
-
DEPENDENCIES
|
64
|
-
pry (~> 0)
|
65
|
-
rake (~> 10)
|
66
|
-
rspec (~> 3)
|
67
|
-
rubocop (~> 0)
|
68
|
-
slide_rule!
|
69
|
-
|
70
|
-
BUNDLED WITH
|
71
|
-
1.10.6
|
data/slide_rulee/.gitignore
DELETED
data/slide_rulee/Gemfile
DELETED
data/slide_rulee/README.md
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# SlideRulee
|
2
|
-
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/slide_rulee`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'slide_rulee'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install slide_rulee
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/slide_rulee. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
-
|
37
|
-
|
38
|
-
## License
|
39
|
-
|
40
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/slide_rulee/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "slide_rulee"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
data/slide_rulee/bin/setup
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'slide_rulee/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "slide_rulee"
|
8
|
-
spec.version = SlideRulee::VERSION
|
9
|
-
spec.authors = ["matthew-nichols"]
|
10
|
-
spec.email = ["matthew.nichols@mx.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{TODO: Write a short summary, because Rubygems requires one.}
|
13
|
-
spec.description = %q{TODO: Write a longer description or delete this line.}
|
14
|
-
spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
-
# delete this section to allow pushing this gem to any host.
|
19
|
-
if spec.respond_to?(:metadata)
|
20
|
-
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
-
else
|
22
|
-
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
-
end
|
24
|
-
|
25
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
-
spec.bindir = "exe"
|
27
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = ["lib"]
|
29
|
-
|
30
|
-
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
-
spec.add_development_dependency "rspec"
|
33
|
-
end
|
File without changes
|