interior 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.8.7
3
+
4
+ notifications:
5
+ recipients: chunt@climate.com
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Interior
1
+ Interior ![Travis CI Status](https://secure.travis-ci.org/climate/interior.png)
2
2
  ========
3
3
 
4
4
  Township GeoCoder Web Service
@@ -12,19 +12,24 @@ Interior uses the GeoCommunicator GeoCoder Web Service provided by the
12
12
 
13
13
  Usage
14
14
  -----
15
- Given township `1N`, range `1E`, section `35`, and meridian `14` (see the US Meridian table below, this is the Gila-Salt River meridian), we can get the center point latitude and longitude in the state of Arizona with:
15
+ Given township `1N`, range `1E`, section `35`, and meridian `14` (Gila-Salt Meridian
16
+ in the US Meridian table), we can get the center point latitude and longitude
17
+ in the state of Arizona with:
16
18
 
17
19
  require 'interior'
18
20
  response = Interior::Geocoder.get_lat_lon('AZ', 14, 1, 'N', 1, 'E', 35)
19
- response.latitude => 33.384549272498
20
- response.longitude => -112.228362739723
21
+ response.success? => true
22
+ response.latitude => 33.384549272498
23
+ response.longitude => -112.228362739723
21
24
 
22
- Section is option. If omitted, the centerpoint latitude and longitude will be for the township and range:
25
+ Section is option. If omitted, the centerpoint latitude and longitude will be for
26
+ the township and range:
23
27
 
24
28
  require 'interior'
25
29
  response = Interior::Geocoder.get_lat_lon('AZ', 14, 1, 'N', 1, 'E') # No section
26
- response.latitude => 33.4211630233451
27
- response.longitude => -112.254699834217
30
+ response.success? => true
31
+ response.latitude => 33.4211630233451
32
+ response.longitude => -112.254699834217
28
33
 
29
34
  US Meridian Map
30
35
  ---------------
data/Rakefile CHANGED
@@ -1,10 +1,22 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
3
 
4
- desc 'Default: Run all specs'
5
- task :default => :spec
4
+ desc 'Default: Run specs'
5
+ task :default => 'spec:fast'
6
6
 
7
7
  desc "Run all specs"
8
8
  RSpec::Core::RakeTask.new do |t|
9
9
  t.rspec_opts = ['--color', '-d']
10
10
  end
11
+
12
+ namespace :spec do
13
+ desc "Run enemy spec"
14
+ RSpec::Core::RakeTask.new(:enemy) do |t|
15
+ t.rspec_opts = ['--color', '-d', '--tag', 'enemy']
16
+ end
17
+
18
+ desc "Run all specs except enemy spec"
19
+ RSpec::Core::RakeTask.new(:fast) do |t|
20
+ t.rspec_opts = ['--color', '-d', '--tag', '~enemy']
21
+ end
22
+ end
data/interior.gemspec CHANGED
@@ -13,11 +13,12 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.rubyforge_project = "interior"
15
15
 
16
- s.files = `git ls-files`.split("\n")
16
+ s.files = `git ls-files | grep -v maps`.split("\n")
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
+ s.add_development_dependency "rake"
21
22
  s.add_development_dependency "rspec"
22
23
  s.add_development_dependency "ruby-debug"
23
24
 
@@ -20,7 +20,7 @@ module Interior
20
20
  trs = build_trs_param(st, me, to, to_dir, ra, ra_dir, se)
21
21
  xml = get_response_body(trs)
22
22
  result = parse_xml(xml)
23
- result ? Interior::Response.new(result[:lat], result[:lon]) : nil
23
+ result ? Interior::Response.new(result[:lat], result[:lon], true) : Interior::Response.new
24
24
  end
25
25
 
26
26
  private
@@ -2,9 +2,14 @@ module Interior
2
2
  class Response
3
3
  attr_reader :latitude, :longitude
4
4
 
5
- def initialize(latitude, longitude)
5
+ def initialize(latitude = nil, longitude = nil, success = false)
6
6
  @latitude = latitude
7
7
  @longitude = longitude
8
+ @success = success
9
+ end
10
+
11
+ def success?
12
+ @success
8
13
  end
9
14
  end
10
15
  end
@@ -1,3 +1,3 @@
1
1
  module Interior
2
- VERSION = "0.8.2"
2
+ VERSION = "0.8.3"
3
3
  end
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <TownshipGeocoderResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.esri.com/">
3
+ <CompletionStatus>false</CompletionStatus>
4
+ <Message>Invalid Township,Range,Section... specified: AZ,14,1,0,N,1,0,E,INVALID,,0</Message>
5
+ </TownshipGeocoderResult>
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <TownshipGeocoderResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.esri.com/">
3
+ <CompletionStatus>true</CompletionStatus>
4
+ <Message>Ok</Message>
5
+ <Data>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
6
+
7
+ &lt;rss version="2.0" xmlns:georss="http://www.georss.org/georss"&gt;
8
+ &lt;channel&gt;
9
+ &lt;title&gt;Township GeoCoder&lt;/title&gt;
10
+ &lt;item&gt;
11
+ &lt;title&gt;Lat Lon&lt;/title&gt;
12
+ &lt;link&gt;http://www.geocommunicator.gov&lt;/link&gt;
13
+ &lt;description&gt;Latitude(33.4211630233451), Longitude(-112.254699834217)&lt;/description&gt;
14
+ &lt;pubDate&gt;1/18/2012 1:08:10 PM&lt;/pubDate&gt;
15
+ &lt;georss:point&gt;-112.254699834217 33.4211630233451&lt;/georss:point&gt;
16
+ &lt;/item&gt;
17
+
18
+ &lt;item&gt;&lt;title&gt;Township Range Section&lt;/title&gt;
19
+ &lt;link&gt;http://www.geocommunicator.gov&lt;/link&gt;
20
+ &lt;description&gt;AZ,14,1,0,N,1,0,E,0,,0&lt;/description&gt;
21
+ &lt;pubDate&gt;1/18/2012 1:08:10 PM&lt;/pubDate&gt;
22
+ &lt;georss:polygon&gt;33.465903569199668,-112.20321220653472,33.462309315982509,-112.2032735108433,33.458715016199164,-112.20333483843484,33.455140739851231,-112.20334010040739,33.451566416936942,-112.20334536237994,33.447976377954433,-112.20341409398594,33.444386338971867,-112.2034828488753,33.440796299989358,-112.20355162704749,33.437206237723558,-112.20362038193667,33.433604650341124,-112.20363020738984,33.430003039675569,-112.20364000955993,33.426407552456,-112.20376417814242,33.4228120652362,-112.20388832344173,33.419203213537628,-112.2038964492312,33.415594408405241,-112.20390457502066,33.411993007287094,-112.20390508724807,33.408391582886111,-112.20390555290936,33.404755699549639,-112.20390071003197,33.401119816213395,-112.20389589043765,33.397011519500268,-112.20352035789205,33.392903222787311,-112.20314482534639,33.389017069791805,-112.202928898207,33.385130963362258,-112.20271301763404,33.38124485693271,-112.20249709049477,33.377358727220269,-112.20228120992169,33.377355607289644,-112.2028021452046,33.377352044980796,-112.20661525922719,33.377348040293725,-112.21094930853258,33.3773479937276,-112.21140542376412,33.377333325397046,-112.21530184459107,33.377316934119563,-112.21965433408337,33.377315932947795,-112.22005654902097,33.377313464942972,-112.22295871314896,33.3773114858825,-112.22400412274044,33.377309949200253,-112.22473576975597,33.377309762935738,-112.22508655240432,33.377309134293,-112.22616916833266,33.37730785372446,-112.22833437690628,33.377306363608341,-112.22906648958326,33.377305152888994,-112.23266758802146,33.377303662772874,-112.23339967741526,33.3773024054874,-112.23700079913635,33.377300938654344,-112.23773309807802,33.377296095776956,-112.24132518597031,33.377294489245514,-112.24205788072362,33.377289646368126,-112.24564782657399,33.377288039836685,-112.24638480541148,33.3772831969593,-112.24997042061182,33.377281543861727,-112.25070958805719,33.377276747550468,-112.25429306121549,33.377274931471447,-112.25503746735063,33.377269250403742,-112.25861414185431,33.377267434324722,-112.25935184246646,33.377261706690888,-112.26293498966203,33.377259890611867,-112.26366838290761,33.377254162978033,-112.26725588403616,33.377252393465142,-112.26798275802355,33.377246665831308,-112.27157675512694,33.377244873035352,-112.27229960114448,33.37723851675878,-112.27589725368904,33.377236700679759,-112.27661970389414,33.377230344403188,-112.28021735643881,33.377228528324167,-112.28094197196907,33.377222172047595,-112.28453745918876,33.377220355968575,-112.2852620747189,33.377213999692,-112.28885758522148,33.377211880933146,-112.28958573977769,33.377202497858036,-112.29318402096499,33.377200542080629,-112.29391168657651,33.377191112439561,-112.29750994448085,33.377189179945219,-112.29823758680948,33.377177142600942,-112.30182969798483,33.377175093691278,-112.30255626929238,33.3771694591897,-112.30441809953703,33.377168108771968,-112.30492422679089,33.377164360198606,-112.30614251313534,33.380698892355724,-112.30614735601273,33.380822548710739,-112.30614765869257,33.384483507907476,-112.30615336304334,33.388116620559288,-112.30615587761429,33.391749733210872,-112.30615839218524,33.395349644212729,-112.30616065064248,33.398949555214756,-112.30616288581666,33.40254986202865,-112.30616598246422,33.406150192125665,-112.30616907911178,33.409782420020974,-112.30619832264091,33.41341464791617,-112.30622754288669,33.417047341472767,-112.30625867234375,33.420680011746356,-112.30628982508392,33.424420505891021,-112.30621725177224,33.42816100003563,-112.30614472502646,33.431818490055832,-112.30626225793571,33.435475980075978,-112.30637981412781,33.439042689428049,-112.30639236369956,33.442609398780064,-112.30640491327125,33.446176084849071,-112.30641743955988,33.449742770918022,-112.30642996584862,33.453320539725667,-112.30642523938656,33.456898308533255,-112.30642046635825,33.460500152029624,-112.30641811476875,33.464101995525823,-112.30641576317925,33.464169632827975,-112.30268309214426,33.464260576477386,-112.29835511971857,33.464347399024575,-112.29404800891865,33.4644341982887,-112.28974089811879,33.464514292030117,-112.28543315867614,33.464594339205576,-112.28112541923355,33.464671359582496,-112.27681847141508,33.464748403242652,-112.27251154687957,33.464825982413288,-112.26813996527443,33.464903538300689,-112.26376838366917,33.464981094188261,-112.25939680206403,33.465058650075889,-112.25502522045878,33.465126194245613,-112.25071738788375,33.465193715132443,-112.24640957859208,33.465407593361874,-112.24212670546217,33.465621471591476,-112.23784378576619,33.465556767955604,-112.23351064450031,33.465492064319562,-112.22917752651739,33.465583380498174,-112.22487074168038,33.465674696676615,-112.22056393356036,33.465720121935362,-112.216255216229,33.465765547193939,-112.21194652218077,33.465834558196889,-112.20757936435768,33.465903569199668,-112.20321220653472&lt;/georss:polygon&gt;
23
+ &lt;/item&gt;&lt;/channel&gt;&lt;/rss&gt;</Data>
24
+ </TownshipGeocoderResult>
@@ -4,60 +4,102 @@ require 'interior/geocoder.rb'
4
4
  describe Interior::Geocoder do
5
5
  let(:coder) { Interior::Geocoder }
6
6
 
7
- describe '#get_lat_lon' do
8
- let (:st) { 'AZ' }
9
- let (:me) { 14 }
10
- let (:to) { 1 }
11
- let (:to_dir) { 'N' }
12
- let (:ra) { 1 }
13
- let (:ra_dir) { 'E' }
7
+ let(:st) { 'AZ' }
8
+ let(:me) { 14 }
9
+ let(:to) { 1 }
10
+ let(:to_dir) { 'N' }
11
+ let(:ra) { 1 }
12
+ let(:ra_dir) { 'E' }
13
+ let(:se) { 35 }
14
+
15
+ # Full integration enemy test
16
+ describe 'enemy_test', :enemy => true do
17
+ subject do
18
+ coder.get_lat_lon(st, me, to, to_dir, ra, ra_dir, se)
19
+ end
14
20
 
15
- subject { coder.get_lat_lon(st, me, to, to_dir, ra, ra_dir, se) }
21
+ it 'returns correct response' do
22
+ subject.success?.should == true
23
+ subject.latitude.should == 33.384549272498
24
+ subject.longitude.should == -112.228362739723
25
+ end
26
+ end
27
+
28
+ describe '#get_lat_lon' do
29
+ subject do
30
+ # use xml fixtures for interior web service
31
+ Net::HTTP.stub(:get_response => double('response', :body => body))
32
+ coder.get_lat_lon(st, me, to, to_dir, ra, ra_dir, se)
33
+ end
16
34
 
17
35
  context 'with section' do
18
- let (:se) { 35 }
36
+ let(:body) { File.open('spec/fixtures/az.xml').read }
19
37
 
20
- it 'returns the correct latitude and longitude' do
38
+ it 'returns successful response' do
39
+ subject.success?.should == true
40
+ end
41
+
42
+ it 'returns correct latitude' do
21
43
  subject.latitude.should == 33.384549272498
44
+ end
45
+
46
+ it 'returns correct longitude' do
22
47
  subject.longitude.should == -112.228362739723
23
48
  end
24
49
  end
25
50
 
26
51
  context 'without section' do
27
- let (:se) { nil }
52
+ let(:se) { nil }
53
+ let(:body) { File.open('spec/fixtures/az_no_section.xml').read }
28
54
 
29
- it 'returns the correct latitude and longitude' do
55
+ it 'returns successful response' do
56
+ subject.success?.should == true
57
+ end
58
+
59
+ it 'returns correct latitude' do
30
60
  subject.latitude.should == 33.4211630233451
61
+ end
62
+
63
+ it 'returns correct longitude' do
31
64
  subject.longitude.should == -112.254699834217
32
65
  end
33
66
  end
67
+
68
+ context 'with invalid parameters' do
69
+ let(:se) { 'INVALID' }
70
+ let(:body) { File.open('spec/fixtures/az_invalid_section.xml').read }
71
+
72
+ it 'returns unsuccessful response' do
73
+ subject.success?.should == false
74
+ end
75
+
76
+ it 'returns nil for latitude' do
77
+ subject.latitude.should == nil
78
+ end
79
+
80
+ it 'returns nil for longitude' do
81
+ subject.longitude.should == nil
82
+ end
83
+ end
34
84
  end
35
85
 
36
86
  describe '#build_trs_param' do
37
87
  subject { coder.send(:build_trs_param, st, me, to, to_dir, ra, ra_dir, se) }
38
88
 
39
89
  context 'when in Arizona' do
40
- let (:st) { 'AZ' }
41
- let (:me) { 14 }
42
- let (:to) { 1 }
43
- let (:to_dir) { 'N' }
44
- let (:ra) { 1 }
45
- let (:ra_dir) { 'E' }
46
- let (:se) { 35 }
47
-
48
90
  it 'returns the correct trs param' do
49
91
  subject.should == "AZ,14,1,0,N,1,0,E,35,,0"
50
92
  end
51
93
  end
52
94
 
53
95
  context 'when in Colorado' do
54
- let (:st) { 'CO' }
55
- let (:me) { 06 }
56
- let (:to) { 1 }
57
- let (:to_dir) { 'S' }
58
- let (:ra) { 68 }
59
- let (:ra_dir) { 'W' }
60
- let (:se) { 16 }
96
+ let(:st) { 'CO' }
97
+ let(:me) { 06 }
98
+ let(:to) { 1 }
99
+ let(:to_dir) { 'S' }
100
+ let(:ra) { 68 }
101
+ let(:ra_dir) { 'W' }
102
+ let(:se) { 16 }
61
103
 
62
104
  it 'returns the correct trs param' do
63
105
  subject.should == "CO,6,1,0,S,68,0,W,16,,0"
@@ -65,13 +107,7 @@ describe Interior::Geocoder do
65
107
  end
66
108
 
67
109
  context 'when missing section' do
68
- let (:st) { 'AZ' }
69
- let (:me) { 14 }
70
- let (:to) { 1 }
71
- let (:to_dir) { 'N' }
72
- let (:ra) { 1 }
73
- let (:ra_dir) { 'E' }
74
- let (:se) { nil }
110
+ let(:se) { nil }
75
111
 
76
112
  it 'defaults to section 0' do
77
113
  subject.should == "AZ,14,1,0,N,1,0,E,0,,0"
@@ -4,7 +4,23 @@ require 'interior/response.rb'
4
4
  describe Interior::Response do
5
5
  let(:latitude) { 30 }
6
6
  let(:longitude) { 60 }
7
- let(:response) { Interior::Response.new(latitude, longitude) }
7
+ let(:success) { true }
8
+ let(:response) { Interior::Response.new(latitude, longitude, success) }
9
+
10
+ describe('#success?') do
11
+ it 'defaults to false' do
12
+ Interior::Response.new.success?.should == false
13
+ end
14
+
15
+ it 'can be initialized' do
16
+ response.success?.should == true
17
+ end
18
+
19
+ it 'is readonly' do
20
+ lambda { response.success = false }.should raise_error
21
+ end
22
+
23
+ end
8
24
 
9
25
  describe('#latitude') do
10
26
  it 'can be initialized' do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interior
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
4
+ hash: 57
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 2
10
- version: 0.8.2
9
+ - 3
10
+ version: 0.8.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Hunt
@@ -18,7 +18,7 @@ cert_chain: []
18
18
  date: 2012-01-18 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: rspec
21
+ name: rake
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
@@ -32,7 +32,7 @@ dependencies:
32
32
  type: :development
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
- name: ruby-debug
35
+ name: rspec
36
36
  prerelease: false
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  none: false
@@ -46,7 +46,7 @@ dependencies:
46
46
  type: :development
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
- name: nokogiri
49
+ name: ruby-debug
50
50
  prerelease: false
51
51
  requirement: &id003 !ruby/object:Gem::Requirement
52
52
  none: false
@@ -57,8 +57,22 @@ dependencies:
57
57
  segments:
58
58
  - 0
59
59
  version: "0"
60
- type: :runtime
60
+ type: :development
61
61
  version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: nokogiri
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ type: :runtime
75
+ version_requirements: *id004
62
76
  description: Find the center latitude/longitude for any grid in the PLSS given township, range, and section.
63
77
  email:
64
78
  - chunt@climate.com
@@ -71,6 +85,7 @@ extra_rdoc_files: []
71
85
  files:
72
86
  - .gitignore
73
87
  - .rvmrc
88
+ - .travis.yml
74
89
  - Gemfile
75
90
  - README.md
76
91
  - Rakefile
@@ -79,9 +94,9 @@ files:
79
94
  - lib/interior/geocoder.rb
80
95
  - lib/interior/response.rb
81
96
  - lib/interior/version.rb
82
- - maps/meridians.jpg
83
- - maps/meridians_small.jpg
84
97
  - spec/fixtures/az.xml
98
+ - spec/fixtures/az_invalid_section.xml
99
+ - spec/fixtures/az_no_section.xml
85
100
  - spec/fixtures/co.xml
86
101
  - spec/lib/interior/geocoder_spec.rb
87
102
  - spec/lib/interior/response_spec.rb
@@ -121,6 +136,8 @@ specification_version: 3
121
136
  summary: Convert PLSS to latitude and longitude
122
137
  test_files:
123
138
  - spec/fixtures/az.xml
139
+ - spec/fixtures/az_invalid_section.xml
140
+ - spec/fixtures/az_no_section.xml
124
141
  - spec/fixtures/co.xml
125
142
  - spec/lib/interior/geocoder_spec.rb
126
143
  - spec/lib/interior/response_spec.rb
data/maps/meridians.jpg DELETED
Binary file
Binary file