distance 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 687cc209435ce9c3846923b3e45bbcf93a98657b
4
- data.tar.gz: 420b0b31cb846bf09e18d6cdf5a2d450351ac5de
3
+ metadata.gz: 5d123ba2ed9a2734083d1cb3d7fd722af9e327f8
4
+ data.tar.gz: fbf75d9780f99dc8bcf72ab3f3c76514921cfb80
5
5
  SHA512:
6
- metadata.gz: 5330a178f261c0f5e1e353297d236b99179552d68e2d567bc54c1a41657b7f88bc7ba470ac32bebec37f3ed37e7ac4e98c6b4722f679b60b676a1e0741b6877b
7
- data.tar.gz: 4429e65174098ffd8e237cdb9b27d8a9bdf53baab47ac1ea94f0e0686cc9da3e157d420a00625e6108152d13d9d035c62885f249d8f6134b128cd69eea33165f
6
+ metadata.gz: 1d7f03ddadf2fc1fee516a4fccdfabfa5182b774dc0cb9ea82697297c794ef9c40446015151543064d91d7df4bb7579f5cb9c10e66f72672ebcdb60ee12e8ee9
7
+ data.tar.gz: 1fac374e015221e06e6304dc1513058826cf85f7892653288d8f5bf3ef60386c4cb6a1dd556b0609207bdb0381627f55d5cf6e86b9fa466c1b4b638052df260a
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/tcollier/distance.svg?branch=master)](https://travis-ci.org/tcollier/distance)
2
+
1
3
  # Distance
2
4
 
3
5
  Convenience methods for using distances
@@ -70,6 +72,25 @@ Distance.miles(10) <= Distance.kilometers(10)
70
72
  # => false
71
73
  ```
72
74
 
75
+ ### Numeric core extensions
76
+
77
+ You can optionally enable core extensions to `Float` and `Integer` by
78
+
79
+ ```ruby
80
+ require 'distance/core_ext'
81
+ ```
82
+
83
+ This adds the following convenience methods to `Float` and `Integer`
84
+
85
+ ```ruby
86
+ 26.2.miles
87
+ # => Distance.miles(26.2)
88
+ 1.kilometer
89
+ # => Distance.kilometers(1)
90
+ 5 * Distance.new(1000)
91
+ # => Distance.new(5000)
92
+ ```
93
+
73
94
  ## Development
74
95
 
75
96
  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.
@@ -0,0 +1,7 @@
1
+ class Float
2
+ alias_method :orig_multiply, :*
3
+
4
+ def *(other)
5
+ other.is_a?(Distance) ? other * self : orig_multiply(other)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class Integer
2
+ alias_method :orig_multiply, :*
3
+
4
+ def *(other)
5
+ other.is_a?(Distance) ? other * self : orig_multiply(other)
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ class Numeric
2
+ def kilometers
3
+ Distance.kilometers(self)
4
+ end
5
+
6
+ alias_method :kilometer, :kilometers
7
+
8
+ def miles
9
+ Distance.miles(self)
10
+ end
11
+
12
+ alias_method :mile, :miles
13
+ end
@@ -0,0 +1,3 @@
1
+ require_relative 'core_ext/float'
2
+ require_relative 'core_ext/integer'
3
+ require_relative 'core_ext/numeric'
@@ -1,3 +1,3 @@
1
1
  class Distance
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: distance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Collier
@@ -85,7 +85,10 @@ files:
85
85
  - bin/setup
86
86
  - distance.gemspec
87
87
  - lib/distance.rb
88
- - lib/distance/fixnum_extensions.rb
88
+ - lib/distance/core_ext.rb
89
+ - lib/distance/core_ext/float.rb
90
+ - lib/distance/core_ext/integer.rb
91
+ - lib/distance/core_ext/numeric.rb
89
92
  - lib/distance/version.rb
90
93
  homepage: https://github.com/tcollier/distance
91
94
  licenses:
@@ -1 +0,0 @@
1
- require_relative '../core_ext/numeric'