lite-measurements 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +17 -3
- data/.travis.yml +1 -0
- data/CHANGELOG.md +21 -0
- data/Gemfile.lock +81 -70
- data/README.md +18 -4
- data/lib/generators/lite/measurements/install_generator.rb +0 -2
- data/lib/generators/lite/measurements/templates/install.rb +9 -3
- data/lib/lite/measurements.rb +9 -13
- data/lib/lite/measurements/digital_storage.rb +8 -3
- data/lib/lite/measurements/helpers/conversion_helper.rb +4 -4
- data/lib/lite/measurements/length.rb +18 -8
- data/lib/lite/measurements/mass.rb +19 -8
- data/lib/lite/measurements/monkey_patches.rb +5 -17
- data/lib/lite/measurements/monkey_patches/digital_storage.rb +9 -0
- data/lib/lite/measurements/monkey_patches/length.rb +9 -0
- data/lib/lite/measurements/monkey_patches/mass.rb +9 -0
- data/lib/lite/measurements/monkey_patches/temperature.rb +9 -0
- data/lib/lite/measurements/monkey_patches/time.rb +9 -0
- data/lib/lite/measurements/temperature.rb +5 -5
- data/lib/lite/measurements/time.rb +11 -4
- data/lib/lite/measurements/version.rb +1 -1
- data/lite-measurements.gemspec +2 -1
- metadata +26 -8
- data/lib/lite/measurements/configuration.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c03231a244a23709daa52499d7ec9ecad0233139eb8882ada2f8f3167411a47b
|
4
|
+
data.tar.gz: 281405d760c0a9da7a85a788c3ae648a2ade4b7cffa64f5da692389624904db6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f5820c8c673b2da8c9efd0b6572f2590d7a72a1c38b816c6c5333f00a73b983675c145f5702554f7e00c6e31795d0cd8ae1b564aa005d5ad570312881b5f9e3
|
7
|
+
data.tar.gz: 99829fc29512c0844c00e10459dfc1fd2785a72d655cd3e83e68b3838718fb5aa51685f888769daab32f7050c74ac3d68f5bc24cc4c725d2dd7212a307b7e165
|
data/.rubocop.yml
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
require:
|
2
2
|
- rubocop-performance
|
3
|
+
- rubocop-rake
|
3
4
|
- rubocop-rspec
|
4
5
|
AllCops:
|
5
|
-
TargetRubyVersion:
|
6
|
+
TargetRubyVersion: 3.0
|
7
|
+
NewCops: enable
|
6
8
|
DisplayCopNames: true
|
7
9
|
DisplayStyleGuide: true
|
8
|
-
|
9
|
-
|
10
|
+
Gemspec/RequiredRubyVersion:
|
11
|
+
Enabled: false
|
12
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
13
|
+
Enabled: true
|
10
14
|
Layout/EmptyLinesAroundBlockBody:
|
11
15
|
Exclude:
|
12
16
|
- 'spec/**/**/*'
|
@@ -14,10 +18,20 @@ Layout/EmptyLinesAroundClassBody:
|
|
14
18
|
EnforcedStyle: empty_lines_except_namespace
|
15
19
|
Layout/EmptyLinesAroundModuleBody:
|
16
20
|
EnforcedStyle: empty_lines_except_namespace
|
21
|
+
Layout/LineLength:
|
22
|
+
Max: 100
|
23
|
+
Layout/SpaceAroundMethodCallOperator:
|
24
|
+
Enabled: true
|
25
|
+
Lint/RaiseException:
|
26
|
+
Enabled: true
|
27
|
+
Lint/StructNewOverride:
|
28
|
+
Enabled: true
|
17
29
|
Metrics/BlockLength:
|
18
30
|
Exclude:
|
19
31
|
- 'spec/**/**/*'
|
20
32
|
- '*.gemspec'
|
33
|
+
Style/ArgumentsForwarding:
|
34
|
+
Enabled: false
|
21
35
|
Style/Documentation:
|
22
36
|
Enabled: false
|
23
37
|
Style/ExpandPathArguments:
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [2.0.0] - 2021-07-22
|
10
|
+
### Changed
|
11
|
+
- Improved setup
|
12
|
+
- Update install generator to reflect configuration changes
|
13
|
+
### Removed
|
14
|
+
- Removed configuration to use explicit inclusions
|
15
|
+
|
16
|
+
## [1.1.1] - 2021-07-21
|
17
|
+
### Changed
|
18
|
+
- Improved Railtie support
|
19
|
+
|
20
|
+
## [1.1.0] - 2021-07-19
|
21
|
+
### Added
|
22
|
+
- Added Ruby 3.0 support
|
23
|
+
|
24
|
+
## [1.0.2] - 2019-08-24
|
25
|
+
### Added
|
26
|
+
- Added ruby 2.7 support
|
27
|
+
### Changed
|
28
|
+
- Improved how configuration works
|
29
|
+
|
9
30
|
## [1.0.1] - 2019-08-17
|
10
31
|
### Changed
|
11
32
|
- Add check for monkey patches
|
data/Gemfile.lock
CHANGED
@@ -1,107 +1,117 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lite-measurements (
|
4
|
+
lite-measurements (2.0.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
actionpack (6.
|
10
|
-
actionview (= 6.
|
11
|
-
activesupport (= 6.
|
12
|
-
rack (~> 2.0)
|
9
|
+
actionpack (6.1.4)
|
10
|
+
actionview (= 6.1.4)
|
11
|
+
activesupport (= 6.1.4)
|
12
|
+
rack (~> 2.0, >= 2.0.9)
|
13
13
|
rack-test (>= 0.6.3)
|
14
14
|
rails-dom-testing (~> 2.0)
|
15
15
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
16
|
-
actionview (6.
|
17
|
-
activesupport (= 6.
|
16
|
+
actionview (6.1.4)
|
17
|
+
activesupport (= 6.1.4)
|
18
18
|
builder (~> 3.1)
|
19
19
|
erubi (~> 1.4)
|
20
20
|
rails-dom-testing (~> 2.0)
|
21
21
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
22
|
-
activesupport (6.
|
22
|
+
activesupport (6.1.4)
|
23
23
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
24
|
-
i18n (>=
|
25
|
-
minitest (
|
26
|
-
tzinfo (~>
|
27
|
-
zeitwerk (~> 2.
|
28
|
-
ast (2.4.
|
29
|
-
builder (3.2.
|
24
|
+
i18n (>= 1.6, < 2)
|
25
|
+
minitest (>= 5.1)
|
26
|
+
tzinfo (~> 2.0)
|
27
|
+
zeitwerk (~> 2.3)
|
28
|
+
ast (2.4.2)
|
29
|
+
builder (3.2.4)
|
30
30
|
colorize (0.8.1)
|
31
|
-
concurrent-ruby (1.1.
|
32
|
-
crass (1.0.
|
33
|
-
diff-lcs (1.
|
34
|
-
erubi (1.
|
35
|
-
fasterer (0.
|
31
|
+
concurrent-ruby (1.1.9)
|
32
|
+
crass (1.0.6)
|
33
|
+
diff-lcs (1.4.4)
|
34
|
+
erubi (1.10.0)
|
35
|
+
fasterer (0.9.0)
|
36
36
|
colorize (~> 0.7)
|
37
|
-
ruby_parser (>= 3.
|
37
|
+
ruby_parser (>= 3.14.1)
|
38
38
|
generator_spec (0.9.4)
|
39
39
|
activesupport (>= 3.0.0)
|
40
40
|
railties (>= 3.0.0)
|
41
|
-
i18n (1.
|
41
|
+
i18n (1.8.10)
|
42
42
|
concurrent-ruby (~> 1.0)
|
43
|
-
|
44
|
-
loofah (2.2.3)
|
43
|
+
loofah (2.10.0)
|
45
44
|
crass (~> 1.0.2)
|
46
45
|
nokogiri (>= 1.5.9)
|
47
|
-
method_source (0.
|
48
|
-
mini_portile2 (2.
|
49
|
-
minitest (5.
|
50
|
-
nokogiri (1.
|
51
|
-
mini_portile2 (~> 2.
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
46
|
+
method_source (1.0.0)
|
47
|
+
mini_portile2 (2.5.3)
|
48
|
+
minitest (5.14.4)
|
49
|
+
nokogiri (1.11.7)
|
50
|
+
mini_portile2 (~> 2.5.0)
|
51
|
+
racc (~> 1.4)
|
52
|
+
parallel (1.20.1)
|
53
|
+
parser (3.0.2.0)
|
54
|
+
ast (~> 2.4.1)
|
55
|
+
racc (1.5.2)
|
56
|
+
rack (2.2.3)
|
56
57
|
rack-test (1.1.0)
|
57
58
|
rack (>= 1.0, < 3)
|
58
59
|
rails-dom-testing (2.0.3)
|
59
60
|
activesupport (>= 4.2.0)
|
60
61
|
nokogiri (>= 1.6)
|
61
|
-
rails-html-sanitizer (1.
|
62
|
-
loofah (~> 2.
|
63
|
-
railties (6.
|
64
|
-
actionpack (= 6.
|
65
|
-
activesupport (= 6.
|
62
|
+
rails-html-sanitizer (1.3.0)
|
63
|
+
loofah (~> 2.3)
|
64
|
+
railties (6.1.4)
|
65
|
+
actionpack (= 6.1.4)
|
66
|
+
activesupport (= 6.1.4)
|
66
67
|
method_source
|
67
|
-
rake (>= 0.
|
68
|
-
thor (
|
68
|
+
rake (>= 0.13)
|
69
|
+
thor (~> 1.0)
|
69
70
|
rainbow (3.0.0)
|
70
|
-
rake (
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
rspec-
|
75
|
-
|
76
|
-
rspec-
|
77
|
-
rspec-
|
71
|
+
rake (13.0.6)
|
72
|
+
regexp_parser (2.1.1)
|
73
|
+
rexml (3.2.5)
|
74
|
+
rspec (3.10.0)
|
75
|
+
rspec-core (~> 3.10.0)
|
76
|
+
rspec-expectations (~> 3.10.0)
|
77
|
+
rspec-mocks (~> 3.10.0)
|
78
|
+
rspec-core (3.10.1)
|
79
|
+
rspec-support (~> 3.10.0)
|
80
|
+
rspec-expectations (3.10.1)
|
78
81
|
diff-lcs (>= 1.2.0, < 2.0)
|
79
|
-
rspec-support (~> 3.
|
80
|
-
rspec-mocks (3.
|
82
|
+
rspec-support (~> 3.10.0)
|
83
|
+
rspec-mocks (3.10.2)
|
81
84
|
diff-lcs (>= 1.2.0, < 2.0)
|
82
|
-
rspec-support (~> 3.
|
83
|
-
rspec-support (3.
|
84
|
-
rubocop (
|
85
|
-
jaro_winkler (~> 1.5.1)
|
85
|
+
rspec-support (~> 3.10.0)
|
86
|
+
rspec-support (3.10.2)
|
87
|
+
rubocop (1.18.3)
|
86
88
|
parallel (~> 1.10)
|
87
|
-
parser (>=
|
89
|
+
parser (>= 3.0.0.0)
|
88
90
|
rainbow (>= 2.2.2, < 4.0)
|
91
|
+
regexp_parser (>= 1.8, < 3.0)
|
92
|
+
rexml
|
93
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
89
94
|
ruby-progressbar (~> 1.7)
|
90
|
-
unicode-display_width (>= 1.4.0, <
|
91
|
-
rubocop-
|
92
|
-
|
93
|
-
rubocop-
|
94
|
-
rubocop (>=
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
95
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
96
|
+
rubocop-ast (1.8.0)
|
97
|
+
parser (>= 3.0.1.1)
|
98
|
+
rubocop-performance (1.11.4)
|
99
|
+
rubocop (>= 1.7.0, < 2.0)
|
100
|
+
rubocop-ast (>= 0.4.0)
|
101
|
+
rubocop-rake (0.6.0)
|
102
|
+
rubocop (~> 1.0)
|
103
|
+
rubocop-rspec (2.4.0)
|
104
|
+
rubocop (~> 1.0)
|
105
|
+
rubocop-ast (>= 1.1.0)
|
106
|
+
ruby-progressbar (1.11.0)
|
107
|
+
ruby_parser (3.16.0)
|
108
|
+
sexp_processor (~> 4.15, >= 4.15.1)
|
109
|
+
sexp_processor (4.15.3)
|
110
|
+
thor (1.1.0)
|
111
|
+
tzinfo (2.0.4)
|
112
|
+
concurrent-ruby (~> 1.0)
|
113
|
+
unicode-display_width (2.0.0)
|
114
|
+
zeitwerk (2.4.2)
|
105
115
|
|
106
116
|
PLATFORMS
|
107
117
|
ruby
|
@@ -115,7 +125,8 @@ DEPENDENCIES
|
|
115
125
|
rspec
|
116
126
|
rubocop
|
117
127
|
rubocop-performance
|
128
|
+
rubocop-rake
|
118
129
|
rubocop-rspec
|
119
130
|
|
120
131
|
BUNDLED WITH
|
121
|
-
2.
|
132
|
+
2.2.24
|
data/README.md
CHANGED
@@ -29,13 +29,27 @@ Or install it yourself as:
|
|
29
29
|
|
30
30
|
## Configurations
|
31
31
|
|
32
|
+
Any and all monkey patches must be explicitly included anywhere you want to use it.
|
33
|
+
|
34
|
+
To globally use the monkey patches, just create an initializer requiring them.
|
35
|
+
|
32
36
|
`rails g lite:measurements:install` will generate the following file:
|
33
|
-
`../config/initalizers/
|
37
|
+
`../config/initalizers/lite_measurements.rb`
|
38
|
+
|
39
|
+
They can be disabled by commenting any of them out.
|
34
40
|
|
35
41
|
```ruby
|
36
|
-
|
37
|
-
|
38
|
-
|
42
|
+
# frozen_string_literal: true
|
43
|
+
|
44
|
+
require 'lite/measurements/monkey_patches'
|
45
|
+
|
46
|
+
# - or-
|
47
|
+
|
48
|
+
# require 'lite/measurements/monkey_patches/digital_storage'
|
49
|
+
# require 'lite/measurements/monkey_patches/length'
|
50
|
+
# require 'lite/measurements/monkey_patches/mass'
|
51
|
+
# require 'lite/measurements/monkey_patches/temperature'
|
52
|
+
# require 'lite/measurements/monkey_patches/time'
|
39
53
|
```
|
40
54
|
|
41
55
|
## Measurements
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require 'lite/measurements/monkey_patches'
|
4
|
+
|
5
|
+
# - or-
|
6
|
+
|
7
|
+
# require 'lite/measurements/monkey_patches/digital_storage'
|
8
|
+
# require 'lite/measurements/monkey_patches/length'
|
9
|
+
# require 'lite/measurements/monkey_patches/mass'
|
10
|
+
# require 'lite/measurements/monkey_patches/temperature'
|
11
|
+
# require 'lite/measurements/monkey_patches/time'
|
data/lib/lite/measurements.rb
CHANGED
@@ -1,17 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'generators/lite/measurements/install_generator' if defined?(Rails::Generators)
|
4
|
+
|
3
5
|
require 'lite/measurements/version'
|
4
|
-
require 'lite/measurements/configuration'
|
5
6
|
require 'lite/measurements/helpers/conversion_helper'
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
require 'lite/measurements/monkey_patches' if Lite::Measurements.configuration.monkey_patches
|
16
|
-
|
17
|
-
require 'generators/lite/measurements/install_generator'
|
7
|
+
require 'lite/measurements/helpers/shift_helper'
|
8
|
+
require 'lite/measurements/base'
|
9
|
+
require 'lite/measurements/digital_storage'
|
10
|
+
require 'lite/measurements/length'
|
11
|
+
require 'lite/measurements/mass'
|
12
|
+
require 'lite/measurements/temperature'
|
13
|
+
require 'lite/measurements/time'
|
@@ -6,9 +6,14 @@ module Lite
|
|
6
6
|
|
7
7
|
include Lite::Measurements::Helpers::ShiftHelper
|
8
8
|
|
9
|
-
DIGITAL_STORAGE_UNITS
|
10
|
-
bytes: 1.0,
|
11
|
-
|
9
|
+
DIGITAL_STORAGE_UNITS = {
|
10
|
+
bytes: 1.0,
|
11
|
+
kilobytes: 1024.0,
|
12
|
+
megabytes: 1024.0**2,
|
13
|
+
gigabytes: 1024.0**3,
|
14
|
+
terabytes: 1024.0**4,
|
15
|
+
petabytes: 1024.0**5,
|
16
|
+
exabytes: 1024.0**6
|
12
17
|
}.freeze
|
13
18
|
|
14
19
|
def convert(from:, to:)
|
@@ -11,17 +11,17 @@ module Lite
|
|
11
11
|
[imperical_keys, metric_keys].flatten
|
12
12
|
end
|
13
13
|
|
14
|
-
# rubocop:disable
|
15
|
-
def convert_to_imperical_units(units, from: nil,
|
14
|
+
# rubocop:disable Layout/LineLength
|
15
|
+
def convert_to_imperical_units(units, convert_to:, convert_from:, from: nil, to: nil)
|
16
16
|
units = shift_units(units, type: klass::METRIC_UNITS, from: from, to: convert_to)
|
17
17
|
shift_units(units / klass::CONVERTER, type: klass::IMPERICAL_UNITS, from: convert_from, to: to)
|
18
18
|
end
|
19
19
|
|
20
|
-
def convert_to_metric_units(units, from: nil,
|
20
|
+
def convert_to_metric_units(units, convert_to:, convert_from:, from: nil, to: nil)
|
21
21
|
units = shift_units(units, type: klass::IMPERICAL_UNITS, from: from, to: convert_to)
|
22
22
|
shift_units(units * klass::CONVERTER, type: klass::METRIC_UNITS, from: convert_from, to: to)
|
23
23
|
end
|
24
|
-
# rubocop:enable
|
24
|
+
# rubocop:enable Layout/LineLength
|
25
25
|
|
26
26
|
def convert_to_imperical_units?(from, to)
|
27
27
|
metric_keys.include?(from) && imperical_keys.include?(to)
|
@@ -7,17 +7,27 @@ module Lite
|
|
7
7
|
include Lite::Measurements::Helpers::ConversionHelper
|
8
8
|
include Lite::Measurements::Helpers::ShiftHelper
|
9
9
|
|
10
|
-
CONVERTER
|
10
|
+
CONVERTER = 0.0254
|
11
11
|
|
12
|
-
IMPERICAL_UNITS
|
13
|
-
inches: 1.0,
|
12
|
+
IMPERICAL_UNITS = {
|
13
|
+
inches: 1.0,
|
14
|
+
feet: 12.0,
|
15
|
+
yards: 36.0,
|
16
|
+
miles: 63_360.0,
|
17
|
+
nautical_miles: 72_913.386
|
14
18
|
}.freeze
|
15
|
-
METRIC_UNITS
|
16
|
-
micrometers: 0.000001,
|
17
|
-
|
19
|
+
METRIC_UNITS = {
|
20
|
+
micrometers: 0.000001,
|
21
|
+
millimeters: 0.001,
|
22
|
+
centimeters: 0.01,
|
23
|
+
decimeters: 0.1,
|
24
|
+
meters: 1.0,
|
25
|
+
dekameters: 10.0,
|
26
|
+
hectometers: 100.0,
|
27
|
+
kilometers: 1_000.0
|
18
28
|
}.freeze
|
19
29
|
|
20
|
-
# rubocop:disable Metrics/
|
30
|
+
# rubocop:disable Metrics/MethodLength, Layout/LineLength
|
21
31
|
def convert(from:, to:)
|
22
32
|
assert_all_valid_keys!(from, to, all_keys)
|
23
33
|
|
@@ -33,7 +43,7 @@ module Lite
|
|
33
43
|
convert_to_imperical_units(amount, from: from, convert_to: :meters, convert_from: :inches, to: to)
|
34
44
|
end
|
35
45
|
end
|
36
|
-
# rubocop:enable Metrics/
|
46
|
+
# rubocop:enable Metrics/MethodLength, Layout/LineLength
|
37
47
|
|
38
48
|
end
|
39
49
|
end
|
@@ -7,17 +7,28 @@ module Lite
|
|
7
7
|
include Lite::Measurements::Helpers::ConversionHelper
|
8
8
|
include Lite::Measurements::Helpers::ShiftHelper
|
9
9
|
|
10
|
-
CONVERTER
|
10
|
+
CONVERTER = 28.349523125
|
11
11
|
|
12
|
-
IMPERICAL_UNITS
|
13
|
-
ounces: 1.0,
|
12
|
+
IMPERICAL_UNITS = {
|
13
|
+
ounces: 1.0,
|
14
|
+
pounds: 16.0,
|
15
|
+
stones: 224.0,
|
16
|
+
us_tons: 32_000.0,
|
17
|
+
imperial_tons: 35_840.0
|
14
18
|
}.freeze
|
15
|
-
METRIC_UNITS
|
16
|
-
micrograms: 0.000001,
|
17
|
-
|
19
|
+
METRIC_UNITS = {
|
20
|
+
micrograms: 0.000001,
|
21
|
+
milligrams: 0.001,
|
22
|
+
centigrams: 0.01,
|
23
|
+
decigrams: 0.1,
|
24
|
+
grams: 1.0,
|
25
|
+
dekagrams: 10.0,
|
26
|
+
hectograms: 100.0,
|
27
|
+
kilograms: 1_000.0,
|
28
|
+
metric_tons: 1_000_000.0
|
18
29
|
}.freeze
|
19
30
|
|
20
|
-
# rubocop:disable Metrics/
|
31
|
+
# rubocop:disable Metrics/MethodLength, Layout/LineLength
|
21
32
|
def convert(from:, to:)
|
22
33
|
assert_all_valid_keys!(from, to, all_keys)
|
23
34
|
|
@@ -33,7 +44,7 @@ module Lite
|
|
33
44
|
convert_to_imperical_units(amount, from: from, convert_to: :grams, convert_from: :ounces, to: to)
|
34
45
|
end
|
35
46
|
end
|
36
|
-
# rubocop:enable Metrics/
|
47
|
+
# rubocop:enable Metrics/MethodLength, Layout/LineLength
|
37
48
|
|
38
49
|
end
|
39
50
|
end
|
@@ -1,19 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
length: Lite::Measurements::Length,
|
9
|
-
mass: Lite::Measurements::Mass,
|
10
|
-
temperature: Lite::Measurements::Temperature,
|
11
|
-
time: Lite::Measurements::Time
|
12
|
-
}.each do |name, klass|
|
13
|
-
define_method("convert_#{name}") do |from:, to:|
|
14
|
-
klass.convert(self, from: from, to: to)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
3
|
+
require 'lite/measurements/monkey_patches/digital_storage'
|
4
|
+
require 'lite/measurements/monkey_patches/length'
|
5
|
+
require 'lite/measurements/monkey_patches/mass'
|
6
|
+
require 'lite/measurements/monkey_patches/temperature'
|
7
|
+
require 'lite/measurements/monkey_patches/time'
|
@@ -4,12 +4,12 @@ module Lite
|
|
4
4
|
module Measurements
|
5
5
|
class Temperature < Lite::Measurements::Base
|
6
6
|
|
7
|
-
C_FREEZING_POINT
|
8
|
-
C_INVERSED_POINT
|
9
|
-
F_FREEZING_POINT
|
10
|
-
K_FREEZING_POINT
|
7
|
+
C_FREEZING_POINT = 5.0 / 9.0
|
8
|
+
C_INVERSED_POINT = 9.0 / 5.0
|
9
|
+
F_FREEZING_POINT = 32.0
|
10
|
+
K_FREEZING_POINT = 273.15
|
11
11
|
|
12
|
-
VALID_KEYS
|
12
|
+
VALID_KEYS = %i[
|
13
13
|
celsius fahrenheit kelvin
|
14
14
|
].freeze
|
15
15
|
|
@@ -6,10 +6,17 @@ module Lite
|
|
6
6
|
|
7
7
|
include Lite::Measurements::Helpers::ShiftHelper
|
8
8
|
|
9
|
-
TIME_UNITS
|
10
|
-
milliseconds: 0.001,
|
11
|
-
|
12
|
-
|
9
|
+
TIME_UNITS = {
|
10
|
+
milliseconds: 0.001,
|
11
|
+
seconds: 1.0,
|
12
|
+
minutes: 60.0,
|
13
|
+
hours: 3600.0,
|
14
|
+
days: 86_400.0,
|
15
|
+
weeks: 604_800.0,
|
16
|
+
years: 31_557_600.0,
|
17
|
+
decades: 31_557_600.0 * 10.0,
|
18
|
+
centuries: 31_557_600.0 * 100.0,
|
19
|
+
millenniums: 31_557_600.0 * 1_000.0
|
13
20
|
}.freeze
|
14
21
|
|
15
22
|
def convert(from:, to:)
|
data/lite-measurements.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
)
|
26
26
|
else
|
27
27
|
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
28
|
-
|
28
|
+
'public gem pushes.'
|
29
29
|
end
|
30
30
|
|
31
31
|
# Specify which files should be added to the gem when it is released.
|
@@ -44,5 +44,6 @@ Gem::Specification.new do |spec|
|
|
44
44
|
spec.add_development_dependency 'rspec'
|
45
45
|
spec.add_development_dependency 'rubocop'
|
46
46
|
spec.add_development_dependency 'rubocop-performance'
|
47
|
+
spec.add_development_dependency 'rubocop-rake'
|
47
48
|
spec.add_development_dependency 'rubocop-rspec'
|
48
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lite-measurements
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: rubocop-rspec
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,7 +136,7 @@ dependencies:
|
|
122
136
|
- - ">="
|
123
137
|
- !ruby/object:Gem::Version
|
124
138
|
version: '0'
|
125
|
-
description:
|
139
|
+
description:
|
126
140
|
email:
|
127
141
|
- j.gomez@drexed.com
|
128
142
|
executables: []
|
@@ -154,13 +168,17 @@ files:
|
|
154
168
|
- lib/lite/measurements.rb
|
155
169
|
- lib/lite/measurements/.DS_Store
|
156
170
|
- lib/lite/measurements/base.rb
|
157
|
-
- lib/lite/measurements/configuration.rb
|
158
171
|
- lib/lite/measurements/digital_storage.rb
|
159
172
|
- lib/lite/measurements/helpers/conversion_helper.rb
|
160
173
|
- lib/lite/measurements/helpers/shift_helper.rb
|
161
174
|
- lib/lite/measurements/length.rb
|
162
175
|
- lib/lite/measurements/mass.rb
|
163
176
|
- lib/lite/measurements/monkey_patches.rb
|
177
|
+
- lib/lite/measurements/monkey_patches/digital_storage.rb
|
178
|
+
- lib/lite/measurements/monkey_patches/length.rb
|
179
|
+
- lib/lite/measurements/monkey_patches/mass.rb
|
180
|
+
- lib/lite/measurements/monkey_patches/temperature.rb
|
181
|
+
- lib/lite/measurements/monkey_patches/time.rb
|
164
182
|
- lib/lite/measurements/temperature.rb
|
165
183
|
- lib/lite/measurements/time.rb
|
166
184
|
- lib/lite/measurements/version.rb
|
@@ -169,7 +187,7 @@ homepage: http://drexed.github.io/lite-measurements
|
|
169
187
|
licenses:
|
170
188
|
- MIT
|
171
189
|
metadata: {}
|
172
|
-
post_install_message:
|
190
|
+
post_install_message:
|
173
191
|
rdoc_options: []
|
174
192
|
require_paths:
|
175
193
|
- lib
|
@@ -184,8 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
202
|
- !ruby/object:Gem::Version
|
185
203
|
version: '0'
|
186
204
|
requirements: []
|
187
|
-
rubygems_version: 3.
|
188
|
-
signing_key:
|
205
|
+
rubygems_version: 3.2.24
|
206
|
+
signing_key:
|
189
207
|
specification_version: 4
|
190
208
|
summary: Convert measurements to different unit sizes or types
|
191
209
|
test_files: []
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Lite
|
4
|
-
module Measurements
|
5
|
-
|
6
|
-
class Configuration
|
7
|
-
|
8
|
-
attr_accessor :monkey_patches
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
@monkey_patches = true
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.configuration
|
17
|
-
@configuration ||= Configuration.new
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.configuration=(config)
|
21
|
-
@configuration = config
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.configure
|
25
|
-
yield(configuration)
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|