scalar 0.2.0 → 1.0.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: 2982f2f0df447e30ec95f786453cc4e028e08e06
4
- data.tar.gz: a8243dc7371a7cd637755bb126c973a193246313
3
+ metadata.gz: 32eb0134d4c99f020e141199ff5f1d93f1d642e2
4
+ data.tar.gz: 84cc4ca441f700b121d44d267f57b1a7425ba873
5
5
  SHA512:
6
- metadata.gz: 4290e8e30e360aff32c4c25727b61210ea09cbae6f168757395f90b028c5769c76f9cf8ed9f6ae30c394d9d2bf74b243a0bc64d41d6c8e855d98f871a29d5531
7
- data.tar.gz: 0fb0077f48e007777a0b8d70edf16ed4ca80563fa49b9a81c6331508d31a64d7e4cab8ebc284f9a33f7597f3019c7db9e08be8ec0aa686d397a0a8b3a3839d14
6
+ metadata.gz: 1823f5d83a87bdead500e2bed59dd26b3fbe0b4c42d444a8965e55fbbb3407b9c49a9b2d6dca22090d6914c326c9bdca3bb1976c8e3ce9a5d00d488834d2905c
7
+ data.tar.gz: 21f62d9a0bf4e1f0cbdaadf0b167f8d5f29659f0f2738f4b86355f4532da52b38005ec2712d2072a8769aa82639ce37f056afc7d9f96cf82ae0fcf1c4ba41ca1
@@ -2,6 +2,8 @@ module Scalar
2
2
  module SupportClasses
3
3
  module Measurement
4
4
  include Comparable
5
+ extend Forwardable
6
+ def_delegators :scalar, :to_f, :to_i
5
7
 
6
8
  module ClassMethods
7
9
  def alias_map=(alias_map)
@@ -42,6 +44,7 @@ module Scalar
42
44
  end
43
45
 
44
46
  def -(other)
47
+ other = self.class.send(unit, 0) if other == 0
45
48
  if !other.is_a?(self.class)
46
49
  raise TypeError, "#{other.class} can't be coerced into #{self.class}"
47
50
  end
@@ -50,6 +53,7 @@ module Scalar
50
53
  end
51
54
 
52
55
  def +(other)
56
+ other = self.class.send(unit, 0) if other == 0
53
57
  if !other.is_a?(self.class)
54
58
  raise TypeError, "#{other.class} can't be coerced into #{self.class}"
55
59
  end
@@ -57,6 +61,22 @@ module Scalar
57
61
  self.class.send(unit, scalar + other.send(unit).scalar)
58
62
  end
59
63
 
64
+ def *(other)
65
+ if !other.is_a?(Numeric)
66
+ raise TypeError, "#{other.class} can't be coerced into #{scalar.class}"
67
+ end
68
+
69
+ self.class.send(unit, scalar * other)
70
+ end
71
+
72
+ def /(other)
73
+ if !other.is_a?(Numeric)
74
+ raise TypeError, "#{other.class} can't be coerced into #{scalar.class}"
75
+ end
76
+
77
+ self.class.send(unit, scalar / other)
78
+ end
79
+
60
80
  def initialize(scalar, unit)
61
81
  self.scalar = scalar.to_r
62
82
  self.unit = unit
@@ -69,6 +89,7 @@ module Scalar
69
89
 
70
90
  attr_reader :scalar
71
91
  alias abs scalar
92
+ alias to_r scalar
72
93
 
73
94
  protected
74
95
  attr_reader :unit
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Scalar
3
- VERSION = "0.2.0"
3
+ VERSION = "1.0.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scalar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Stannard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-26 00:00:00.000000000 Z
11
+ date: 2017-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler