unite_rb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +54 -0
  4. metadata +62 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec93ad7597fc5baf4922ea3e63a6050f3b3b0f23
4
+ data.tar.gz: 415f40c6eb1d7972dd44a99469b8276b61074b1a
5
+ SHA512:
6
+ metadata.gz: 630f4b61522c0ead33805d7b13b09cc3c04fef0b223709113ce17724088b48f94baf0f0de559e2daaf542f2610e68d28bfd247a4bbf102c6bd7689d4e6e7a974
7
+ data.tar.gz: fb8813c51786da75c5936cbc00a4972f1800d1a4e14afcf37b58d4f131fe711c45675d97cf1ba522b50db2e0535c63feebec7b9b9b4f50c4a3571038ba3490d3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Marcelo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,54 @@
1
+
2
+ # unite_rb
3
+
4
+ Brings units to numeric variables in Ruby.
5
+
6
+ ## Getting started
7
+
8
+ Install gem:
9
+
10
+ ```
11
+ gem install unite_rb
12
+ ```
13
+
14
+ Usage:
15
+
16
+ ```ruby
17
+ require "unite_rb"
18
+
19
+ s = UniteRb::Scope.new
20
+ s.dimensions = [:m, :km, :min, :s]
21
+
22
+ # Define relations between units using 'add', 'sub', 'mul', 'div'
23
+ s.equate(:km, s.mul(:m, 1000))
24
+ s.equate(:s, s.div(:min, 60))
25
+
26
+ dist_to_iss = s.var(408, :km)
27
+ dist_to_iss2 = s.var(408_000, :m)
28
+ time_to_sun = s.var(4, :min)
29
+
30
+ # Comparisons
31
+ dist_to_iss == dist_to_iss2 # => true
32
+ dist_to_iss > dist_to_iss2 # => false
33
+ dist_to_iss < time_to_sun # => UniteRb::UnrelatedDimensions: No relation exists between dimensions km and min
34
+
35
+ # Arithmetic
36
+ puts dist_to_iss + dist_to_iss2 # => 816 km
37
+
38
+ # Convert
39
+ time_to_sun_in_s = time_to_sun.convert(:s)
40
+ time_to_sun_in_s.dim # => s
41
+ puts time_to_sun_in_s # => 240 s
42
+ ```
43
+
44
+ ## To be done
45
+
46
+ - Allow dimensions to be multiplied to generate new dimensions (e.g. `s.div(:m, :s)`)
47
+ - Enable complex relations between units, for example:
48
+ ```ruby
49
+ s = UniteRb::Scope.new
50
+ s.dimensions = [:C, :F]
51
+
52
+ s.equate(:C, s.mul(5/9, s.sub(:F, 32))) # C = 5/9(F - 32)
53
+ ```
54
+
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unite_rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marcelo Pereira
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.4'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.4'
27
+ description: |-
28
+ This module enables attaching units to numeric variables. Relations between units can be specified,
29
+ which furthers allow variables with different units to be compared, and arithmetic operations to be performed on them.
30
+ email:
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE
36
+ - README.md
37
+ homepage: https://github.com/marcper/unite_rb
38
+ licenses:
39
+ - MIT
40
+ metadata:
41
+ source_code_uri: https://github.com/marcper/unite_rb
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.5.2
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Bring units to Ruby variables
62
+ test_files: []