quantify 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/quantify.rb +3 -1
- data/lib/quantify/config.rb +243 -243
- data/lib/quantify/core_extensions/numeric.rb +19 -0
- data/lib/quantify/core_extensions/string.rb +29 -0
- data/lib/quantify/core_extensions/symbol.rb +7 -0
- data/lib/quantify/dimensions.rb +19 -21
- data/lib/quantify/quantify.rb +32 -1
- data/lib/quantify/quantity.rb +37 -37
- data/lib/quantify/unit/base_unit.rb +113 -61
- data/lib/quantify/unit/compound_base_unit.rb +54 -14
- data/lib/quantify/unit/compound_unit.rb +42 -18
- data/lib/quantify/unit/non_si_unit.rb +1 -1
- data/lib/quantify/unit/prefix/base_prefix.rb +5 -5
- data/lib/quantify/unit/prefix/prefix.rb +4 -4
- data/lib/quantify/unit/unit.rb +55 -24
- data/spec/compound_unit_spec.rb +205 -0
- data/spec/dimension_spec.rb +49 -1
- data/spec/quantify_spec.rb +20 -0
- data/spec/quantity_spec.rb +9 -9
- data/spec/string_spec.rb +55 -0
- data/spec/unit_spec.rb +292 -10
- metadata +24 -19
- data/lib/quantify/core_extensions.rb +0 -63
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
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.5
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Berkeley
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06
|
18
|
+
date: 2011-07-06 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -43,27 +43,32 @@ extra_rdoc_files: []
|
|
43
43
|
files:
|
44
44
|
- README
|
45
45
|
- COPYING
|
46
|
-
- lib/quantify.rb
|
47
|
-
- lib/quantify/
|
46
|
+
- lib/quantify/unit/prefix/non_si_prefix.rb
|
47
|
+
- lib/quantify/unit/prefix/base_prefix.rb
|
48
|
+
- lib/quantify/unit/prefix/si_prefix.rb
|
49
|
+
- lib/quantify/unit/prefix/prefix.rb
|
50
|
+
- lib/quantify/unit/unit.rb
|
51
|
+
- lib/quantify/unit/base_unit.rb
|
52
|
+
- lib/quantify/unit/si_unit.rb
|
53
|
+
- lib/quantify/unit/compound_base_unit.rb
|
54
|
+
- lib/quantify/unit/compound_unit.rb
|
55
|
+
- lib/quantify/unit/non_si_unit.rb
|
48
56
|
- lib/quantify/config.rb
|
49
|
-
- lib/quantify/core_extensions.rb
|
57
|
+
- lib/quantify/core_extensions/string.rb
|
58
|
+
- lib/quantify/core_extensions/numeric.rb
|
59
|
+
- lib/quantify/core_extensions/symbol.rb
|
50
60
|
- lib/quantify/dimensions.rb
|
61
|
+
- lib/quantify/inflections.rb
|
51
62
|
- lib/quantify/exception.rb
|
52
63
|
- lib/quantify/quantity.rb
|
53
|
-
- lib/quantify/
|
54
|
-
- lib/quantify
|
55
|
-
- lib/quantify/unit/compound_unit.rb
|
56
|
-
- lib/quantify/unit/non_si_unit.rb
|
57
|
-
- lib/quantify/unit/si_unit.rb
|
58
|
-
- lib/quantify/unit/unit.rb
|
59
|
-
- lib/quantify/unit/compound_base_unit.rb
|
60
|
-
- lib/quantify/unit/prefix/base_prefix.rb
|
61
|
-
- lib/quantify/unit/prefix/non_si_prefix.rb
|
62
|
-
- lib/quantify/unit/prefix/si_prefix.rb
|
63
|
-
- lib/quantify/unit/prefix/prefix.rb
|
64
|
+
- lib/quantify/quantify.rb
|
65
|
+
- lib/quantify.rb
|
64
66
|
- spec/dimension_spec.rb
|
65
|
-
- spec/
|
67
|
+
- spec/string_spec.rb
|
68
|
+
- spec/compound_unit_spec.rb
|
66
69
|
- spec/quantity_spec.rb
|
70
|
+
- spec/unit_spec.rb
|
71
|
+
- spec/quantify_spec.rb
|
67
72
|
has_rdoc: true
|
68
73
|
homepage: https://github.com/spatchcock/quantify
|
69
74
|
licenses: []
|
@@ -1,63 +0,0 @@
|
|
1
|
-
|
2
|
-
class String
|
3
|
-
|
4
|
-
def standardize
|
5
|
-
self.gsub("_"," ")
|
6
|
-
end
|
7
|
-
|
8
|
-
def to_power index
|
9
|
-
name = self.clone
|
10
|
-
case index
|
11
|
-
when 1 then name
|
12
|
-
when 2 then "square #{name}"
|
13
|
-
when 3 then "cubic #{name}"
|
14
|
-
else
|
15
|
-
ordinal = ActiveSupport::Inflector.ordinalize index
|
16
|
-
name << " to the #{ordinal} power"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def words
|
21
|
-
split(/\s+/)
|
22
|
-
end
|
23
|
-
|
24
|
-
def word_count
|
25
|
-
words.size
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_quantity
|
29
|
-
Quantify::Quantity.parse self
|
30
|
-
end
|
31
|
-
|
32
|
-
alias :to_q :to_quantity
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
class Symbol
|
37
|
-
|
38
|
-
def standardize
|
39
|
-
self.to_s.standardize
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
class Numeric
|
45
|
-
|
46
|
-
# Syntactic sugar for defining instances of the Quantity class.
|
47
|
-
#
|
48
|
-
# Enables quantities to be specified by using unit names, symbols or JScience
|
49
|
-
# labels as argments on Numeric objects, e.g.
|
50
|
-
#
|
51
|
-
# 1.5.metre is equivalent to Quantity. new 1.5, :metre
|
52
|
-
#
|
53
|
-
# 1000.t is equivalent to Quantity. new 1000, :t
|
54
|
-
#
|
55
|
-
def method_missing(method, *args, &block)
|
56
|
-
if unit = Unit.for(method.to_s)
|
57
|
-
Quantify::Quantity.new self, unit
|
58
|
-
else
|
59
|
-
super
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|