auom 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/.rubocop.yml +2 -6
- data/.travis.yml +5 -2
- data/Changelog.md +5 -1
- data/Gemfile +0 -5
- data/README.md +17 -22
- data/TODO +1 -1
- data/auom.gemspec +14 -14
- data/circle.yml +3 -0
- data/config/flay.yml +1 -1
- data/config/flog.yml +1 -1
- data/config/reek.yml +2 -1
- data/config/rubocop.yml +130 -34
- data/lib/auom.rb +0 -2
- data/lib/auom/algebra.rb +5 -7
- data/lib/auom/equalization.rb +0 -2
- data/lib/auom/inspection.rb +26 -23
- data/lib/auom/relational.rb +2 -4
- data/lib/auom/unit.rb +15 -17
- data/spec/shared/incompatible_operation_behavior.rb +0 -2
- data/spec/shared/operation_behavior.rb +5 -4
- data/spec/shared/sunits_shared.rb +0 -2
- data/spec/spec_helper.rb +1 -4
- data/spec/unit/auom/algebra/add_spec.rb +12 -16
- data/spec/unit/auom/algebra/divide_spec.rb +50 -52
- data/spec/unit/auom/algebra/multiply_spec.rb +17 -21
- data/spec/unit/auom/algebra/substract_spec.rb +4 -8
- data/spec/unit/auom/equalization/equality_operator_spec.rb +3 -7
- data/spec/unit/auom/inspection/class_methods/prettify_unit_part_spec.rb +7 -7
- data/spec/unit/auom/inspection/inspect_spec.rb +1 -5
- data/spec/unit/auom/relational/greater_than_or_equal_to_predicate_spec.rb +0 -4
- data/spec/unit/auom/relational/greater_than_predicate_spec.rb +0 -4
- data/spec/unit/auom/relational/less_than_or_equal_to_predicate_spec.rb +0 -4
- data/spec/unit/auom/relational/less_than_predicate_spec.rb +0 -4
- data/spec/unit/auom/unit/assert_same_unit_spec.rb +2 -6
- data/spec/unit/auom/unit/class_methods/convert_spec.rb +0 -4
- data/spec/unit/auom/unit/class_methods/lookup_spec.rb +2 -6
- data/spec/unit/auom/unit/class_methods/new_spec.rb +16 -21
- data/spec/unit/auom/unit/class_methods/try_convert_spec.rb +0 -4
- data/spec/unit/auom/unit/class_methods/units_spec.rb +0 -4
- data/spec/unit/auom/unit/denominators_spec.rb +0 -4
- data/spec/unit/auom/unit/numerators_spec.rb +0 -4
- data/spec/unit/auom/unit/same_unit_predicate_spec.rb +1 -5
- data/spec/unit/auom/unit/scalar_spec.rb +0 -4
- data/spec/unit/auom/unit/unit_spec.rb +0 -4
- data/spec/unit/auom/unit/unitless_predicate_spec.rb +0 -4
- metadata +29 -22
- data/Gemfile.devtools +0 -71
- data/Guardfile +0 -8
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0052fcab4f594eaadb81ddb9c50b5383a1f6ccbe
|
4
|
+
data.tar.gz: 7dee775c276bad51bfa0b8a926b022278f2c008b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 010b60063558dc2268e38fd1af143492334a37f45a5613e52bfb052a2bee8337305ff1df52ebf5ec8d35aca7db1d92185ca6b7fa9f10aba0aef1d12a75f037c8
|
7
|
+
data.tar.gz: 4db585b70f9db889c5ff9e39a1afb4793bec6d3d62e2dd710661d29711af67c3b3cbb0874a98057b3ad3675755bc1cbed0969d3cae570050a29c6f0ab06b5067
|
data/.rspec
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/Changelog.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# v0.2.0 2017-09-29
|
2
|
+
|
3
|
+
* [breaking-change] Drop support for < 2.4
|
4
|
+
|
1
5
|
# v0.1.0 2014-03-24
|
2
6
|
|
3
7
|
* [breaking-change] Drop support for 1.8
|
@@ -12,7 +16,7 @@
|
|
12
16
|
|
13
17
|
# v0.0.4 2012-11-20
|
14
18
|
|
15
|
-
* [feature] Support for relational
|
19
|
+
* [feature] Support for relational operators >, <, >= and <=
|
16
20
|
|
17
21
|
[Compare v0.0.3..v0.0.4](https://github.com/mbj/auom/compare/v0.0.3...v0.0.4)
|
18
22
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
AUOM Algebra (for) Units of
|
1
|
+
AUOM Algebra (for) Units of Measurement
|
2
2
|
=======================================
|
3
3
|
|
4
4
|
[![Build Status](https://secure.travis-ci.org/mbj/auom.png?branch=master)](http://travis-ci.org/mbj/auom)
|
@@ -6,7 +6,7 @@ AUOM Algebra (for) Units of Measuerment
|
|
6
6
|
[![Code Climate](https://codeclimate.com/github/mbj/auom.png)](https://codeclimate.com/github/mbj/auom)
|
7
7
|
|
8
8
|
This is another unit system for ruby.
|
9
|
-
It was created since I was not confident about the existing
|
9
|
+
It was created since I was not confident about the existing ones.
|
10
10
|
|
11
11
|
Features:
|
12
12
|
|
@@ -17,38 +17,33 @@ Features:
|
|
17
17
|
* No magic coercion from number like strings to numbers.
|
18
18
|
* Will never loose precision (Uses rational as scalar internally)
|
19
19
|
* Allows namespacing of unit systems via subclass.
|
20
|
-
* Well tested (100%
|
20
|
+
* Well tested (100% mutation coverage via [mutant](https://github.com/mbj/mutant))
|
21
21
|
|
22
|
-
The default set of predefined units is
|
23
|
-
specific subclass. Override: ```
|
22
|
+
The default set of predefined units is minimal as this library should be used in an application
|
23
|
+
specific subclass. Override: ```AUOM::Unit.units```
|
24
24
|
|
25
25
|
Installation
|
26
26
|
------------
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
``` ruby
|
31
|
-
gem 'auom', :git => 'https://github.com/mbj/auom'
|
32
|
-
```
|
28
|
+
Install the gem `auom` via your preferred method.
|
33
29
|
|
34
30
|
Examples
|
35
31
|
--------
|
36
32
|
|
37
33
|
``` ruby
|
38
|
-
|
39
|
-
# Create a unit
|
40
34
|
require 'auom'
|
41
35
|
|
42
36
|
include AUOM
|
43
37
|
|
44
|
-
u = Unit.new(1,
|
45
|
-
u * 100
|
46
|
-
u / Unit.new(10
|
47
|
-
u
|
48
|
-
u * Unit.new(
|
49
|
-
u
|
50
|
-
u
|
51
|
-
u + Unit.new(1,
|
38
|
+
u = Unit.new(1, :meter) # <AUOM::Unit @scalar=1 meter>
|
39
|
+
u * 100 # <AUOM::Unit @scalar=100 meter>
|
40
|
+
u / Unit.new(10, :meter) # <AUOM::Unit @scalar=0.1>
|
41
|
+
u / Unit.new(10, [ :meter, :meter ]) # <AUOM::Unit @scaler=0.1 1/meter>
|
42
|
+
u * Unit.new(10, :meter) # <AUOM::Unit @scalar=10 meter^2>
|
43
|
+
u * Unit.new(1, :euro) # <AUOM::Unit @scalar=1 euro*meter>
|
44
|
+
u - Unit.new(1, :meter) # <AUOM::Unit @scalar=0 meter>
|
45
|
+
u + Unit.new(1, :meter) # <AUOM::Unit @scalar=2 meter>
|
46
|
+
u + Unit.new(1, :euro) # raises error about incompatible units
|
52
47
|
```
|
53
48
|
|
54
49
|
Credits
|
@@ -70,6 +65,6 @@ Contributing
|
|
70
65
|
Copyright
|
71
66
|
---------
|
72
67
|
|
73
|
-
Copyright (c)
|
68
|
+
Copyright (c) 2014 Markus Schirp
|
74
69
|
|
75
|
-
See LICENSE for details
|
70
|
+
See `LICENSE` for details
|
data/TODO
CHANGED
@@ -1 +1 @@
|
|
1
|
-
* Make
|
1
|
+
* Make built-in units configurable
|
data/auom.gemspec
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = 'auom'
|
3
|
+
gem.version = '0.2.0'
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
gem.authors = ['Markus Schirp']
|
6
|
+
gem.email = 'mbj@schirp-dso.com'
|
7
|
+
gem.summary = 'Algebra (with) Units Of Measurement'
|
8
|
+
gem.homepage = 'http://github.com/mbj/auom'
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
gem.files = `git ls-files`.split("\n")
|
11
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
12
|
+
gem.require_paths = %w[lib]
|
13
|
+
gem.extra_rdoc_files = %w[TODO LICENSE]
|
11
14
|
|
12
|
-
|
13
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
-
s.require_paths = %w(lib)
|
15
|
-
s.extra_rdoc_files = %w(TODO LICENSE)
|
15
|
+
gem.required_ruby_version = '>= 2.4'
|
16
16
|
|
17
|
-
|
17
|
+
gem.add_dependency('equalizer', '~> 0.0.9')
|
18
18
|
|
19
|
-
|
19
|
+
gem.add_development_dependency('devtools', '~> 0.1.12')
|
20
20
|
end
|
data/circle.yml
CHANGED
data/config/flay.yml
CHANGED
data/config/flog.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
---
|
2
|
-
threshold:
|
2
|
+
threshold: 15.1
|
data/config/reek.yml
CHANGED
@@ -55,7 +55,8 @@ NestedIterators:
|
|
55
55
|
TooManyStatements:
|
56
56
|
max_statements: 6
|
57
57
|
exclude:
|
58
|
-
-
|
58
|
+
- AUOM::Inspection#pretty_unit # 7 statements
|
59
|
+
- AUOM::Unit#initialize # 8 statements
|
59
60
|
enabled: true
|
60
61
|
DuplicateMethodCall:
|
61
62
|
allow_calls: []
|
data/config/rubocop.yml
CHANGED
@@ -1,18 +1,5 @@
|
|
1
1
|
inherit_from: ../.rubocop.yml
|
2
2
|
|
3
|
-
# General note about rubocop.
|
4
|
-
# It does NOT allow to silence a specific rule violation.
|
5
|
-
# For that reason I sometimes have to disable a whole cop where
|
6
|
-
# I just tried to whitelist a specific occurence.
|
7
|
-
|
8
|
-
|
9
|
-
AllCops:
|
10
|
-
Includes:
|
11
|
-
- '../**/*.rake'
|
12
|
-
- 'Gemfile'
|
13
|
-
- 'Gemfile.triage'
|
14
|
-
- 'mutant.gemspec'
|
15
|
-
|
16
3
|
# Avoid parameter lists longer than five parameters.
|
17
4
|
ParameterLists:
|
18
5
|
Max: 3
|
@@ -24,27 +11,36 @@ BlockNesting:
|
|
24
11
|
|
25
12
|
# Align with the style guide.
|
26
13
|
CollectionMethods:
|
14
|
+
Enabled: true
|
27
15
|
PreferredMethods:
|
28
16
|
collect: 'map'
|
29
17
|
inject: 'reduce'
|
30
18
|
find: 'detect'
|
31
19
|
find_all: 'select'
|
32
20
|
|
33
|
-
|
34
|
-
|
35
|
-
Max: 17 # TODO: Bring down to 10
|
36
|
-
|
37
|
-
RegexpLiteral: # I do not agree %r(\A) is more readable than /\A/
|
38
|
-
Enabled: false
|
21
|
+
AccessModifierIndentation:
|
22
|
+
EnforcedStyle: outdent
|
39
23
|
|
40
24
|
# Limit line length
|
41
25
|
LineLength:
|
42
|
-
Max:
|
26
|
+
Max: 120
|
43
27
|
|
44
28
|
# Disable documentation checking until a class needs to be documented once
|
45
29
|
Documentation:
|
46
30
|
Enabled: false
|
47
31
|
|
32
|
+
# Permit
|
33
|
+
#
|
34
|
+
# boolean_check? or fail
|
35
|
+
#
|
36
|
+
# Reject
|
37
|
+
#
|
38
|
+
# if foo or bar
|
39
|
+
# ...
|
40
|
+
# end
|
41
|
+
AndOr:
|
42
|
+
EnforcedStyle: conditionals
|
43
|
+
|
48
44
|
# Do not favor modifier if/unless usage when you have a single-line body
|
49
45
|
IfUnlessModifier:
|
50
46
|
Enabled: false
|
@@ -61,29 +57,129 @@ ConstantName:
|
|
61
57
|
TrivialAccessors:
|
62
58
|
Enabled: false
|
63
59
|
|
64
|
-
#
|
65
|
-
|
60
|
+
# Allow empty lines around class body
|
61
|
+
EmptyLinesAroundClassBody:
|
66
62
|
Enabled: false
|
67
63
|
|
68
|
-
#
|
69
|
-
|
64
|
+
# Allow empty lines around module body
|
65
|
+
EmptyLinesAroundModuleBody:
|
66
|
+
Enabled: false
|
67
|
+
|
68
|
+
# Allow empty lines around block body
|
69
|
+
EmptyLinesAroundBlockBody:
|
70
70
|
Enabled: false
|
71
71
|
|
72
|
-
#
|
73
|
-
|
72
|
+
# Allow multiple line operations to not require indentation
|
73
|
+
MultilineOperationIndentation:
|
74
74
|
Enabled: false
|
75
75
|
|
76
|
-
|
77
|
-
|
76
|
+
# Prefer String#% over Kernel#sprintf
|
77
|
+
FormatString:
|
78
|
+
EnforcedStyle: format
|
79
|
+
|
80
|
+
# Use square brackets for literal Array objects
|
81
|
+
PercentLiteralDelimiters:
|
82
|
+
PreferredDelimiters:
|
83
|
+
'%': '{}'
|
84
|
+
'%i': '[]'
|
85
|
+
'%q': ()
|
86
|
+
'%Q': ()
|
87
|
+
'%r': '{}'
|
88
|
+
'%s': ()
|
89
|
+
'%w': '[]'
|
90
|
+
'%W': '[]'
|
91
|
+
'%x': ()
|
92
|
+
|
93
|
+
# Use %i[...] for arrays of symbols
|
94
|
+
SymbolArray:
|
95
|
+
Enabled: true
|
96
|
+
|
97
|
+
# Align if/else blocks with the variable assignment
|
98
|
+
EndAlignment:
|
99
|
+
EnforcedStyleAlignWith: variable
|
100
|
+
|
101
|
+
# Prefer #kind_of? over #is_a?
|
102
|
+
ClassCheck:
|
103
|
+
EnforcedStyle: kind_of?
|
104
|
+
|
105
|
+
# Do not prefer double quotes to be used when %q or %Q is more appropriate
|
106
|
+
UnneededPercentQ:
|
107
|
+
Enabled: false
|
108
|
+
|
109
|
+
# Allow a maximum ABC score
|
110
|
+
Metrics/AbcSize:
|
111
|
+
Max: 21.02
|
78
112
|
|
79
|
-
|
80
|
-
IndentationWidth:
|
113
|
+
Metrics/BlockLength:
|
81
114
|
Enabled: false
|
82
115
|
|
83
|
-
#
|
84
|
-
|
116
|
+
# Do not prefer lambda.call(...) over lambda.(...)
|
117
|
+
LambdaCall:
|
85
118
|
Enabled: false
|
86
119
|
|
87
|
-
#
|
88
|
-
|
120
|
+
# Buggy cop, returns false positive for our code base
|
121
|
+
NonLocalExitFromIterator:
|
122
|
+
Enabled: false
|
123
|
+
|
124
|
+
# To allow alignment of similar expressions we want to allow more than one
|
125
|
+
# space around operators:
|
126
|
+
#
|
127
|
+
# let(:a) { bar + something }
|
128
|
+
# let(:b) { foobar + something }
|
129
|
+
#
|
130
|
+
SpaceAroundOperators:
|
131
|
+
Enabled: false
|
132
|
+
|
133
|
+
# We use parallel assignments with great success
|
134
|
+
ParallelAssignment:
|
135
|
+
Enabled: false
|
136
|
+
|
137
|
+
# Allow additional specs
|
138
|
+
ExtraSpacing:
|
139
|
+
AllowForAlignment: true
|
140
|
+
|
141
|
+
# Buggy
|
142
|
+
FormatParameterMismatch:
|
143
|
+
Enabled: false
|
144
|
+
|
145
|
+
# Different preference
|
146
|
+
SignalException:
|
147
|
+
EnforcedStyle: semantic
|
148
|
+
|
149
|
+
# Do not use `alias`
|
150
|
+
Alias:
|
151
|
+
EnforcedStyle: prefer_alias_method
|
152
|
+
|
153
|
+
# Teaching people to ignore singleton class is pointless
|
154
|
+
RedundantFreeze:
|
155
|
+
Enabled: false
|
156
|
+
|
157
|
+
# Do not waste my horizontal or vertical space
|
158
|
+
IndentArray:
|
159
|
+
Enabled: false
|
160
|
+
|
161
|
+
# Prefer
|
162
|
+
#
|
163
|
+
# some_receiver
|
164
|
+
# .foo
|
165
|
+
# .bar
|
166
|
+
# .baz
|
167
|
+
#
|
168
|
+
# Over
|
169
|
+
#
|
170
|
+
# some_receiver.foo
|
171
|
+
# .bar
|
172
|
+
# .baz
|
173
|
+
MultilineMethodCallIndentation:
|
174
|
+
EnforcedStyle: indented
|
175
|
+
|
176
|
+
# Align keys and values in a multiline hash
|
177
|
+
AlignHash:
|
178
|
+
EnforcedColonStyle: table
|
179
|
+
|
180
|
+
# Prefer `public_send` and `__send__` over `send`
|
181
|
+
Send:
|
182
|
+
Enabled: true
|
183
|
+
|
184
|
+
Lint/UnifiedInteger:
|
89
185
|
Enabled: false
|
data/lib/auom.rb
CHANGED
data/lib/auom/algebra.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
1
|
module AUOM
|
4
2
|
# The AUOM algebra
|
5
3
|
module Algebra
|
@@ -31,7 +29,7 @@ module AUOM
|
|
31
29
|
|
32
30
|
alias_method :+, :add
|
33
31
|
|
34
|
-
# Return
|
32
|
+
# Return subtraction result
|
35
33
|
#
|
36
34
|
# @param [Object] operand
|
37
35
|
#
|
@@ -50,11 +48,11 @@ module AUOM
|
|
50
48
|
#
|
51
49
|
# @api public
|
52
50
|
#
|
53
|
-
def
|
51
|
+
def subtract(operand)
|
54
52
|
add(operand * -1)
|
55
53
|
end
|
56
54
|
|
57
|
-
alias_method :-, :
|
55
|
+
alias_method :-, :subtract
|
58
56
|
|
59
57
|
# Return multiplication result
|
60
58
|
#
|
@@ -70,7 +68,7 @@ module AUOM
|
|
70
68
|
# # with unit
|
71
69
|
# Unit.new(2, :meter) * Unit.new(1, :meter) # => <AUOM::Unit @scalar=2 meter^2>
|
72
70
|
#
|
73
|
-
# #
|
71
|
+
# # different units
|
74
72
|
# Unit.new(2, :meter) * Unit.new(1, :euro) # => <AUOM::Unit @scalar=2 meter*euro>
|
75
73
|
#
|
76
74
|
# @api public
|
@@ -102,7 +100,7 @@ module AUOM
|
|
102
100
|
# # with unit
|
103
101
|
# Unit.new(2, :meter) / Unit.new(1, :meter) # => <AUOM::Unit @scalar=2>
|
104
102
|
#
|
105
|
-
# #
|
103
|
+
# # different units
|
106
104
|
# Unit.new(2, :meter) / Unit.new(1, :euro) # => <AUOM::Unit @scalar=2 meter/euro>
|
107
105
|
#
|
108
106
|
# @api public
|