weighable 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 796c7341c87131931e5896422b919270a952c9d87763a7e3696697682d7236ab
4
- data.tar.gz: 7cf5162848d619bb19863bffaccda5cf09725a689dca2db94424e9ecd5ee6596
2
+ SHA1:
3
+ metadata.gz: 03334b7e6f21d02d412415c4f3e489153f616700
4
+ data.tar.gz: 450fffc6175fdf9275ec245eb4098b67fe62a1ec
5
5
  SHA512:
6
- metadata.gz: b798ed54c99730c1d4d8504a2eb246d34105d313aca1bc3e6c0b2fc5b13f6cd7fba76531e38ef1df827e99a0730c74a93577e820d8a93ebbb084632b0e45e11c
7
- data.tar.gz: 34e84421edec24cfa3f4b3b01425e366b991024c70481d0d6b160ce6683d5f4da747243acaf2933f6472b8b0c8120e85b33cb1dd285381ce2f9b38ca9c5db1d3
6
+ metadata.gz: 1bb65307014f18a2eca97b831a6a462eeec631f890319d5e59797ddfc844ac785427bc9a8d8b11ee1e3f8deafb2d54ac40ef623cc7f21225fedf19193c773ba4
7
+ data.tar.gz: 1d39b80722b28ef393b901f9aa9dc697c453e57b03191d064a07061dc624243640738c5361de65dd7131754acee85130bcf6b5a69aa363879d8687c8d9f3cfe5
@@ -0,0 +1,32 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ environment:
5
+ CC_TEST_REPORTER_ID: 0f917edc031f16b4e113269d2a97c6db32df02fb034919c35d95c896d68e5c2a
6
+ docker:
7
+ - image: circleci/ruby:2.2.8
8
+ steps:
9
+ - checkout
10
+ - restore_cache:
11
+ keys:
12
+ - weighable-{{ checksum "Gemfile" }}
13
+ - weighable-
14
+ - run:
15
+ name: install dependencies
16
+ command: bundle check || bundle install
17
+ - save_cache:
18
+ key: weighable-{{ checksum "Gemfile" }}
19
+ paths:
20
+ - vendor/bundle
21
+ - run:
22
+ name: Setup Code Climate test-reporter
23
+ command: |
24
+ # download test reporter as a static binary
25
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
26
+ chmod +x ./cc-test-reporter
27
+ - run:
28
+ name: Run rspec in parallel
29
+ command: |
30
+ ./cc-test-reporter before-build
31
+ bundle exec rspec --format documentation --format RspecJunitFormatter -o rspec.xml
32
+ ./cc-test-reporter after-build --exit-code $?
@@ -1,3 +1,3 @@
1
1
  module Weighable
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
@@ -7,32 +7,35 @@ module Weighable
7
7
  attr_reader :value, :unit
8
8
 
9
9
  UNIT = {
10
- gram: 0,
11
- ounce: 1,
12
- pound: 2,
13
- milligram: 3,
14
- kilogram: 4,
15
- unit: 5
10
+ gram: 0,
11
+ ounce: 1,
12
+ pound: 2,
13
+ milligram: 3,
14
+ kilogram: 4,
15
+ unit: 5,
16
+ fluid_ounce: 6
16
17
  }.freeze
17
18
 
18
19
  UNIT_ABBREVIATION = {
19
- gram: 'g',
20
- ounce: 'oz',
21
- pound: 'lb',
22
- milligram: 'mg',
23
- kilogram: 'kg',
24
- unit: nil
20
+ gram: 'g',
21
+ ounce: 'oz',
22
+ pound: 'lb',
23
+ milligram: 'mg',
24
+ kilogram: 'kg',
25
+ fluid_ounce: 'fl oz',
26
+ unit: nil
25
27
  }.freeze
26
28
 
27
29
  ABBREVIATION_ALIASES = {
28
- 'g' => :gram,
29
- 'oz' => :ounce,
30
- 'lb' => :pound,
31
- 'mg' => :milligram,
32
- 'kg' => :kilogram,
33
- 'ea' => :unit,
34
- 'each' => :unit,
35
- nil => :unit
30
+ 'g' => :gram,
31
+ 'oz' => :ounce,
32
+ 'lb' => :pound,
33
+ 'mg' => :milligram,
34
+ 'kg' => :kilogram,
35
+ 'fl oz' => :fluid_ounce,
36
+ 'ea' => :unit,
37
+ 'each' => :unit,
38
+ nil => :unit
36
39
  }.freeze
37
40
 
38
41
  GRAMS_PER_OUNCE = BigDecimal.new('28.34952')
@@ -46,52 +49,72 @@ module Weighable
46
49
  KILOGRAMS_PER_OUNCE = GRAMS_PER_OUNCE * KILOGRAMS_PER_GRAM
47
50
  MILLIGRAMS_PER_POUND = GRAMS_PER_POUND * MILLIGRAMS_PER_GRAM
48
51
  KILOGRAMS_PER_POUND = GRAMS_PER_POUND * KILOGRAMS_PER_GRAM
49
- KILOGRAMS_PER_MILLIGRAM = MILLIGRAMS_PER_GRAM**2
52
+ MILLIGRAMS_PER_KILOGRAM = MILLIGRAMS_PER_GRAM**2
53
+ FLUID_OUNCE_PER_OUNCE = IDENTITY
50
54
 
51
55
  CONVERSIONS = {
52
56
  UNIT[:unit] => {
53
57
  UNIT[:unit] => [:*, IDENTITY]
54
58
  },
55
59
  UNIT[:gram] => {
56
- UNIT[:gram] => [:*, IDENTITY],
57
- UNIT[:ounce] => [:/, GRAMS_PER_OUNCE],
58
- UNIT[:pound] => [:/, GRAMS_PER_POUND],
59
- UNIT[:milligram] => [:*, MILLIGRAMS_PER_GRAM],
60
- UNIT[:kilogram] => [:*, KILOGRAMS_PER_GRAM]
60
+ UNIT[:gram] => [:*, IDENTITY],
61
+ UNIT[:ounce] => [:/, GRAMS_PER_OUNCE],
62
+ UNIT[:pound] => [:/, GRAMS_PER_POUND],
63
+ UNIT[:milligram] => [:*, MILLIGRAMS_PER_GRAM],
64
+ UNIT[:kilogram] => [:*, KILOGRAMS_PER_GRAM],
65
+ UNIT[:fluid_ounce] => [:/, GRAMS_PER_OUNCE]
61
66
  },
62
67
  UNIT[:ounce] => {
63
68
  UNIT[:gram] => [:*, GRAMS_PER_OUNCE],
64
69
  UNIT[:ounce] => [:*, IDENTITY],
65
70
  UNIT[:pound] => [:/, OUNCES_PER_POUND],
66
71
  UNIT[:milligram] => [:*, MILLIGRAMS_PER_OUNCE],
67
- UNIT[:kilogram] => [:*, KILOGRAMS_PER_OUNCE]
72
+ UNIT[:kilogram] => [:*, KILOGRAMS_PER_OUNCE],
73
+ UNIT[:fluid_ounce] => [:*, IDENTITY]
68
74
  },
69
75
  UNIT[:pound] => {
70
76
  UNIT[:gram] => [:*, GRAMS_PER_POUND],
71
77
  UNIT[:ounce] => [:*, OUNCES_PER_POUND],
72
78
  UNIT[:pound] => [:*, IDENTITY],
73
79
  UNIT[:milligram] => [:*, MILLIGRAMS_PER_POUND],
74
- UNIT[:kilogram] => [:*, KILOGRAMS_PER_POUND]
80
+ UNIT[:kilogram] => [:*, KILOGRAMS_PER_POUND],
81
+ UNIT[:fluid_ounce] => [:*, OUNCES_PER_POUND]
75
82
  },
76
83
  UNIT[:milligram] => {
77
84
  UNIT[:gram] => [:/, MILLIGRAMS_PER_GRAM],
78
85
  UNIT[:ounce] => [:/, MILLIGRAMS_PER_OUNCE],
79
86
  UNIT[:pound] => [:/, MILLIGRAMS_PER_POUND],
80
87
  UNIT[:milligram] => [:*, IDENTITY],
81
- UNIT[:kilogram] => [:/, KILOGRAMS_PER_MILLIGRAM]
88
+ UNIT[:kilogram] => [:/, MILLIGRAMS_PER_KILOGRAM],
89
+ UNIT[:fluid_ounce] => [:/, MILLIGRAMS_PER_OUNCE]
82
90
  },
83
91
  UNIT[:kilogram] => {
84
92
  UNIT[:gram] => [:/, KILOGRAMS_PER_GRAM],
85
93
  UNIT[:ounce] => [:/, KILOGRAMS_PER_OUNCE],
86
94
  UNIT[:pound] => [:/, KILOGRAMS_PER_POUND],
87
- UNIT[:milligram] => [:*, KILOGRAMS_PER_MILLIGRAM],
88
- UNIT[:kilogram] => [:*, IDENTITY]
95
+ UNIT[:milligram] => [:*, MILLIGRAMS_PER_KILOGRAM],
96
+ UNIT[:kilogram] => [:*, IDENTITY],
97
+ UNIT[:fluid_ounce] => [:/, KILOGRAMS_PER_OUNCE]
98
+ },
99
+ UNIT[:fluid_ounce] => {
100
+ UNIT[:fluid_ounce] => [:*, IDENTITY],
101
+ UNIT[:gram] => [:*, GRAMS_PER_OUNCE],
102
+ UNIT[:ounce] => [:*, IDENTITY],
103
+ UNIT[:pound] => [:/, OUNCES_PER_POUND],
104
+ UNIT[:milligram] => [:*, MILLIGRAMS_PER_OUNCE],
105
+ UNIT[:kilogram] => [:*, KILOGRAMS_PER_OUNCE],
89
106
  }
90
107
  }.freeze
91
108
 
92
109
  def self.parse(string)
93
- value, unit = string.split(' ')
94
- from_value_and_unit(value, unit)
110
+ unit_start = string.index(' ')
111
+ if unit_start
112
+ unit = string.slice!(unit_start + 1..-1)
113
+ value = string.slice!(0..unit_start - 1)
114
+ from_value_and_unit(value, unit)
115
+ else
116
+ from_value_and_unit(string, nil)
117
+ end
95
118
  end
96
119
 
97
120
  def self.from_value_and_unit(value, unit)
@@ -102,7 +125,7 @@ module Weighable
102
125
 
103
126
  def self.parse_unit(unit)
104
127
  unit = ActiveSupport::Inflector.singularize(unit.downcase) unless unit.nil?
105
- unit_symbol = unit ? unit.to_sym : unit
128
+ unit_symbol = unit ? unit.tr(' ', '_').to_sym : unit
106
129
  UNIT[unit_symbol] || ABBREVIATION_ALIASES[unit]
107
130
  end
108
131
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weighable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trae Robrock
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-09 00:00:00.000000000 Z
11
+ date: 2019-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -143,6 +143,7 @@ executables: []
143
143
  extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
+ - ".circleci/config.yml"
146
147
  - ".gitignore"
147
148
  - ".hound.yml"
148
149
  - ".rspec"
@@ -156,7 +157,6 @@ files:
156
157
  - Rakefile
157
158
  - bin/console
158
159
  - bin/setup
159
- - circle.yml
160
160
  - lib/weighable.rb
161
161
  - lib/weighable/active_record/migration_extensions/schema_statements.rb
162
162
  - lib/weighable/active_record/migration_extensions/table.rb
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  version: '0'
190
190
  requirements: []
191
191
  rubyforge_project:
192
- rubygems_version: 2.7.6
192
+ rubygems_version: 2.4.5.3
193
193
  signing_key:
194
194
  specification_version: 4
195
195
  summary: Like BigDecimal, but for weight. Includes Rails integration.
data/circle.yml DELETED
@@ -1,18 +0,0 @@
1
- machine:
2
- environment:
3
- CC_TEST_REPORTER_ID: 0f917edc031f16b4e113269d2a97c6db32df02fb034919c35d95c896d68e5c2a
4
-
5
- dependencies:
6
- pre:
7
- - gem update bundler
8
- post:
9
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
10
- - chmod +x ./cc-test-reporter
11
-
12
- test:
13
- pre:
14
- - ./cc-test-reporter before-build
15
- override:
16
- - bundle exec rspec --format documentation --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec.xml
17
- post:
18
- - ./cc-test-reporter after-build --exit-code $EXIT_CODE