quantify 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +76 -70
- metadata +3 -3
data/README
CHANGED
@@ -5,105 +5,111 @@ Homepage: https://github.com/spatchcock/quantify
|
|
5
5
|
|
6
6
|
Examples
|
7
7
|
|
8
|
-
unit = Unit.km #=> #<Quantify::Unit::SI:0xb75c9718 ... >
|
9
|
-
unit.name #=> 'kilometre'
|
10
|
-
unit.symbol #=> 'kg'
|
11
|
-
unit.dimensions #=> #<Quantify::Dimensions:0xb75c4254 .. >
|
12
|
-
unit.measures #=> 'length'
|
13
|
-
unit.alternatives :name #=> ['metre', 'megametre', 'gigametre', 'terametre', 'angstrom',
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
other_unit = Unit.hour
|
19
|
-
other_unit.name #=> 'hour'
|
20
|
-
other_unit.symbol #=> 'h'
|
21
|
-
other_unit.measures #=> 'time'
|
22
|
-
other_unit.alternatives :symbol #=> [ 's', 'ks', 'Ms', 'Gs', 'Ts', 'd', 'min' ]
|
23
|
-
|
24
|
-
another_unit = unit / other_unit #=> #<Quantify::Unit::Compound:0xb74af323 ... >
|
25
|
-
another_unit.name #=> 'kilometer per hour'
|
26
|
-
another_unit.symbol #=> 'km h^-1'
|
27
|
-
another_unit.measures #=> 'velocity'
|
28
|
-
|
29
|
-
last_unit = Unit.m
|
30
|
-
last.unit.measures #=> 'length'
|
31
|
-
square = last_unit ** 2 #=> #<Quantify::Unit::Compound:0xb446f12f ... >
|
32
|
-
square.symbol #=> 'm^2'
|
33
|
-
square.measures #=> 'area'
|
34
|
-
|
35
|
-
----
|
8
|
+
unit = Unit.km #=> #<Quantify::Unit::SI:0xb75c9718 ... >
|
9
|
+
unit.name #=> 'kilometre'
|
10
|
+
unit.symbol #=> 'kg'
|
11
|
+
unit.dimensions #=> #<Quantify::Dimensions:0xb75c4254 .. >
|
12
|
+
unit.measures #=> 'length'
|
13
|
+
unit.alternatives :name #=> ['metre', 'megametre', 'gigametre', 'terametre', 'angstrom',
|
14
|
+
# 'astronomical unit', 'baromil', 'chain', 'dram', 'ell', 'fathom',
|
15
|
+
# 'fermi', 'foot us survey', 'foot', 'furlong', 'hand', 'inch',
|
16
|
+
# 'nautical league', 'statute league', 'light year', 'line',
|
17
|
+
# 'link', 'yard']
|
18
|
+
other_unit = Unit.hour
|
19
|
+
other_unit.name #=> 'hour'
|
20
|
+
other_unit.symbol #=> 'h'
|
21
|
+
other_unit.measures #=> 'time'
|
22
|
+
other_unit.alternatives :symbol #=> [ 's', 'ks', 'Ms', 'Gs', 'Ts', 'd', 'min' ]
|
23
|
+
|
24
|
+
another_unit = unit / other_unit #=> #<Quantify::Unit::Compound:0xb74af323 ... >
|
25
|
+
another_unit.name #=> 'kilometer per hour'
|
26
|
+
another_unit.symbol #=> 'km h^-1'
|
27
|
+
another_unit.measures #=> 'velocity'
|
28
|
+
|
29
|
+
last_unit = Unit.m
|
30
|
+
last.unit.measures #=> 'length'
|
31
|
+
square = last_unit ** 2 #=> #<Quantify::Unit::Compound:0xb446f12f ... >
|
32
|
+
square.symbol #=> 'm^2'
|
33
|
+
square.measures #=> 'area'
|
36
34
|
|
37
35
|
Define quantity - method 1
|
38
|
-
|
39
|
-
quantity.
|
40
|
-
quantity.
|
41
|
-
quantity.unit
|
36
|
+
|
37
|
+
quantity = Quantity.new(1234.5678, :lb) #=> #<Quantify::Quantity:0xjk39d570 ... >
|
38
|
+
quantity.value #=> 1234.5678
|
39
|
+
quantity.unit #=> #<Quantify::Unit::NonSI:0xb182124 ... >
|
40
|
+
quantity.unit.symbol #=> 'lb'
|
42
41
|
|
43
42
|
Define quantity - method 2
|
44
|
-
|
45
|
-
|
46
|
-
quantity.
|
43
|
+
|
44
|
+
string = quantity.to_s #=> "1234.5678 lb"
|
45
|
+
quantity = Quantity.parse(string) #=> #<Quantify::Quantity:0xj982b4f9 ... >
|
46
|
+
quantity.to_s #=> "1234.5678 lb"
|
47
47
|
|
48
48
|
Define quantity - method 3
|
49
|
-
|
50
|
-
quantity
|
49
|
+
|
50
|
+
quantity = 1234.5678.lb #=> #<Quantify::Quantity:02387f7340 ... >
|
51
|
+
quantity.to_s #=> "1234.5678 lb"
|
51
52
|
|
52
53
|
Multiply by scalar
|
53
|
-
|
54
|
-
new_quantity
|
54
|
+
|
55
|
+
new_quantity = quantity * 4 #=> #<Quantify::Quantity:87b37f720 ... >
|
56
|
+
new_quantity.to_s #=> "4938.2712 lb"
|
55
57
|
|
56
58
|
Convert unit
|
57
|
-
converted_quantity = new_quantity.to_kg #=> #<Quantify::Quantity:0b8787a688 ... >
|
58
|
-
converted_quantity.to_s #=> "2239.96213731074 kg"
|
59
59
|
|
60
|
-
|
60
|
+
converted_quantity = new_quantity.to_kg #=> #<Quantify::Quantity:0b8787a688 ... >
|
61
|
+
converted_quantity.to_s #=> "2239.96213731074 kg"
|
61
62
|
|
62
63
|
One line conversion of a quantity to a new unit
|
63
64
|
5000 litres into US petroleum barrels
|
64
65
|
|
65
|
-
5000.L.to_bbl.value #=> 31.4490528488754
|
66
|
-
|
67
|
-
----
|
66
|
+
5000.L.to_bbl.value #=> 31.4490528488754
|
68
67
|
|
69
68
|
Complex example
|
70
69
|
|
71
70
|
Define energy units
|
72
|
-
kW = Unit.kW #=> #<Quantify::Unit::SI:0xb7586620 ... >
|
73
|
-
kW.name #=> 'kilowatt'
|
74
|
-
kW.measures #=> 'power'
|
75
71
|
|
76
|
-
|
77
|
-
|
78
|
-
|
72
|
+
kW = Unit.kW #=> #<Quantify::Unit::SI:0xb7586620 ... >
|
73
|
+
kW.name #=> 'kilowatt'
|
74
|
+
kW.measures #=> 'power'
|
75
|
+
|
76
|
+
h = Unit.h #=> #<Quantify::Unit::NonSI:0xb7582994 ... >
|
77
|
+
h.symbol #=> 'h'
|
78
|
+
h.measures #=> 'time'
|
79
79
|
|
80
80
|
Create compound unit for energy
|
81
|
-
|
82
|
-
kWh
|
83
|
-
kWh.
|
84
|
-
kWh.
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
81
|
+
|
82
|
+
kWh = kW / h #=> #<Quantify::Unit::Compound:0xb756b0b4 ... >
|
83
|
+
kWh.name #=> 'kilowatt hour'
|
84
|
+
kWh.measures #=> 'energy'
|
85
|
+
kWh.alternatives :symbol #=> ['J', 'kJ', 'MJ', 'GJ', 'TJ', 'BTU', 'cal', 'CHU',
|
86
|
+
# 'dyn cm', 'eV', 'erg', 'Eh']
|
87
|
+
kWh.alternatives :name #=> ['joule', 'kilojoule', 'megajoule', 'gigajoule',
|
88
|
+
# 'terajoule', 'british thermal unit', 'calorie',
|
89
|
+
# 'celsius heat unit', 'dyne centimetre', 'electron volt',
|
90
|
+
# 'erg', 'hartree']
|
90
91
|
|
91
92
|
Create mass unit
|
92
|
-
|
93
|
+
|
94
|
+
kg = Unit.kg #=> #<Quantify::Unit::SI:0xb758b594 ... >
|
93
95
|
|
94
96
|
Create emission factor compound unit
|
95
|
-
|
96
|
-
kg_per_kWh
|
97
|
-
kg_per_kWh.
|
97
|
+
|
98
|
+
kg_per_kWh = kg / kWh #=> #<Quantify::Unit::Compound:0xb746f093 ... >
|
99
|
+
kg_per_kWh.symbol #=> "kg_kW^-1_h^-1
|
100
|
+
kg_per_kWh.name #=> 'kilogram per kilowatt hour'
|
98
101
|
|
99
102
|
Create emission factor quantity
|
100
|
-
|
101
|
-
emission_factor.
|
103
|
+
|
104
|
+
emission_factor = Quantity.new(0.54, kg_per_kWh) #=> #<Quantify::Quantity:0xb75cd570 ... >
|
105
|
+
emission_factor.to_s #=> "0.54 kg kW^-1 h^-1"
|
102
106
|
|
103
107
|
Create consumption quantity
|
104
|
-
|
105
|
-
consumption.
|
108
|
+
|
109
|
+
consumption = Quantity.new(9885.5, kWh) #=> #<Quantify::Quantity:0xb7j4k3570 ... >
|
110
|
+
consumption.to_s #=> "9885.5 kWh"
|
106
111
|
|
107
112
|
Calculate emissions
|
108
|
-
|
109
|
-
emissions
|
113
|
+
|
114
|
+
emissions = consumption * emission_factor #=> #<Quantify::Quantity:0xb456g2s70 ... >
|
115
|
+
emissions.to_s #=> "5338.17 kg"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quantify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Berkeley
|