metric_space 0.0.3 → 0.0.4

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: 95f9354064dfeae7662545c858ec8d79eff3ed0f
4
- data.tar.gz: 0fd387fe9dd38b09ce49e7fc0014e714adddb2cf
3
+ metadata.gz: d03c5cdd0bc4536fad6968870d78ccdc1daca528
4
+ data.tar.gz: c5104533d60cb21169acabb33650315bd5b81e00
5
5
  SHA512:
6
- metadata.gz: 2de743e7b27d341d314efb30fc4f3eeb700ef0784229c9e64be75f8efdea7fe89fcd1107313293c820fbcfc75e821d1f710e3e6e3f40e9192556c978add0f2db
7
- data.tar.gz: 054c788df5c2e646433c46c7df5e240a6b1b52cb900f67b776741940208ed79f589d0ed875ffe68772be081891ebdf387bb62b77b1c5a1b424b8e8c52a62254d
6
+ metadata.gz: befda889af180f0b9b56cccd68a9f69b29f3f940797f249fdcc629769796f8e7fc78539b9a6e80d81f556139ab6dc01894e5bcf86e3852c34261063a61c8b1ff
7
+ data.tar.gz: 2c720ea3751d1ac1c5373b1d95c1dd02ebf3f574f76884192560da747ed51caf96e4a66d8a28cd29c8ddbd63c73e605d666d5b2d836b27c6d1f8de6ebef6c1e2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
1
  ## v0.0.1
2
2
 
3
3
  * initial release
4
+
5
+ ## v0.0.4
6
+
7
+ * code clean up
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # MetricSpace [![Gem Version](https://badge.fury.io/rb/metric_space.png)](http://badge.fury.io/rb/metric_space) [![Build Status](https://travis-ci.org/fractalsoft/metric_space.png)](https://travis-ci.org/fractalsoft/metric_space) [![Dependency Status](https://gemnasium.com/fractalsoft/metric_space.png)](https://gemnasium.com/fractalsoft/metric_space) [![Coverage Status](https://coveralls.io/repos/fractalsoft/metric_space/badge.png)](https://coveralls.io/r/fractalsoft/metric_space)
1
+ # MetricSpace [![Gem Version](https://badge.fury.io/rb/metric_space.png)](http://badge.fury.io/rb/metric_space) [![Build Status](https://travis-ci.org/fractalsoft/metric_space.png)](https://travis-ci.org/fractalsoft/metric_space) [![Dependency Status](https://gemnasium.com/fractalsoft/metric_space.png)](https://gemnasium.com/fractalsoft/metric_space) [![Coverage Status](https://coveralls.io/repos/fractalsoft/metric_space/badge.png)](https://coveralls.io/r/fractalsoft/metric_space) [![Stories in Ready](https://badge.waffle.io/fractalsoft/metric_space.png)](http://waffle.io/fractalsoft/metric_space)
2
+
3
+ [![endorse](https://api.coderwall.com/torrocus/endorsecount.png)](https://coderwall.com/torrocus)
2
4
 
3
5
  Count distance between points in selected metric space
4
6
 
data/lib/metric_space.rb CHANGED
@@ -1,9 +1,6 @@
1
- require "metric_space/metric"
2
- require "metric_space/british_rail"
3
- require "metric_space/euclidean"
4
- require "metric_space/maximum"
5
- require "metric_space/taxicab"
6
- require "metric_space/version"
7
-
8
- module MetricSpace
9
- end
1
+ require 'metric_space/metric'
2
+ require 'metric_space/british_rail'
3
+ require 'metric_space/euclidean'
4
+ require 'metric_space/maximum'
5
+ require 'metric_space/taxicab'
6
+ require 'metric_space/version'
@@ -12,7 +12,7 @@ module MetricSpace
12
12
  # point2 = {a:-1.5, b:3.0, c:-1.5}
13
13
  # self.distance(point1, point2) #=> 9.353142959975042
14
14
  def self.distance(one, two)
15
- first, second = self.normalize(one), self.normalize(two)
15
+ first, second = normalize(one), normalize(two)
16
16
  if first == second
17
17
  Euclidean.distance(one, two)
18
18
  else
@@ -27,7 +27,7 @@ module MetricSpace
27
27
  def self.normalize(point)
28
28
  hash, max = point.dup, point.values.map(&:abs).max
29
29
  hash.each_pair do |index, value|
30
- hash[index] = value/max
30
+ hash[index] = value / max
31
31
  end
32
32
  hash
33
33
  end
@@ -1,7 +1,9 @@
1
1
  module MetricSpace
2
2
  # Difference between two values in one dimension
3
3
  class Metric
4
+
4
5
  protected
6
+
5
7
  # Count difference between two points in selected dimension
6
8
  def self.difference(one, two, index)
7
9
  ((one[index] || 0.0) - (two[index] || 0.0)).abs
@@ -1,6 +1,6 @@
1
1
  module MetricSpace
2
- # The name relates to the distance a taxi has to drive in a rectangular street
3
- # grid to get from the origin to the point x.
2
+ # The name relates to the distance a taxi has to drive in
3
+ # a rectangular street grid to get from the origin to the point x.
4
4
  class Taxicab
5
5
  # Distance between two points in taxicab metrics
6
6
  #
@@ -1,3 +1,4 @@
1
+ # Gem version
1
2
  module MetricSpace
2
- VERSION = "0.0.3"
3
+ VERSION = '0.0.4'
3
4
  end
@@ -1,51 +1,51 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe MetricSpace::BritishRail do
4
- let(:klass) { MetricSpace::BritishRail }
4
+ subject { MetricSpace::BritishRail }
5
5
 
6
- describe ".distance" do
6
+ describe '.distance' do
7
7
  [
8
8
  {
9
- point1: {a: 3.0, b: 4.0},
10
- point2: {a: 8.0, b: 6.0},
9
+ point1: { a: 3.0, b: 4.0 },
10
+ point2: { a: 8.0, b: 6.0 },
11
11
  distance: 15.0
12
12
  },
13
13
  {
14
- point1: {a: 3.0, c: 4.0},
15
- point2: {a: 8.0, b: 6.0},
14
+ point1: { a: 3.0, c: 4.0 },
15
+ point2: { a: 8.0, b: 6.0 },
16
16
  distance: 15.0
17
17
  },
18
18
  {
19
- point1: {a: 4.0, b: 3.0},
20
- point2: {a: 8.0, b: 6.0},
19
+ point1: { a: 4.0, b: 3.0 },
20
+ point2: { a: 8.0, b: 6.0 },
21
21
  distance: 5.0
22
22
  },
23
23
  {
24
- point1: {a: 4.0, b: -3.0},
25
- point2: {a: -8.0, b: 6.0},
24
+ point1: { a: 4.0, b: -3.0 },
25
+ point2: { a: -8.0, b: 6.0 },
26
26
  distance: 15.0
27
27
  },
28
28
  {
29
- point1: {a: -1.5, b: 1.5},
30
- point2: {a: 1.5, b: -1.5},
31
- distance: 3*(2.0**0.5)
29
+ point1: { a: -1.5, b: 1.5 },
30
+ point2: { a: 1.5, b: -1.5 },
31
+ distance: 3 * (2.0**0.5)
32
32
  },
33
33
  ].each do |example|
34
34
  point1, point2, distance = example.values
35
- it "should return #{distance} for distance between #{point1} and #{point2}" do
36
- klass.distance(point1, point2).round(5).should eq(distance.round(5))
35
+ it "is #{distance} between #{point1} and #{point2}" do
36
+ subject.distance(point1, point2).round(5).should eq(distance.round(5))
37
37
  end
38
38
  end
39
39
  end
40
40
 
41
- describe ".normalize" do
41
+ describe '.normalize' do
42
42
  {
43
- {a:2.0, b:1.0, c:0.5} => {a:1.0, b:0.5, c:0.25},
44
- {a:-2.0, b:4.0, c:-1.0} => {a:-0.5, b:1.0, c:-0.25}
43
+ { a: 2.0, b: 1.0, c: 0.5 } => { a: 1.0, b: 0.5, c: 0.25 },
44
+ { a: -2.0, b: 4.0, c: -1.0 } => { a: -0.5, b: 1.0, c: -0.25 }
45
45
  }.each_pair do |input, output|
46
46
  it "should return #{output} for #{input}" do
47
- klass.normalize({a:2.0, b:1.0, c:0.5}).should eq({a:1.0, b:0.5, c:0.25})
47
+ subject.normalize(input).should eq(output)
48
48
  end
49
49
  end
50
50
  end
51
- end
51
+ end
@@ -1,22 +1,23 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe MetricSpace::Euclidean do
4
- let(:klass) { MetricSpace::Euclidean }
4
+ subject { MetricSpace::Euclidean }
5
+
5
6
  [
6
7
  {
7
- point1: {a: 7.25, b: 8.5},
8
- point2: {a: 4.25, b: 4.5},
8
+ point1: { a: 7.25, b: 8.5 },
9
+ point2: { a: 4.25, b: 4.5 },
9
10
  distance: 5.0
10
11
  },
11
12
  {
12
- point1: {a: 0.5, c: 0.5},
13
- point2: {b: 0.4, c: 0.8},
13
+ point1: { a: 0.5, c: 0.5 },
14
+ point2: { b: 0.4, c: 0.8 },
14
15
  distance: 0.5**0.5
15
16
  }
16
17
  ].each do |example|
17
18
  point1, point2, distance = example.values
18
- it "should return #{distance} for distance between #{point1} and #{point2}" do
19
- klass.distance(point1, point2).round(5).should eq(distance.round(5))
19
+ it "is #{distance} between #{point1} and #{point2}" do
20
+ subject.distance(point1, point2).round(5).should eq(distance.round(5))
20
21
  end
21
22
  end
22
23
  end
@@ -1,22 +1,23 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe MetricSpace::Maximum do
4
- let(:klass) { MetricSpace::Maximum }
4
+ subject { MetricSpace::Maximum }
5
+
5
6
  [
6
7
  {
7
- point1: {a: 7.25, b: 8.5, c: 2.0},
8
- point2: {a: 4.25, b: 4.5, c: 7.0},
8
+ point1: { a: 7.25, b: 8.5, c: 2.0 },
9
+ point2: { a: 4.25, b: 4.5, c: 7.0 },
9
10
  distance: 5
10
11
  },
11
12
  {
12
- point1: {a: 0.3, c: 0.5},
13
- point2: {b: 0.8, c: 0.9},
13
+ point1: { a: 0.3, c: 0.5 },
14
+ point2: { b: 0.8, c: 0.9 },
14
15
  distance: 0.8
15
16
  }
16
17
  ].each do |example|
17
18
  point1, point2, distance = example.values
18
- it "should return #{distance} for distance between #{point1} and #{point2}" do
19
- klass.distance(point1, point2).round(5).should eq(distance)
19
+ it "is #{distance} between #{point1} and #{point2}" do
20
+ subject.distance(point1, point2).round(5).should eq(distance)
20
21
  end
21
22
  end
22
23
  end
@@ -1,22 +1,23 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe MetricSpace::Taxicab do
4
- let(:klass) { MetricSpace::Taxicab }
4
+ subject { MetricSpace::Taxicab }
5
+
5
6
  [
6
7
  {
7
- point1: {a: -0.25, b: 3.25, c: 0.8},
8
- point2: {a: 0.8, b: 1.25, c: 0.5},
8
+ point1: { a: -0.25, b: 3.25, c: 0.8 },
9
+ point2: { a: 0.8, b: 1.25, c: 0.5 },
9
10
  distance: 3.35
10
11
  },
11
12
  {
12
- point1: {a: 0.8, c: 0.5},
13
- point2: {b: 0.3, c: 1},
13
+ point1: { a: 0.8, c: 0.5 },
14
+ point2: { b: 0.3, c: 1 },
14
15
  distance: 1.6
15
16
  }
16
17
  ].each do |example|
17
18
  point1, point2, distance = example.values
18
- it "should return #{distance} for distance between #{point1} and #{point2}" do
19
- klass.distance(point1, point2).round(5).should eq(distance)
19
+ it "is #{distance} between #{point1} and #{point2}" do
20
+ subject.distance(point1, point2).round(5).should eq(distance)
20
21
  end
21
22
  end
22
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metric_space
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksander Malaszkiewicz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-27 00:00:00.000000000 Z
11
+ date: 2013-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler