measured 2.0.0.pre4 → 2.0.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -16
  3. data/lib/measured/version.rb +1 -1
  4. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 674d14a40f494d518096818abee97059c304c311
4
- data.tar.gz: f8303931e971c18c714e4d4ba74ec39c141fefd8
3
+ metadata.gz: 7c468b43dd721649e5b050c0ad7f81b17e541734
4
+ data.tar.gz: d7c36b859f8e80539841a8a52457f923ca175136
5
5
  SHA512:
6
- metadata.gz: 5402f3214c5b44a06f979f4fe86a9dc27682a2b3bb605ab944c8a35dcda780f58e11d8be70901eeb28e61986049bbd9e26e3930d13e66170b79de20b5f8c9446
7
- data.tar.gz: 10f00639a2bc89230c0a60ab00f58cfb27801c90262c326e6a658947b22ef4bef7208bbed33fdd9486ecc6957f2cdfc5a954622e44c71f0b89021f690fb063f1
6
+ metadata.gz: fae18c324062e6274e0b6dab29b2ed0bcdb88012d90859edbc23fad081d1c02aba34710f54d0ecb2e7eb92a1940ef382fd5c0edaf2700ba2fc0ce422e333a3e7
7
+ data.tar.gz: ef22bf6cc930d8e3835095952e9aad259e32475584a0d0537f38f459e4ab141d4713f275f1c33d35e52eeabf0c7221c6192cec137827d3938287ece2e603f1da
data/README.md CHANGED
@@ -26,24 +26,28 @@ Initialize a measurement:
26
26
 
27
27
  ```ruby
28
28
  Measured::Weight.new("12", "g")
29
+ > #<Measured::Weight: 12 #<Measured::Unit: g (gram, grams)>>
29
30
  ```
30
31
 
31
32
  Convert to return a new measurement:
32
33
 
33
34
  ```ruby
34
35
  Measured::Weight.new("12", "g").convert_to("kg")
36
+ > #<Measured::Weight: 0.012 #<Measured::Unit: kg (kilogram, kilograms) 1000/1 g>>
35
37
  ```
36
38
 
37
39
  Agnostic to symbols/strings:
38
40
 
39
41
  ```ruby
40
42
  Measured::Weight.new(1, "kg") == Measured::Weight.new(1, :kg)
43
+ > true
41
44
  ```
42
45
 
43
46
  Seamlessly handles aliases:
44
47
 
45
48
  ```ruby
46
49
  Measured::Weight.new(12, :oz) == Measured::Weight.new("12", :ounce)
50
+ > true
47
51
  ```
48
52
 
49
53
  Raises on unknown units:
@@ -60,39 +64,39 @@ Parse from string without having to split out the value and unit first:
60
64
 
61
65
  ```ruby
62
66
  Measured::Weight.parse("123 grams")
63
- > #<Measured::Weight 123 g>
67
+ > #<Measured::Weight: 123 #<Measured::Unit: g (gram, grams)>>
64
68
  ```
65
69
 
66
70
  Parse can scrub extra whitespace and split number from unit:
67
71
 
68
72
  ```ruby
69
73
  Measured::Weight.parse(" 2kg ")
70
- > #<Measured::Weight 2 kg>
74
+ > #<Measured::Weight: 2 #<Measured::Unit: kg (kilogram, kilograms) 1000/1 g>>
71
75
  ```
72
76
 
73
77
  Perform addition / subtraction against other units, all represented internally as `Rational` or `BigDecimal`:
74
78
 
75
79
  ```ruby
76
80
  Measured::Weight.new(1, :g) + Measured::Weight.new(2, :g)
77
- > #<Measured::Weight 3 g>
81
+ > #<Measured::Weight: 3 #<Measured::Unit: g (gram, grams)>>
78
82
  Measured::Weight.new("2.1", :g) - Measured::Weight.new(1, :g)
79
- > #<Measured::Weight 1.1 g>
83
+ > #<Measured::Weight: 1.1 #<Measured::Unit: g (gram, grams)>>
80
84
  ```
81
85
 
82
86
  Multiplication and division by units is not supported, but the actual value can be scaled by a scalar:
83
87
 
84
88
  ```ruby
85
89
  Measured::Weight.new(10, :g).scale(0.5)
86
- > #<Measured::Weight 5 g>
90
+ > #<Measured::Weight: 5 #<Measured::Unit: g (gram, grams)>>
87
91
  Measured::Weight.new(2, :g).scale(3)
88
- > #<Measured::Weight 6 g>
92
+ > #<Measured::Weight: 6 #<Measured::Unit: g (gram, grams)>>
89
93
  ```
90
94
 
91
95
  In cases of differing units, the left hand side takes precedence:
92
96
 
93
97
  ```ruby
94
98
  Measured::Weight.new(1000, :g) + Measured::Weight.new(1, :kg)
95
- > #<Measured::Weight 2000 g>
99
+ > #<Measured::Weight: 2000 #<Measured::Unit: g (gram, grams)>>
96
100
  ```
97
101
 
98
102
  Converts units only as needed for equality comparison:
@@ -107,33 +111,33 @@ Extract the unit and the value:
107
111
  ```ruby
108
112
  weight = Measured::Weight.new("1.2", "grams")
109
113
  weight.value
110
- > #<BigDecimal 1.2>
114
+ > #<BigDecimal:7fabf6c1d0a0,'0.12E1',18(18)>
111
115
  weight.unit
112
- > "g"
116
+ > #<Measured::Unit: g (gram, grams)>
113
117
  ```
114
118
 
115
119
  See all valid units:
116
120
 
117
121
  ```ruby
118
- Measured::Weight.units
122
+ Measured::Weight.unit_names
119
123
  > ["g", "kg", "lb", "oz"]
120
124
  ```
121
125
 
122
126
  Check if a unit is a valid unit or alias:
123
127
 
124
128
  ```ruby
125
- Measured::Weight.valid_unit?(:g)
129
+ Measured::Weight.unit_or_alias?(:g)
126
130
  > true
127
- Measured::Weight.valid_unit?("gram")
131
+ Measured::Weight.unit_or_alias?("gram")
128
132
  > true
129
- Measured::Weight.valid_unit?("stone")
133
+ Measured::Weight.unit_or_alias?("stone")
130
134
  > false
131
135
  ```
132
136
 
133
137
  See all valid units with their aliases:
134
138
 
135
139
  ```ruby
136
- Measured::Weight.units_with_aliases
140
+ Measured::Weight.unit_names_with_aliases
137
141
  > ["g", "gram", "grams", "kg", "kilogram", "kilograms", "lb", "lbs", "ounce", "ounces", "oz", "pound", "pounds"]
138
142
  ```
139
143
 
@@ -166,6 +170,7 @@ There is a shortcut initialization syntax for modules inside the `Measured` name
166
170
 
167
171
  ```ruby
168
172
  Measured::Weight(1, :g)
173
+ > #<Measured::Weight: 1 #<Measured::Unit: g (gram, grams)>>
169
174
  ```
170
175
 
171
176
  ### Adding new units
@@ -212,7 +217,6 @@ Existing alternatives which were considered:
212
217
  ### Gem: [quantified](https://github.com/Shopify/quantified)
213
218
  * **Pros**
214
219
  * Lightweight.
215
- * Included with ActiveShipping/ActiveUtils.
216
220
  * **Cons**
217
221
  * All math done with floats making it highly lossy.
218
222
  * All units assumed to be pluralized, meaning using unit abbreviations is not possible.
@@ -222,7 +226,7 @@ Existing alternatives which were considered:
222
226
  ### Gem: [unitwise](https://github.com/joshwlewis/unitwise)
223
227
  * **Pros**
224
228
  * Well written and maintained.
225
- * Conversions done with Unified Code for Units of Measure (UCUM) so highly accurate and reliable.
229
+ * Conversions done with Unified Code for Units of Measure (UCUM) so highly accurate and reliable.
226
230
  * **Cons**
227
231
  * Lots of code. Good code, but lots of it.
228
232
  * Many modifications to core types.
@@ -1,3 +1,3 @@
1
1
  module Measured
2
- VERSION = "2.0.0.pre4"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: measured
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin McPhillips
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-29 00:00:00.000000000 Z
11
+ date: 2017-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -151,9 +151,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
151
  version: '0'
152
152
  required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  requirements:
154
- - - ">"
154
+ - - ">="
155
155
  - !ruby/object:Gem::Version
156
- version: 1.3.1
156
+ version: '0'
157
157
  requirements: []
158
158
  rubyforge_project:
159
159
  rubygems_version: 2.5.2