rats 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NmRmYmQ4MGUzMzQ1ZDFkNWUzMzlkZTJmZmViM2IzMDU0NjU2OGZkYQ==
5
+ data.tar.gz: !binary |-
6
+ YTc3NjhiY2QxMTRkMDk0NmM2Y2E3NGQxZGMzYzdkMzY4OWFkY2VkOQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MjEzZTJjNDM0YWRhNjY0MmNiZWE1NTBlYTY1ODZlMGM1ZjUxZmUzZjIxYjkz
10
+ NWZiYTdmMmZmYzJjNzAzZjQyNzI1MWRhNWE5ZTMxOTQwZTM0NTI3ZjJkOWVl
11
+ NDllMWMzNjBiMjA4ZDRjNmNlODNhNmE4ZmY0ODRlMTZjNmExYWU=
12
+ data.tar.gz: !binary |-
13
+ YWFjMWZkNTM4MGVhMDdlMzM2ODBiNmUwNmI1ZWI3ZDdjNjE1MzgzYzNmMWJi
14
+ YWNiOTI1OTJlZGI3Zjc0MzQyNjQ1YzY0Y2I2N2IwMjJjZTBhYTM1NmY1OWYy
15
+ YWY0N2RlODVmNGUxODU0YmEzNmUzZTRhNjQzZmUwYmE0Y2QxZTI=
data/.gitignore CHANGED
@@ -1,22 +1,6 @@
1
- ## MAC OS
2
1
  .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
2
  coverage
18
3
  rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
22
4
  docs
5
+ Gemfile.lock
6
+ pkg
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,9 @@
1
+ rvm:
2
+ - 2.1.0
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ script: 'bundle exec rake'
7
+ branches:
8
+ only:
9
+ - master
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'rake'
5
+
6
+ group :development, :test do
7
+ gem 'rspec', '>= 2.11'
8
+ gem 'mocha'
9
+ end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2010 Mark G
1
+ Copyright (c) 2009-2014 Mark Gangl
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,13 +1,16 @@
1
- = rats
1
+ # rats
2
+ [![Build Status](https://travis-ci.org/attack/rats.png)](https://travis-ci.org/attack/rats)
2
3
 
3
4
  a.k.a. Ruby Alberta Township System
4
5
 
5
6
  A ruby class to help with using the Alberta Township System. This class will allow
6
7
  you to create and represent townships, sections and quarter sections.
7
8
 
8
- You may find it amusing that Alberta is Rat-free ... until now.
9
+ #### Status
9
10
 
10
- == ATS
11
+ This gem is not under active development, but is still maintained.
12
+
13
+ ## ATS
11
14
 
12
15
  Alberta Township system is a land survey grid used in Alberta, Canada that
13
16
  divides the whole province into addressable locations.
@@ -16,7 +19,7 @@ A typical location looks like: NE 1-2-3 W4
16
19
 
17
20
  Which can be broken down as follows ...
18
21
 
19
- === Meridian
22
+ ### Meridian
20
23
 
21
24
  from above example: [= W4] or West of the 4th Meridian
22
25
 
@@ -25,7 +28,7 @@ and increments approx. every 4th line of longitude, from East to West.
25
28
 
26
29
  Alberta contains 3 of these Meridians, W4 through W6.
27
30
 
28
- === Range
31
+ ### Range
29
32
  a.k.a Range Lines
30
33
 
31
34
  from above example: [= 3]
@@ -36,7 +39,7 @@ resets at the next Meridian. Each increase is approx. every 6 miles.
36
39
  NOTE: The longitude lines are closer together the further North you get, so as
37
40
  you go North, there is less Ranges from East to West.
38
41
 
39
- === Township
42
+ ### Township
40
43
  a.k.a. Township Lines
41
44
 
42
45
  from above example: [= 2]
@@ -49,7 +52,7 @@ NOTE: The 6x6 mile "square" indicated by the Township (line) + Range (line) +
49
52
  Meridian is confusingly called a Township. So you have the Township line and
50
53
  the 6x6 mile Township "square".
51
54
 
52
- === Section
55
+ ### Section
53
56
 
54
57
  from above example: [= 1]
55
58
 
@@ -59,7 +62,7 @@ There can be up to a maximum of 36 Sections in a township. The number starts wi
59
62
  North of number 6 and counts up West-to-East until the number 12. It snakes back
60
63
  and forth until it finishes at number 36 in the North-East corner.
61
64
 
62
- === Multi
65
+ ### Multi
63
66
  a.k.a. Multi Quarters
64
67
 
65
68
  from above example: [= N or = North]
@@ -74,7 +77,7 @@ The Multi Quarter Section represents a 1/2 x 1 mile + 1/2 x 1/2 mile area within
74
77
  They are identified by "NSE", "NSW", "ENW", "ESW", "SNE", "SNW", "WNE" and "WSE",
75
78
  "NWS", "NES", "SEN", "SWN", "NWE", "NEW", "SEW", "SWE".
76
79
 
77
- === Quarter
80
+ ### Quarter
78
81
  a.k.a. Quarter Section
79
82
 
80
83
  from above example: [= NE]
@@ -83,12 +86,12 @@ The Quarter represents a 1/2 x 1/2 mile square within the 1x1 mile Section.
83
86
  There can be 4 Quarters in a Section. They are identified by "NE", "NW", "SE"
84
87
  and "SW".
85
88
 
86
- == Purpose
89
+ ## Purpose
87
90
 
88
91
  The purpose of Rats is to make it easier to deal with location described using
89
92
  the Alberta Township System, at the Quarter, Section or Township level.
90
93
 
91
- === Validation
94
+ ### Validation
92
95
 
93
96
  Included is validations, only allowing you to describe locations that actually
94
97
  exist.
@@ -98,7 +101,7 @@ For example, Range-line 30 is valid for Township-lines 1-18, but not 18-126.
98
101
  NOTE: At the moment, invalid quarters within valid sections are not currently
99
102
  identified.
100
103
 
101
- === Parsing
104
+ ### Parsing
102
105
 
103
106
  Included is string parsing, allowing you to extract and separate the different
104
107
  fields from multiple string representations of the location.
@@ -106,7 +109,7 @@ fields from multiple string representations of the location.
106
109
  For example, NE 1-2-3 W4 and 40300201NE are both recognized and parsed, representing
107
110
  the same location.
108
111
 
109
- === Expansion/Division
112
+ ### Expansion/Division
110
113
 
111
114
  Townships, Sections and Half Sections can be divided into multiple Quarter Sections.
112
115
  1 Half Section = 2 Quarter Sections
@@ -117,87 +120,79 @@ Townships, Sections and Half Sections can be divided into multiple Quarter Secti
117
120
  For example, the Half Section N 1-2-3 W4 has the Quarter Sections NE 1-2-3 W4 and
118
121
  NW 1-2-3 W4.
119
122
 
120
- === Display
123
+ ### Display
121
124
 
122
125
  Included is string creation that can create common representations of the
123
126
  location.
124
127
 
125
- = Usage
128
+ # Usage
126
129
 
127
130
  Parse a location
128
131
 
129
- quarter_section = Rats.new("NE 1-2-3 W4")
132
+ ```ruby
133
+ quarter_section = Rats.new("NE 1-2-3 W4")
134
+ ```
130
135
 
131
136
  Print the location
132
137
 
133
- quarter_section.location
134
- quarter_section.location(:padded)
135
- quarter_section.location(:short)
136
- quarter_section.location(:long)
138
+ ```ruby
139
+ quarter_section.location
140
+ quarter_section.location(:padded)
141
+ quarter_section.location(:short)
142
+ quarter_section.location(:long)
143
+ ```
137
144
 
138
145
  Read the attributes
139
146
 
140
- quarter_section.quarter
141
- quarter_section.section
142
- quarter_section.township
143
- quarter_section.range
144
- quarter_section.meridian
145
-
147
+ ```ruby
148
+ quarter_section.quarter
149
+ quarter_section.section
150
+ quarter_section.township
151
+ quarter_section.range
152
+ quarter_section.meridian
153
+ ```
154
+
146
155
  Divide into multiple Quarter Sections
147
156
 
148
- half_section = Rats.new("N 1-2-3 W4")
149
- half_section.is_divisible?
150
- quarter_sections = half_section.divide
151
- # quarter_sections == [Rats.new("NE 1-2-3 W4"), Rats.new("NW 1-2-3 W4")]
157
+ ```ruby
158
+ half_section = Rats.new("N 1-2-3 W4")
159
+ half_section.is_divisible?
160
+ quarter_sections = half_section.divide
161
+ # quarter_sections == [Rats.new("NE 1-2-3 W4"), Rats.new("NW 1-2-3 W4")]
152
162
 
153
- multi_section = Rats.new("NSE 1-2-3 W4")
154
- multi_section.is_divisible?
155
- quarter_sections = multi_section.divide
156
- # quarter_sections == [Rats.new("NE 1-2-3 W4"), Rats.new("NW 1-2-3 W4"), Rats.new("SE 1-2-3 W4")]
163
+ multi_section = Rats.new("NSE 1-2-3 W4")
164
+ multi_section.is_divisible?
165
+ quarter_sections = multi_section.divide
166
+ # quarter_sections == [Rats.new("NE 1-2-3 W4"), Rats.new("NW 1-2-3 W4"), Rats.new("SE 1-2-3 W4")]
167
+ ```
157
168
 
158
- = Information
169
+ # Information
159
170
 
160
- == links
171
+ ## links
161
172
 
162
173
  http://en.wikipedia.org/wiki/Alberta_Township_System
163
174
 
164
- == Road Map
175
+ ## Road Map
165
176
 
166
177
  Future:
167
- - either correct the assumption that all quarters are valid in a valid
178
+ * either correct the assumption that all quarters are valid in a valid
168
179
  section, or remove validation completely (re: all or none)
169
- - add support for Saskatchewan (no timeline, need to find data)
170
- - address bugs, if any
171
-
172
- Except for the above, once this gem is finalized, I do not see future
173
- development happening unless I want to add ATS to other-system conversions
174
- (ie: latitude/longitude). Nothing else is planned.
180
+ * add support for Saskatchewan (no timeline, need to find data)
175
181
 
176
- Currently this point has not been reached and this gem is still in development.
177
-
178
- == Assumptions
182
+ ## Assumptions
179
183
 
180
184
  As currently written, I assume that within every valid section, all four quarters
181
185
  are valid. I know this to be incorrect, but I can not correct this until I know which
182
186
  cases this assumption breaks down.
183
187
 
184
- == Environment
185
-
186
- This gem was created using:
187
- - ruby 1.9.1-p378, 1.9.2-p0
188
- - rspec 1.3.0
189
- - rake 0.8.7
188
+ ## Contributing
190
189
 
191
- == Note on Patches/Pull Requests
192
-
193
- * Fork the project.
194
- * Make your feature addition or bug fix.
195
- * Add tests for it. This is important so I don't break it in a
196
- future version unintentionally.
197
- * Commit, do not mess with rakefile, version, or history.
198
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
199
- * Send me a pull request. Bonus points for topic branches.
190
+ 1. Fork it
191
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
192
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
193
+ 4. Push to the branch (`git push origin my-new-feature`)
194
+ 5. Create new Pull Request
200
195
 
201
- == Copyright
196
+ ## Copyright
202
197
 
203
- Copyright (c) 2010 Mark sG. See LICENSE for details.
198
+ Copyright (c) 2009-2014 Mark Gangl. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,46 +1,12 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "rats"
8
- gem.summary = "A ruby class to help with using the Alberta Township System"
9
- gem.description = "A ruby class to help with using the Alberta Township System"
10
- gem.email = "rats@attackcorp.com"
11
- gem.homepage = "http://github.com/attack/rats"
12
- gem.authors = ["Mark G"]
13
- #gem.add_development_dependency "rspec", ">= 1.2.9"
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
- end
20
-
21
- require 'spec/rake/spectask'
22
- Spec::Rake::SpecTask.new(:spec) do |spec|
23
- spec.libs << 'lib' << 'spec'
24
- spec.spec_files = FileList['spec/**/*_spec.rb']
25
- spec.spec_opts = ["-c"]
26
- end
4
+ require 'bundler/gem_tasks'
5
+ require 'rspec/core/rake_task'
27
6
 
28
- Spec::Rake::SpecTask.new(:rcov) do |spec|
29
- spec.libs << 'lib' << 'spec'
7
+ RSpec::Core::RakeTask.new(:spec) do |spec|
30
8
  spec.pattern = 'spec/**/*_spec.rb'
31
- spec.rcov = true
9
+ spec.rspec_opts = ["--color"]
32
10
  end
33
11
 
34
- task :spec => :check_dependencies
35
-
36
- task :default => :spec
37
-
38
- require 'rake/rdoctask'
39
- Rake::RDocTask.new do |rdoc|
40
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
-
42
- rdoc.rdoc_dir = 'rdoc'
43
- rdoc.title = "rats #{version}"
44
- rdoc.rdoc_files.include('README*')
45
- rdoc.rdoc_files.include('lib/**/*.rb')
46
- end
12
+ task default: :spec
@@ -1,21 +1,16 @@
1
- $:.unshift(File.dirname(__FILE__))
2
-
1
+ require 'rats/version'
3
2
  require 'rats/base'
4
3
  require 'rats/data'
5
4
  require 'rats/boundaries'
6
5
 
7
6
  module Rats
8
-
9
7
  def self.new(*args)
10
8
  Rats::Base.new(args)
11
9
  end
12
-
13
- # custom errors
14
- #
10
+
15
11
  class OutOfBounds < StandardError; end
16
12
  #class OutOfSection < OutOfBounds; end
17
13
  #class OutOfTownship < OutOfBounds; end
18
14
  #class OutOfMeridian < OutOfBounds; end
19
15
  #class OutOfAlberta < OutOfBounds; end
20
-
21
- end
16
+ end
@@ -1,8 +1,7 @@
1
1
  module Rats
2
2
  class Base
3
-
4
3
  attr_accessor :errors
5
-
4
+
6
5
  def initialize(*args)
7
6
  return unless args.flatten!
8
7
  @quarter = Rats::Quarter.new
@@ -17,13 +16,13 @@ module Rats
17
16
  set_values(args)
18
17
  end
19
18
  end
20
-
19
+
21
20
  def q; @quarter; end
22
21
  def s; @section; end
23
22
  def t; @township; end
24
23
  def r; @range; end
25
24
  def m; @meridian; end
26
-
25
+
27
26
  def q=(v); @quarter = v; end
28
27
  def s=(v); @section = v; end
29
28
  def t=(v); @township = v; end
@@ -59,11 +58,11 @@ module Rats
59
58
  return unless value
60
59
  if value.is_a?(Array)
61
60
  set_values(value)
62
- else
61
+ else
63
62
  parse_string(value)
64
63
  end
65
64
  end
66
-
65
+
67
66
  def to_s
68
67
  default_location
69
68
  end
@@ -88,20 +87,20 @@ module Rats
88
87
  end
89
88
  end
90
89
 
91
- def valid?
90
+ def valid?
92
91
  # check each data field individually
93
92
  [:meridian, :range, :township, :section, :quarter].each do |data|
94
93
  valid = self.send(data.to_s.chars.first).valid?
95
94
  add_error(data, self.send(data.to_s.chars.first).error) unless valid
96
95
  end
97
-
96
+
98
97
  # check each field as it relates to others
99
98
  self.exists? unless self.errors.size > 0
100
-
99
+
101
100
  # are we valid?
102
101
  self.errors.size == 0
103
102
  end
104
-
103
+
105
104
  # test that a location actually exists
106
105
  #
107
106
  def exists?
@@ -110,26 +109,26 @@ module Rats
110
109
  add_error(:land, 'does not exist')
111
110
  return false
112
111
  end
113
-
112
+
114
113
  # make sure range exists
115
114
  unless TOWNSHIPS_BY_RANGE_AND_MERIDIAN[self.meridian][self.range]
116
115
  add_error(:land, 'does not exist')
117
116
  return false
118
117
  end
119
-
118
+
120
119
  # make sure township exists
121
120
  unless TOWNSHIPS_BY_RANGE_AND_MERIDIAN[self.meridian][self.range][:townships].include?(self.township)
122
121
  add_error(:land, 'does not exist')
123
122
  return false
124
123
  end
125
-
124
+
126
125
  # make sure section exists
127
-
126
+
128
127
  # it is possible all sections exists for all townships
129
128
  if TOWNSHIPS_BY_RANGE_AND_MERIDIAN[self.meridian][self.range].has_key?(:sections)
130
129
  # NO, now see if this township has valid sections
131
130
  if TOWNSHIPS_BY_RANGE_AND_MERIDIAN[self.meridian][self.range][:sections].has_key?(self.township)
132
- # YES, check further to see that this section is listed
131
+ # YES, check further to see that this section is listed
133
132
  unless TOWNSHIPS_BY_RANGE_AND_MERIDIAN[self.meridian][self.range][:sections][self.township].include?(self.section)
134
133
  add_error(:land, 'does not exist')
135
134
  return false
@@ -145,17 +144,17 @@ module Rats
145
144
  return true
146
145
  end
147
146
  end
148
-
147
+
149
148
  def to_a
150
149
  [self.quarter, self.section, self.township, self.range, self.meridian].compact
151
150
  end
152
-
151
+
153
152
  # can this location be broken down into quarter sections?
154
153
  #
155
154
  def is_divisible?
156
155
  [:half, :section, :township].include?(self.scope)
157
156
  end
158
-
157
+
159
158
  # returns individual quarter sections for a :half_section, :section or :township
160
159
  #
161
160
  def divide
@@ -169,7 +168,7 @@ module Rats
169
168
  self.divide_township
170
169
  end
171
170
  end
172
-
171
+
173
172
  def divide_half
174
173
  quarters = []
175
174
  locations = case self.quarter.to_s.downcase
@@ -216,15 +215,15 @@ module Rats
216
215
  when 'swe'
217
216
  ['NE','SE','SW']
218
217
  end
219
-
218
+
220
219
  # create the required locations
221
220
  locations.each do |quarter|
222
221
  quarters << Rats.new(self.meridian, self.range, self.township, section || self.section, quarter)
223
222
  end
224
-
223
+
225
224
  quarters
226
225
  end
227
-
226
+
228
227
  def divide_section(section=nil)
229
228
  quarters = []
230
229
  ['NE', 'NW', 'SE', 'SW'].each do |quarter|
@@ -232,7 +231,7 @@ module Rats
232
231
  end
233
232
  quarters
234
233
  end
235
-
234
+
236
235
  def divide_township
237
236
  quarters = []
238
237
  (1..36).each do |section|
@@ -276,9 +275,9 @@ module Rats
276
275
  end
277
276
 
278
277
  def parse_parcel_id(parcel_id)
279
- result = parcel_id.to_s.scan(/^(\d{1})(\d{2})(\d{3})(\d{2})(\D{1,2})?/)
278
+ result = parcel_id.to_s.scan(/^(\d{1})(\d{2})(\d{3})(\d{2})(\D{1,2})?/)
280
279
  return unless result && result.size > 0
281
- numbers = result.pop.compact
280
+ numbers = result.pop.compact
282
281
  self.meridian = numbers.shift.to_i if numbers.size > 0
283
282
  self.range = numbers.shift.to_i if numbers.size > 0
284
283
  self.township = numbers.shift.to_i if numbers.size > 0
@@ -294,7 +293,7 @@ module Rats
294
293
  self.section = values.shift.to_i if values.size > 0
295
294
  self.quarter = values.shift.to_s if values.size > 0
296
295
  end
297
-
296
+
298
297
 
299
298
  def default_location
300
299
  if self.quarter
@@ -307,7 +306,7 @@ module Rats
307
306
  def short_location
308
307
  [@meridian.to_p,@range.to_p,@township.to_p,@section.to_p,@quarter.to_p].compact.join('').strip
309
308
  end
310
-
309
+
311
310
  def padded_location
312
311
  if self.quarter
313
312
  "#{@quarter.to_p} #{[@section.to_p,@township.to_p,@range.to_p].compact.join('-')} #{@meridian.to_s}".strip
@@ -327,11 +326,11 @@ module Rats
327
326
  parts << self.m.fullname
328
327
  parts.compact.join(', ')
329
328
  end
330
-
329
+
331
330
  def add_error(index, the_error)
332
331
  @errors[index] = [] unless @errors.has_key?(index)
333
- @errors[index] << the_error
332
+ @errors[index] << the_error
334
333
  end
335
-
334
+
336
335
  end
337
336
  end