os_map_ref 0.2.0 → 0.3.0

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: 63ae3fcaaf973eec7b4724150197b0ab202538be
4
- data.tar.gz: 08a5ebe1a235a599ea73648a2b0a8718134f3b7b
3
+ metadata.gz: 12d54845568c88b7000830b89f9cf22dc0dd869f
4
+ data.tar.gz: 3724276fae454400abc143894458372ae74f012a
5
5
  SHA512:
6
- metadata.gz: de6195a4927e318ebc2c00cf8c61677ee3a9d144cbbf1cd3a76ce80920e5768ff4a2810272d979917e90a39841f2866d4e55dbcc360c65513231be3b93b4b322
7
- data.tar.gz: e21af0b63498777aa48e6ec7b2e6ab6dc1ac5dc6ece9f94b9eb9c3e7fc397f2fb8e409adf3a219fdbb52be4441a7a7fa6a25e29c83c7280a267accf733d826f2
6
+ metadata.gz: a89ed1be4cc0d2651a61ba9a1cba8bbc5ccf2b83bdf2fec3f2071f29b9ea44c2a0cd172a673a0c05da8645d2370146a0ff9e53d9dfc94ac78124405bf83828e6
7
+ data.tar.gz: 2b2fe98324f2e80b6550d5459c63120bebb0a3ed46ac334f10ff0fc9b11689c9a35673c028bafb78679dc159ac4bc833a87598b377c361cdd6650d1056d9720f
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml CHANGED
@@ -1,4 +1,16 @@
1
1
  language: ruby
2
+ cache: bundler
3
+
2
4
  rvm:
3
5
  - 2.2.3
6
+
4
7
  before_install: gem install bundler -v 1.11.2
8
+
9
+ # Have this option to stop travis-ci building twice. Currently we have travis set to build both
10
+ # PR's and pushes. However this means when we push to a PR we have to wait for Travis to finish
11
+ # 2 builds. If we unticked 'pushes' when the PR was finally merged that would not be built. The
12
+ # brute force approach would be to untick build PR's and just build all pushes. We instead have
13
+ # gone with the approach outlined here http://stackoverflow.com/a/31882307
14
+ branches:
15
+ only:
16
+ - master
data/README.md CHANGED
@@ -1,27 +1,33 @@
1
1
  # OsMapRef
2
2
 
3
+ [![Build Status](https://travis-ci.org/EnvironmentAgency/os_map_ref.svg?branch=master)](https://travis-ci.org/EnvironmentAgency/os_map_ref)
4
+
3
5
  This gem allows you to gather U.K. Ordnance Survey Eastings, North, and Map
4
6
  References from a range of text inputs.
5
7
 
6
8
  ## Installation
7
9
 
8
- Add this line to your application's Gemfile:
10
+ Add this line to your application's Gemfile
9
11
 
10
12
  ```ruby
11
13
  gem 'os_map_ref'
12
14
  ```
13
15
 
14
- And then execute:
16
+ And then update your dependencies by calling
15
17
 
16
- $ bundle
18
+ ```bash
19
+ $ bundle install
20
+ ```
17
21
 
18
- Or install it yourself as:
22
+ Or install it yourself as
19
23
 
20
- $ gem install os_map_ref
24
+ ```bash
25
+ $ gem install os_map_ref
26
+ ```
21
27
 
22
28
  ## Usage
23
29
 
24
- To convert a map reference to eastings and northings:
30
+ To convert a map reference to eastings and northings
25
31
 
26
32
  ```ruby
27
33
  location = OsMapRef::Location.for 'ST5880171043'
@@ -31,7 +37,7 @@ location.northing == 171043
31
37
  location.map_reference == 'ST 58801 71043'
32
38
  ```
33
39
 
34
- To convert eastings and northings to a map reference:
40
+ To convert eastings and northings to a map reference
35
41
 
36
42
  ```ruby
37
43
  location = OsMapRef::Location.for '358801, 171043'
@@ -44,7 +50,7 @@ location.map_reference == 'ST 58801 71043'
44
50
  ### From OS Map Reference to Longitude and Latitude
45
51
 
46
52
  If your end result needs to be longitude and latitude, you can combine the
47
- OsMapRef output with that of another gem:
53
+ OsMapRef output with that of another gem called
48
54
  [global_convert](https://github.com/reggieb/global_convert)
49
55
 
50
56
  For example
@@ -78,9 +84,11 @@ for an interactive prompt that will allow you to experiment.
78
84
 
79
85
  To install this gem onto your local machine, run `bundle exec rake install`.
80
86
 
81
- ## Contributing
87
+ ## Contributing to this project
88
+
89
+ If you have an idea you'd like to contribute please log an issue.
82
90
 
83
- Bug reports and pull requests are welcome on GitHub at https://github.com/reggieb/os_map_ref.
91
+ All contributions should be submitted via a pull request.
84
92
 
85
93
  ## License
86
94
 
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
 
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList['test/**/*_test.rb']
4
+ begin
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ rescue LoadError
8
8
  end
9
9
 
10
- task :spec => :test
10
+ task :test => :spec
11
11
 
12
12
  task :default => :test
@@ -58,12 +58,12 @@ module OsMapRef
58
58
  end
59
59
 
60
60
  def padded_map_reference_easting
61
- map_reference_easting.ljust(5, '0')
61
+ map_reference_easting.ljust((normal_length - 1), padding)
62
62
  end
63
63
 
64
64
  def padded_map_reference_northing
65
- target_length = northing_longer_than_easting? ? 6 : 5
66
- map_reference_northing.ljust(target_length, '0')
65
+ target_length = northing_longer_than_easting? ? extended_length : normal_length
66
+ map_reference_northing.ljust((target_length - 1), padding)
67
67
  end
68
68
 
69
69
  def northing_longer_than_easting?
@@ -80,11 +80,41 @@ module OsMapRef
80
80
 
81
81
  def get_easting_and_northing
82
82
  match = easting_northing_pattern.match input
83
- (1..2).collect{|n| match[n].ljust(6, '0').to_i}
84
- end
85
-
83
+ easting = match[1]
84
+ northing = match[3]
85
+ length = northing.length > easting.length ? extended_length : normal_length
86
+ [
87
+ easting.ljust(normal_length, padding),
88
+ northing.ljust(length, padding)
89
+ ]
90
+ end
91
+
92
+ def extended_length
93
+ normal_length + 1
94
+ end
95
+
96
+ def normal_length
97
+ 6
98
+ end
99
+
100
+ def padding
101
+ '0'
102
+ end
103
+
104
+ # Matches are:
105
+ # 1: First digits which may be followed with a decimal point and more digits
106
+ # 2: The decimal point and trailing digits from first match (if present)
107
+ # 3: Second digits which may be followed with a decimal point and more digits
108
+ # 4: The decimal point and trailing digits from second match (if present)
109
+ # So:
110
+ # "1234.5, 6789.0" --> 1: "1234.5", 2: ".5", 3: "6789.0", 4: ".0"
111
+ # "1234 6789" --> 1: "1234", 2: nil, 3: "6789", 4: nil
86
112
  def easting_northing_pattern
87
- /(\d{3,6})[\,\s]+(\d{3,6})/
113
+ eastings = /\d{3,6}/ # 3 to 6 digits
114
+ northings = /\d{3,7}/ # 3 to 7 digits
115
+ decimals = /\.\d+/ # decimal point and trailing digits
116
+ separator = /[\,\s]+/ # commas or spaces
117
+ /(#{eastings}(#{decimals})?)#{separator}(#{northings}(#{decimals})?)/
88
118
  end
89
119
  end
90
120
  end
@@ -9,8 +9,12 @@ module OsMapRef
9
9
 
10
10
  def initialize(args={})
11
11
  @map_reference = args[:map_reference].freeze if args[:map_reference]
12
- @easting = args[:easting].to_i if args[:easting]
13
- @northing = args[:northing].to_i if args[:northing]
12
+ @easting = remove_decimals(args[:easting]) if args[:easting]
13
+ @northing = remove_decimals(args[:northing]) if args[:northing]
14
+ end
15
+
16
+ def remove_decimals(number)
17
+ number.to_s.sub /\.\d*/, ""
14
18
  end
15
19
 
16
20
  def map_reference
@@ -26,7 +30,7 @@ module OsMapRef
26
30
  end
27
31
 
28
32
  def short_easting
29
- easting.to_s[1..-1].to_i
33
+ easting.to_s[1..-1]
30
34
  end
31
35
 
32
36
  def long_northing?
@@ -38,7 +42,7 @@ module OsMapRef
38
42
  end
39
43
 
40
44
  def short_northing
41
- northing.to_s[chars_in_northing_start..-1].to_i
45
+ northing.to_s[chars_in_northing_start..-1]
42
46
  end
43
47
 
44
48
  def chars_in_northing_start
@@ -50,11 +54,11 @@ module OsMapRef
50
54
  end
51
55
 
52
56
  def easting
53
- @easting ||= easting_from_map_reference.to_i
57
+ @easting ||= easting_from_map_reference
54
58
  end
55
59
 
56
60
  def northing
57
- @northing ||= northing_from_map_reference.to_i
61
+ @northing ||= northing_from_map_reference
58
62
  end
59
63
 
60
64
  def northing_from_map_reference
@@ -1,3 +1,3 @@
1
1
  module OsMapRef
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/os_map_ref.gemspec CHANGED
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.11"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "minitest", "~> 5.0"
25
+ spec.add_development_dependency "rspec"
25
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: os_map_ref
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Nichols
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-31 00:00:00.000000000 Z
11
+ date: 2016-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: This gem allows you to gather U.K. Ordnance Survey Eastings, North, and
56
70
  Map References from a range of text inputs; and output them in a consistent manner
57
71
  email:
@@ -61,6 +75,7 @@ extensions: []
61
75
  extra_rdoc_files: []
62
76
  files:
63
77
  - ".gitignore"
78
+ - ".rspec"
64
79
  - ".travis.yml"
65
80
  - Gemfile
66
81
  - LICENSE