dimensional 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -1
- data/lib/dimensional.rb +1 -1
- data/lib/dimensional/metric.rb +2 -2
- data/lib/dimensional/system.rb +1 -5
- data/lib/dimensional/version.rb +3 -0
- data/test/metric_test.rb +9 -0
- metadata +2 -1
data/Rakefile
CHANGED
@@ -3,6 +3,7 @@ require 'rake/testtask'
|
|
3
3
|
require 'rake/rdoctask'
|
4
4
|
require 'rake/gempackagetask'
|
5
5
|
require 'rubygems'
|
6
|
+
require 'lib/dimensional/version'
|
6
7
|
|
7
8
|
task :default => [:test]
|
8
9
|
|
@@ -16,7 +17,7 @@ Rake::Task['test'].comment = "Run all tests in test/*_test.rb"
|
|
16
17
|
spec = Gem::Specification.new do |s|
|
17
18
|
s.platform = Gem::Platform::RUBY
|
18
19
|
s.name = %q{dimensional}
|
19
|
-
s.version =
|
20
|
+
s.version = Dimensional::VERSION
|
20
21
|
s.required_ruby_version = '>= 1.6.8'
|
21
22
|
s.date = %q{2009-10-09}
|
22
23
|
s.authors = ["Chris Hapgood"]
|
data/lib/dimensional.rb
CHANGED
data/lib/dimensional/metric.rb
CHANGED
@@ -29,7 +29,7 @@ module Dimensional
|
|
29
29
|
def initialize(name, dimension, parent = nil)
|
30
30
|
@name = name && name.to_s
|
31
31
|
@dimension = dimension
|
32
|
-
@units =
|
32
|
+
@units = {}
|
33
33
|
@parent = parent
|
34
34
|
end
|
35
35
|
|
@@ -45,7 +45,7 @@ module Dimensional
|
|
45
45
|
|
46
46
|
def preferences(u)
|
47
47
|
baseline = parent ? parent.preferences(u) : {}
|
48
|
-
baseline.merge(@units[u])
|
48
|
+
baseline.merge(@units[u] || {})
|
49
49
|
end
|
50
50
|
|
51
51
|
# How "preferred" is the given unit for this metric?
|
data/lib/dimensional/system.rb
CHANGED
@@ -3,8 +3,6 @@ require 'delegate'
|
|
3
3
|
module Dimensional
|
4
4
|
# Represents a set of units for comprehensive measurement of physical quantities.
|
5
5
|
class System < DelegateClass(String)
|
6
|
-
PRIORITY = []
|
7
|
-
|
8
6
|
@registry = Hash.new
|
9
7
|
@abbreviation_registry = Hash.new
|
10
8
|
|
@@ -14,7 +12,6 @@ module Dimensional
|
|
14
12
|
raise "System #{s}'s abbreviation already exists" if @abbreviation_registry[s.abbreviation]
|
15
13
|
@registry[s.to_sym] = s
|
16
14
|
@abbreviation_registry[s.abbreviation.to_sym] = s if s.abbreviation
|
17
|
-
PRIORITY << s
|
18
15
|
const_set(s.abbreviation, s) rescue nil # Not all symbols strings are valid constant names
|
19
16
|
s
|
20
17
|
end
|
@@ -27,8 +24,7 @@ module Dimensional
|
|
27
24
|
|
28
25
|
# Purge all systems from storage.
|
29
26
|
def self.reset!
|
30
|
-
constants.each {|d| remove_const(d)
|
31
|
-
PRIORITY.clear
|
27
|
+
constants.each {|d| remove_const(d)}
|
32
28
|
@registry.clear
|
33
29
|
@abbreviation_registry.clear
|
34
30
|
end
|
data/test/metric_test.rb
CHANGED
@@ -87,4 +87,13 @@ class MetricTest < Test::Unit::TestCase
|
|
87
87
|
assert length.to_enum.kind_of?(Enumerable::Enumerator)
|
88
88
|
assert_respond_to length, :map
|
89
89
|
end
|
90
|
+
|
91
|
+
def test_preferences_query_does_not_modify_preferences
|
92
|
+
draft = Metric.register('draft', Dimension::L)
|
93
|
+
foot = Unit[:L, :BA, 'foot']
|
94
|
+
p0 = draft.preference(foot)
|
95
|
+
draft.preferences(foot)
|
96
|
+
p1 = draft.preference(foot)
|
97
|
+
assert_equal p0, p1
|
98
|
+
end
|
90
99
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dimensional
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Hapgood
|
@@ -29,6 +29,7 @@ files:
|
|
29
29
|
- lib/dimensional/metric.rb
|
30
30
|
- lib/dimensional/system.rb
|
31
31
|
- lib/dimensional/unit.rb
|
32
|
+
- lib/dimensional/version.rb
|
32
33
|
- lib/dimensional.rb
|
33
34
|
- test/configurator_test.rb
|
34
35
|
- test/demo.rb
|