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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 006868b9cca39594d800bf786a49dc9fd3b733cd
4
- data.tar.gz: 09282b0628ea97599120d36e53602b9ec7819a9a
3
+ metadata.gz: c64f03bd0a58531ff1ba600c493168d36baeca24
4
+ data.tar.gz: aacb2941fa539b5051d904b269047b3d33c96b75
5
5
  SHA512:
6
- metadata.gz: 22599f361ab8bd3a3cb514f786b3e314ef4e8f7c20c74732cf225e471722d0c8262c67fb57b4b3fc30905ba34c5719ca773e7185f363ce4911b5cdf2bcff0216
7
- data.tar.gz: 3a712c9ff14c6d08e26847ff0d8308524528a00e2e10eed5ffd03884affee53acc8c42b498e3d03d2555ad6d648f3ab25991bbdd27fe4d96317cbef53f8791de
6
+ metadata.gz: f266a284b49d88cd63f3958f778e8b2288d7d06fb520f22fdaf24aa84c0d75ee2b102595f9333dc9b5e9aa695fddc50b3e56256ca58b61cb5c030eea4a422841
7
+ data.tar.gz: 9cd3e4e6689bd4c316b65b5edb91d89c5767597347a66f3b4c53f13fc08ff794fb3f21f13bb36fcf0c1f4581d885b2c131d7f45055bf286832623565d0f04d3a
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  .rspec
2
2
  **.DS_Store
3
3
  Guardfile
4
+ Gemfile.lock
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
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
- source 'http://gems.moneydesktop.com'
3
2
 
4
3
  gemspec
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/slide_rule.svg)](https://badge.fury.io/rb/slide_rule) [![Build Status](https://travis-ci.org/mattnichols/slide_rule.svg)](https://travis-ci.org/mattnichols/slide_rule)
2
+
1
3
  # SlideRule
2
4
  Ruby object distance calculator
3
5
 
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
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 :default => :spec
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
- if distance < threshold
31
- {
32
- item: item,
33
- distance: distance
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.inject(0.0) { |calculated_dist, dist| calculated_dist + dist }
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 = Date.parse(first) unless first.is_a?(::Date) || first.is_a?(::Time)
12
- second = Date.parse(second) unless second.is_a?(::Date) || second.is_a?(::Time)
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 = Date.parse(date_1) unless date_1.is_a?(::Date) || date_1.is_a?(::Time)
8
- date_2 = Date.parse(date_2) unless date_2.is_a?(::Date) || date_2.is_a?(::Time)
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 = Levee.distance(first, second).to_f
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
@@ -1,3 +1,3 @@
1
1
  module SlideRule
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/slide_rule.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'levenshtein'
2
+
1
3
  require_relative './slide_rule/version.rb'
2
4
  require_relative './slide_rule/distance_calculator.rb'
3
5
  require_relative './slide_rule/distance_calculators/day_of_month.rb'
data/slide_rule.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  ##
19
19
  # Dependencies
20
20
  #
21
- s.add_runtime_dependency 'levee', '~> 2'
21
+ s.add_runtime_dependency 'levenshtein', '~> 0.2'
22
22
 
23
23
  ##
24
24
  # Development Dependencies
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.1
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-02 00:00:00.000000000 Z
12
+ date: 2015-11-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: levee
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
- - ".rubocop_todo.yml"
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
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/slide_rulee/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in slide_rulee.gemspec
4
- gemspec
@@ -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
-
@@ -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
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here
@@ -1,3 +0,0 @@
1
- module SlideRulee
2
- VERSION = "0.1.0"
3
- end
@@ -1,5 +0,0 @@
1
- require "slide_rulee/version"
2
-
3
- module SlideRulee
4
- # Your code goes here...
5
- end
@@ -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
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SlideRulee do
4
- it 'has a version number' do
5
- expect(SlideRulee::VERSION).not_to be nil
6
- end
7
-
8
- it 'does something useful' do
9
- expect(false).to eq(true)
10
- end
11
- end
@@ -1,2 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require 'slide_rulee'
File without changes