lite-measurements 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6cab32c9502bf1582a4a450cfd22bfbeffe232dadebba759a1e17abdbd84685
4
- data.tar.gz: 00f6cfada5e5638f1d4af4afc068467c52b4f5687aef9b38f95f03713f1aa1da
3
+ metadata.gz: c03231a244a23709daa52499d7ec9ecad0233139eb8882ada2f8f3167411a47b
4
+ data.tar.gz: 281405d760c0a9da7a85a788c3ae648a2ade4b7cffa64f5da692389624904db6
5
5
  SHA512:
6
- metadata.gz: 8ba17383f0e5e87ace39217c6250e964485696943e6e4737215c6e748f4f192522fc4958638bc0898c74f2996cdab5fac18f8e638cff88c75f8fecb42ce1140b
7
- data.tar.gz: 8f3d98b958018f61687e91b2a65f70263fde96115e560a18d7c73636acbedf89c083d7ab3273a7dfac842f2553bfb0de3a3dd2c063e231013259fba42bc48942
6
+ metadata.gz: 2f5820c8c673b2da8c9efd0b6572f2590d7a72a1c38b816c6c5333f00a73b983675c145f5702554f7e00c6e31795d0cd8ae1b564aa005d5ad570312881b5f9e3
7
+ data.tar.gz: 99829fc29512c0844c00e10459dfc1fd2785a72d655cd3e83e68b3838718fb5aa51685f888769daab32f7050c74ac3d68f5bc24cc4c725d2dd7212a307b7e165
data/CHANGELOG.md CHANGED
@@ -6,6 +6,13 @@ 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
+
9
16
  ## [1.1.1] - 2021-07-21
10
17
  ### Changed
11
18
  - Improved Railtie support
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-measurements (1.1.1)
4
+ lite-measurements (2.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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/lite-measurements.rb`
37
+ `../config/initalizers/lite_measurements.rb`
38
+
39
+ They can be disabled by commenting any of them out.
34
40
 
35
41
  ```ruby
36
- Lite::Measurements.configure do |config|
37
- config.monkey_patches = true
38
- end
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
- Lite::Measurements.configure do |config|
4
- config.monkey_patches = true
5
- end
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'
@@ -3,12 +3,11 @@
3
3
  require 'generators/lite/measurements/install_generator' if defined?(Rails::Generators)
4
4
 
5
5
  require 'lite/measurements/version'
6
- require 'lite/measurements/configuration'
7
-
8
- %w[conversion shift].each do |filename|
9
- require "lite/measurements/helpers/#{filename}_helper"
10
- end
11
-
12
- %w[base digital_storage length mass temperature time monkey_patches].each do |filename|
13
- require "lite/measurements/#{filename}"
14
- end
6
+ require 'lite/measurements/helpers/conversion_helper'
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'
@@ -7,8 +7,13 @@ module Lite
7
7
  include Lite::Measurements::Helpers::ShiftHelper
8
8
 
9
9
  DIGITAL_STORAGE_UNITS = {
10
- bytes: 1.0, kilobytes: 1024.0, megabytes: 1024.0**2, gigabytes: 1024.0**3,
11
- terabytes: 1024.0**4, petabytes: 1024.05**5, exabytes: 1024**6
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:)
@@ -10,11 +10,21 @@ module Lite
10
10
  CONVERTER = 0.0254
11
11
 
12
12
  IMPERICAL_UNITS = {
13
- inches: 1.0, feet: 12.0, yards: 36.0, miles: 63_360.0, nautical_miles: 72_913.386
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
19
  METRIC_UNITS = {
16
- micrometers: 0.000001, millimeters: 0.001, centimeters: 0.01, decimeters: 0.1, meters: 1.0,
17
- dekameters: 10.0, hectometers: 100.0, kilometers: 1_000.0
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
30
  # rubocop:disable Metrics/MethodLength, Layout/LineLength
@@ -10,11 +10,22 @@ module Lite
10
10
  CONVERTER = 28.349523125
11
11
 
12
12
  IMPERICAL_UNITS = {
13
- ounces: 1.0, pounds: 16.0, stones: 224.0, us_tons: 32_000.0, imperial_tons: 35_840.0
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
19
  METRIC_UNITS = {
16
- micrograms: 0.000001, milligrams: 0.001, centigrams: 0.01, decigrams: 0.1, grams: 1.0,
17
- dekagrams: 10.0, hectograms: 100.0, kilograms: 1_000.0, metric_tons: 1_000_000.0
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
31
  # rubocop:disable Metrics/MethodLength, Layout/LineLength
@@ -1,19 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if Lite::Measurements.configuration.monkey_patches
4
- class Numeric
5
-
6
- {
7
- digital_storage: Lite::Measurements::DigitalStorage,
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'
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Numeric
4
+
5
+ def convert_digital_storage(from:, to:)
6
+ Lite::Measurements::DigitalStorage.convert(self, from: from, to: to)
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Numeric
4
+
5
+ def convert_length(from:, to:)
6
+ Lite::Measurements::Length.convert(self, from: from, to: to)
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Numeric
4
+
5
+ def convert_mass(from:, to:)
6
+ Lite::Measurements::Mass.convert(self, from: from, to: to)
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Numeric
4
+
5
+ def convert_temperature(from:, to:)
6
+ Lite::Measurements::Temperature.convert(self, from: from, to: to)
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Numeric
4
+
5
+ def convert_time(from:, to:)
6
+ Lite::Measurements::Time.convert(self, from: from, to: to)
7
+ end
8
+
9
+ end
@@ -7,9 +7,16 @@ module Lite
7
7
  include Lite::Measurements::Helpers::ShiftHelper
8
8
 
9
9
  TIME_UNITS = {
10
- milliseconds: 0.001, seconds: 1.0, minutes: 60.0, hours: 3600.0, days: 86_400.0,
11
- weeks: 604_800.0, years: 31_557_600.0, decades: 31_557_600.0 * 10.0,
12
- centuries: 31_557_600.0 * 100.0, millenniums: 31_557_600.0 * 1_000.0
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:)
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Measurements
5
5
 
6
- VERSION = '1.1.1'
6
+ VERSION = '2.0.0'
7
7
 
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-measurements
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
@@ -168,13 +168,17 @@ files:
168
168
  - lib/lite/measurements.rb
169
169
  - lib/lite/measurements/.DS_Store
170
170
  - lib/lite/measurements/base.rb
171
- - lib/lite/measurements/configuration.rb
172
171
  - lib/lite/measurements/digital_storage.rb
173
172
  - lib/lite/measurements/helpers/conversion_helper.rb
174
173
  - lib/lite/measurements/helpers/shift_helper.rb
175
174
  - lib/lite/measurements/length.rb
176
175
  - lib/lite/measurements/mass.rb
177
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
178
182
  - lib/lite/measurements/temperature.rb
179
183
  - lib/lite/measurements/time.rb
180
184
  - lib/lite/measurements/version.rb
@@ -1,35 +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
- class << self
17
-
18
- attr_writer :configuration
19
-
20
- def configuration
21
- @configuration ||= Configuration.new
22
- end
23
-
24
- def configure
25
- yield(configuration)
26
- end
27
-
28
- def reset_configuration!
29
- @configuration = Configuration.new
30
- end
31
-
32
- end
33
-
34
- end
35
- end