Skip to content

Commit

Permalink
Adds for method to location, to allow text input
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Nichols committed Mar 23, 2016
1 parent 0b96d83 commit 17a58cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/os_map_ref/location.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
require 'matrix'
module OsMapRef
class Location

def self.for(text)
input_processor = InputProcessor.new(text)
new input_processor.params
end

def initialize(args={})
@map_reference = args[:map_reference].freeze if args[:map_reference]
@easting = args[:easting].to_i if args[:easting]
Expand Down
15 changes: 15 additions & 0 deletions test/os_map_ref/location_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
module OsMapRef
class LocationTest < Minitest::Test

def test_for_with_map_reference
@location = Location.for map_reference
assert_equal map_reference, @location.map_reference
end

def test_for_with_map_reference_with_no_spaces
@location = Location.for map_reference.delete(' ')
assert_equal map_reference, @location.map_reference
end

def test_for_with_easting_and_northing
@location = Location.for [easting, northing].join(' ')
assert_equal map_reference, @location.map_reference
end

def test_new_with_map_reference
@location = Location.new map_reference: map_reference
assert_equal map_reference, @location.map_reference
Expand Down

0 comments on commit 17a58cf

Please sign in to comment.