os_map_ref 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/lib/os_map_ref/input_processor.rb +87 -86
- data/lib/os_map_ref/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e2b921bf19f2d0da1e4137e3d99405406c3b0bd
|
4
|
+
data.tar.gz: 3ab34f8c15a09653a0fe9832c6d2582f12fba8ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5aa6dadbd16152dc75dbadf0bb18fba8861c884687e1562912316279355fd06bb9f789ce3c1ce5b3a4d2efa2d77c57177b90803a0c41dd8d7a67b239c9338e3f
|
7
|
+
data.tar.gz: c87a6547421f334dc30ca1f71b271043773139fcff45a38924426b57424d476261f8c7f1eb027965b1d7c07d7c9553ff0106f55690b6c59b9d501c0cbb930515
|
@@ -1,89 +1,90 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
1
|
+
module OsMapRef
|
2
|
+
class InputProcessor
|
3
|
+
attr_reader :input
|
4
|
+
|
5
|
+
def initialize(input)
|
6
|
+
@input = input
|
7
|
+
end
|
8
|
+
|
9
|
+
def params
|
10
|
+
case input
|
11
|
+
when map_reference_pattern
|
12
|
+
map_reference_params
|
13
|
+
when easting_northing_pattern
|
14
|
+
easting_northing_params
|
15
|
+
else
|
16
|
+
raise OsMapRef::Error, "Unable to process input #{input}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def map_reference_params
|
21
|
+
{map_reference: processed_map_reference}
|
22
|
+
end
|
23
|
+
|
24
|
+
def easting_northing_params
|
25
|
+
{
|
26
|
+
easting: easting_and_northing[0],
|
27
|
+
northing: easting_and_northing[1]
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def processed_map_reference
|
32
|
+
[
|
33
|
+
grid_letters,
|
34
|
+
padded_map_reference_easting,
|
35
|
+
padded_map_reference_northing
|
36
|
+
].join(' ')
|
37
|
+
end
|
38
|
+
|
39
|
+
def map_reference_elements
|
40
|
+
@map_reference_elements ||= get_map_reference_elements
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_map_reference_elements
|
44
|
+
match = map_reference_pattern.match input
|
45
|
+
(1..3).collect{|n| match[n]}
|
46
|
+
end
|
47
|
+
|
48
|
+
def grid_letters
|
49
|
+
map_reference_elements[0]
|
50
|
+
end
|
51
|
+
|
52
|
+
def map_reference_easting
|
53
|
+
map_reference_elements[1]
|
54
|
+
end
|
55
|
+
|
56
|
+
def map_reference_northing
|
57
|
+
map_reference_elements[2]
|
58
|
+
end
|
59
|
+
|
60
|
+
def padded_map_reference_easting
|
61
|
+
map_reference_easting.ljust(5, '0')
|
62
|
+
end
|
63
|
+
|
64
|
+
def padded_map_reference_northing
|
65
|
+
target_length = northing_longer_than_easting? ? 6 : 5
|
66
|
+
map_reference_northing.ljust(target_length, '0')
|
67
|
+
end
|
68
|
+
|
69
|
+
def northing_longer_than_easting?
|
70
|
+
map_reference_northing.length > map_reference_easting.length
|
71
|
+
end
|
72
|
+
|
73
|
+
def map_reference_pattern
|
74
|
+
/([a-zA-Z]{2})\s*(\d{3,5})\s*(\d{3,6})/
|
75
|
+
end
|
76
|
+
|
77
|
+
def easting_and_northing
|
78
|
+
@easting_and_northing ||= get_easting_and_northing
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_easting_and_northing
|
82
|
+
match = easting_northing_pattern.match input
|
83
|
+
(1..2).collect{|n| match[n].ljust(6, '0').to_i}
|
84
|
+
end
|
85
|
+
|
86
|
+
def easting_northing_pattern
|
87
|
+
/(\d{3,6})[\,\s]+(\d{3,6})/
|
16
88
|
end
|
17
89
|
end
|
18
|
-
|
19
|
-
def map_reference_params
|
20
|
-
{map_reference: processed_map_reference}
|
21
|
-
end
|
22
|
-
|
23
|
-
def easting_northing_params
|
24
|
-
{
|
25
|
-
easting: easting_and_northing[0],
|
26
|
-
northing: easting_and_northing[1]
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
def processed_map_reference
|
31
|
-
[
|
32
|
-
grid_letters,
|
33
|
-
padded_map_reference_easting,
|
34
|
-
padded_map_reference_northing
|
35
|
-
].join(' ')
|
36
|
-
end
|
37
|
-
|
38
|
-
def map_reference_elements
|
39
|
-
@map_reference_elements ||= get_map_reference_elements
|
40
|
-
end
|
41
|
-
|
42
|
-
def get_map_reference_elements
|
43
|
-
match = map_reference_pattern.match input
|
44
|
-
(1..3).collect{|n| match[n]}
|
45
|
-
end
|
46
|
-
|
47
|
-
def grid_letters
|
48
|
-
map_reference_elements[0]
|
49
|
-
end
|
50
|
-
|
51
|
-
def map_reference_easting
|
52
|
-
map_reference_elements[1]
|
53
|
-
end
|
54
|
-
|
55
|
-
def map_reference_northing
|
56
|
-
map_reference_elements[2]
|
57
|
-
end
|
58
|
-
|
59
|
-
def padded_map_reference_easting
|
60
|
-
map_reference_easting.ljust(5, '0')
|
61
|
-
end
|
62
|
-
|
63
|
-
def padded_map_reference_northing
|
64
|
-
target_length = northing_longer_than_easting? ? 6 : 5
|
65
|
-
map_reference_northing.ljust(target_length, '0')
|
66
|
-
end
|
67
|
-
|
68
|
-
def northing_longer_than_easting?
|
69
|
-
map_reference_northing.length > map_reference_easting.length
|
70
|
-
end
|
71
|
-
|
72
|
-
def map_reference_pattern
|
73
|
-
/([a-zA-Z]{2})\s*(\d{3,5})\s*(\d{3,6})/
|
74
|
-
end
|
75
|
-
|
76
|
-
def easting_and_northing
|
77
|
-
@easting_and_northing ||= get_easting_and_northing
|
78
|
-
end
|
79
|
-
|
80
|
-
def get_easting_and_northing
|
81
|
-
match = easting_northing_pattern.match input
|
82
|
-
(1..2).collect{|n| match[n].ljust(6, '0').to_i}
|
83
|
-
end
|
84
|
-
|
85
|
-
def easting_northing_pattern
|
86
|
-
/(\d{3,6})[\,\s]+(\d{3,6})/
|
87
|
-
end
|
88
|
-
|
89
90
|
end
|
data/lib/os_map_ref/version.rb
CHANGED