silva 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/silva/exception.rb +1 -1
- data/lib/silva/system/base.rb +2 -2
- data/lib/silva/system/gridref.rb +5 -7
- data/lib/silva/version.rb +1 -1
- data/test/test_gridref.rb +2 -3
- metadata +1 -1
data/lib/silva/exception.rb
CHANGED
@@ -3,5 +3,5 @@ module Silva
|
|
3
3
|
class InvalidTransformError < StandardError; end
|
4
4
|
class InvalidParamError < StandardError; end
|
5
5
|
class InvalidParamValueError < StandardError; end
|
6
|
-
class
|
6
|
+
class InsufficientParamsError < StandardError; end
|
7
7
|
end
|
data/lib/silva/system/base.rb
CHANGED
@@ -30,7 +30,7 @@ module Silva
|
|
30
30
|
#
|
31
31
|
def initialize(options)
|
32
32
|
@system_name = self.class.name.split('::').last.downcase.to_sym
|
33
|
-
options = DEFAULT_PARAMS.merge(options)
|
33
|
+
options = self.class::DEFAULT_PARAMS.merge(options)
|
34
34
|
params_satisfied?(options)
|
35
35
|
options.each {|param, val| set_param(param, val) }
|
36
36
|
end
|
@@ -61,7 +61,7 @@ module Silva
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def params_satisfied?(options)
|
64
|
-
raise InsufficientParamsError unless REQUIRED_PARAMS & options.keys == REQUIRED_PARAMS
|
64
|
+
raise Silva::InsufficientParamsError unless self.class::REQUIRED_PARAMS & options.keys == self.class::REQUIRED_PARAMS
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
data/lib/silva/system/gridref.rb
CHANGED
@@ -28,8 +28,6 @@ module Silva
|
|
28
28
|
# Height of the UK grid
|
29
29
|
OSGB_GRID_SCALE = 100000
|
30
30
|
|
31
|
-
attr_reader :gridref
|
32
|
-
|
33
31
|
##
|
34
32
|
# Lazily create the gridref from given eastings and northings, or just return it if already set.
|
35
33
|
#
|
@@ -37,14 +35,14 @@ module Silva
|
|
37
35
|
#
|
38
36
|
def gridref
|
39
37
|
unless @gridref
|
40
|
-
e100k = (
|
41
|
-
n100k = (
|
38
|
+
e100k = (easting / 100000).floor
|
39
|
+
n100k = (northing / 100000).floor
|
42
40
|
|
43
41
|
index = n100k * OSGB_GRID_WIDTH + e100k
|
44
42
|
prefix = OSGB_PREFIXES[index]
|
45
43
|
|
46
|
-
e = ((
|
47
|
-
n = ((
|
44
|
+
e = ((easting % OSGB_GRID_SCALE) / (10**(5 - @digits / 2))).round
|
45
|
+
n = ((northing % OSGB_GRID_SCALE) / (10**(5 - @digits / 2))).round
|
48
46
|
|
49
47
|
@gridref = prefix + e.to_s.rjust(@digits / 2) + n.to_s.rjust(@digits / 2)
|
50
48
|
end
|
@@ -98,7 +96,7 @@ module Silva
|
|
98
96
|
end
|
99
97
|
|
100
98
|
def params_satisfied?(options)
|
101
|
-
super
|
99
|
+
super unless options.include?(:gridref)
|
102
100
|
end
|
103
101
|
end
|
104
102
|
end
|
data/lib/silva/version.rb
CHANGED
data/test/test_gridref.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
class TestGridref < Test::Unit::TestCase
|
2
|
-
def
|
2
|
+
def test_gridref_no_digits
|
3
3
|
Silva::Test::DATA.each do |data|
|
4
|
-
|
5
|
-
l = Silva::Location.from(:gridref, options)
|
4
|
+
l = Silva::Location.from(:en, data[:en]).to(:gridref)
|
6
5
|
assert_equal(data[:gridref], l.to_s)
|
7
6
|
end
|
8
7
|
end
|