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 +4 -4
- data/lib/scalar/support_classes/measurement.rb +21 -0
- data/lib/scalar/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32eb0134d4c99f020e141199ff5f1d93f1d642e2
|
4
|
+
data.tar.gz: 84cc4ca441f700b121d44d267f57b1a7425ba873
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/scalar/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2017-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|