os_map_ref 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d3a6d62d55bbfca44fd8031064e34087eb938e9
4
- data.tar.gz: 4793331eb8dddfd7033762b3df45bcfe188bf07a
3
+ metadata.gz: 3e2b921bf19f2d0da1e4137e3d99405406c3b0bd
4
+ data.tar.gz: 3ab34f8c15a09653a0fe9832c6d2582f12fba8ac
5
5
  SHA512:
6
- metadata.gz: 9638109a89f0295e16fec3a4c2e03a029f9aba6c905baa21f412dda6765eb13f8d37c36d54ff3e203ba148e4bd0dc09eab0111f9f4328bc99e754778abe0fb3b
7
- data.tar.gz: b0dcce127c708d994d3c7e96c8173a8630d911aab28434ab20324e909efc1be3eaca192a3b27dd233df12aff6f9451c49ed56a0f6c2d030910827baa7f81dfc7
6
+ metadata.gz: 5aa6dadbd16152dc75dbadf0bb18fba8861c884687e1562912316279355fd06bb9f789ce3c1ce5b3a4d2efa2d77c57177b90803a0c41dd8d7a67b239c9338e3f
7
+ data.tar.gz: c87a6547421f334dc30ca1f71b271043773139fcff45a38924426b57424d476261f8c7f1eb027965b1d7c07d7c9553ff0106f55690b6c59b9d501c0cbb930515
@@ -1,89 +1,90 @@
1
- class InputProcessor
2
- attr_reader :input
3
-
4
- def initialize(input)
5
- @input = input
6
- end
7
-
8
- def params
9
- case input
10
- when map_reference_pattern
11
- map_reference_params
12
- when easting_northing_pattern
13
- easting_northing_params
14
- else
15
- raise OsMapRef::Error, "Unable to process input #{input}"
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
@@ -1,3 +1,3 @@
1
1
  module OsMapRef
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: os_map_ref
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Nichols